我需要放置一个跨越四行的文本值。我原以为/希望这能奏效:
private int curDescriptionTopRow = 8;
. . .
private void AddDescription(String desc)
{
int curDescriptionBottomRow = curDescriptionTopRow + 3;
_xlSheet.Range[_xlSheet.Cells[curDescriptionTopRow, 1], _xlSheet.Cells[curDescriptionBottomRow, 1]].Font.Bold = true;
_xlSheet.Range[_xlSheet.Cells[curDescriptionTopRow, 1], _xlSheet.Cells[curDescriptionBottomRow, 1]].VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
_xlSheet.Range[_xlSheet.Cells[curDescriptionTopRow, 1], _xlSheet.Cells[curDescriptionBottomRow, 1]].Value2 = desc;
curDescriptionTopRow = curDescriptionTopRow + 4;
}我需要第一个描述在单元格A8 - A11中垂直中心显示( A列,第8-11行)。
上面的代码在所有四行中都添加了描述,而不仅仅是在四行中添加了一次。
我怎样才能避免描述中的三种多余的外观?
发布于 2015-11-05 18:05:07
定义并合并范围是可行的:
private int curDescriptionTopRow = 8;
. . .
private void AddDescription(String desc)
{
int curDescriptionBottomRow = curDescriptionTopRow + 3;
var range =
_xlSheet.Range[_xlSheet.Cells[curDescriptionTopRow, 1], _xlSheet.Cells[curDescriptionBottomRow, 1]];
range.Merge();
range.Font.Bold = true;
range.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
range.Value2 = desc;
}https://stackoverflow.com/questions/33551681
复制相似问题