[英]How can I get a value to expand over multiple rows in Excel?
I need to place a text value spanning four rows. 我需要放置一个跨越四行的文本值。 I thought/hoped this would work: 我认为/希望这样做会起作用:
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;
}
I need the first description to display, vertically centered, in cells A8 - A11 (column A, rows 8-11). 我需要第一个描述以垂直居中的方式显示在单元格A8-A11中(列A,第8-11行)。
The code above adds the description in all four rows, rather than just one time in the four rows. 上面的代码在所有四行中添加了描述,而不是在四行中仅添加了一次。
How can I prevent the three redundant appearances of the description? 如何防止描述的三个重复出现?
Defining and then Merging the range works: 定义然后合并范围是可行的:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.