繁体   English   中英

如何获得一个值以扩展Excel中的多行?

[英]How can I get a value to expand over multiple rows in Excel?

我需要放置一个跨越四行的文本值。 我认为/希望这样做会起作用:

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行)。

上面的代码在所有四行中添加了描述,而不是在四行中仅添加了一次。

如何防止描述的三个重复出现?

定义然后合并范围是可行的:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM