Search code examples
c#excelepplus

EPPlus Excel File. Show correct output for diagonal cell


Using EPPlus I wrote code to show diagonal cell information.

I read this tutorial on how to achieve this in Excel.

This is the code I wrote:

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

When I open the Excel file it initially looks like this:

Incorrect view.

Then I double click the cell to enter mode: 'editing directly in cells'. I click away and then I see the correct output result:

Correct output.

My question: What can I do to immediately show the correct output result?

FYI:

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

Solution

  • Try turning on text wrapping:

    diagonalCell.Style.WrapText = true;