0
我的动态创建的电子表格的一部分看起来像这样:如何使用C#将Excel单元格内容右对齐?
起初,两个货币值(在有界塔内部的四行每个块中的第二和第三行)为(默认)从右侧偏移一点,因为您可以看到第二个货币值/第三行是现在。
因此,两个货币行与第一行(int)和最后一行(%)并不完全对齐。
我希望他们都拥有块的右侧的垂直边框,如int和%行。
我尝试加入此代码为第一币值/第二排,试图证明它,希望它会证明正确:
monthPurchasesCell.HorizontalAlignment = XlVAlign.xlVAlignJustify;
...但是,你可以在屏幕上看到它的反面(证明左边)。没有“xlVAlignJustifyRight”左右。
在上下文中,代码在一个月块显示四行是:
private void AddMonthData(int packages, decimal purchases, decimal avgPrice, double percent, int colToPopulate)
{
var monthPackagesCell = (Range)_xlSheet.Cells[_curDescriptionTopRow, colToPopulate];
monthPackagesCell.Value2 = packages.ToString("N0", CultureInfo.CurrentCulture);
var monthPurchasesCell = (Range)_xlSheet.Cells[_curDescriptionTopRow + 1, colToPopulate];
monthPurchasesCell.Value2 = purchases.ToString("C", CultureInfo.CurrentCulture);
monthPurchasesCell.HorizontalAlignment = XlVAlign.xlVAlignJustify;
var monthAvgPriceCell = (Range)_xlSheet.Cells[_curDescriptionTopRow + 2, colToPopulate];
monthAvgPriceCell.Value2 = avgPrice.ToString("C", CultureInfo.CurrentCulture);
var monthPercentOfTotalCell = (Range)_xlSheet.Cells[_curDescriptionTopRow + 3, colToPopulate];
monthPercentOfTotalCell.Value2 = percent.ToString("P", CultureInfo.CurrentCulture);
}
我怎么能证明货币值向右?
XlValign - 这不是用于垂直对齐吗?您将水平对齐设置为垂直对齐。所以这就是为什么你没有得到左/右对齐。尝试xlRight,看看你得到什么。有时候,你不会对任何你想要的法律表达有任何智慧。 – NovaDev