EPPlus Excel文件。显示对角线单元的正确输出

时间:2016-12-15 12:45:30

标签: c# excel epplus

使用EPPlus我编写了代码来显示对角线信息。

我读了这个tutorial on how to achieve this in Excel

这是我写的代码:

private void AddDiagonalTitleHeaders(ExcelWorksheet ws, string diagonalLocation)
{
    var diagonalCell = ws.Cells[diagonalLocation];
    var border = diagonalCell.Style.Border;
    border.Diagonal.Style = ExcelBorderStyle.Thick;
    border.DiagonalDown = true;

    diagonalCell.Style.Font.Size = 18;
    diagonalCell.Style.VerticalAlignment = ExcelVerticalAlignment.Top;

    var altEnter = ((char)10).ToString();
    var spaces = " ";
    var diagonalText = string.Format("{1}{1}{1}ActionFlags{0}{0}{0}{0}{0}{0}{0}{0}Status", altEnter, spaces);
    diagonalCell.Value = diagonalText;
}

当我打开Excel文件时,它最初看起来像这样:

Incorrect view.

然后我双击单元格进入模式:'直接在单元格中编辑'。 我点击了然后我看到了正确的输出结果:

Correct output.

我的问题:如何立即显示正确的输出结果?

仅供参考:

var diagonalText = "   ActionFlags\n\n\n\n\n\n\n\nStatus"; //Is the same

1 个答案:

答案 0 :(得分:1)

尝试打开文字换行:

diagonalCell.Style.WrapText = true;