Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Excel中获取要展开到多行的值?_C#_Excel_Office Interop_Excel Interop - Fatal编程技术网

C# 如何在Excel中获取要展开到多行的值?

C# 如何在Excel中获取要展开到多行的值?,c#,excel,office-interop,excel-interop,C#,Excel,Office Interop,Excel Interop,我需要放置一个跨四行的文本值。我认为/希望这会奏效: private int curDescriptionTopRow = 8; . . . private void AddDescription(String desc) { int curDescriptionBottomRow = curDescriptionTopRow + 3; _xlSheet.Range[_xlSheet.Cells[curDescriptionTopRow, 1], _xlSheet.Cells[

我需要放置一个跨四行的文本值。我认为/希望这会奏效:

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;
}