0

I'm developing a Windows Form Application with C#, and I have already implemented Interop for Excel on it to create a worksheet with some data.

I can already create the excel document but when I open it, the size of the cells look like this:

enter image description here

I have already implemented some functions on the code to try to fix this problem:

char[] NosCharsToRemove = "\n".ToCharArray();
ExcelWorkSheet.Cells[row, col] = norm.comments.TrimStart(NosCharsToRemove);

Or,

ExcelWorkSheet.Cells[row, col] = norm.comments.TrimStart();

Or,

ExcelWorkSheet.Cells[row, col] = norm.comments.Replace(System.Environment.NewLine, "");

But no one has worked.

If I go to the Excel document and I tap double click in one of the "ugly" cells, and then, I focus another random cell, the "ugly cell" is fixed "magically".

enter image description here

Does anyone know how can I fix this problem programatically?

I will appreciate so much their help!

Erik Barajas
  • 193
  • 2
  • 12

1 Answers1

0

Try wordwrap style for the cell. Refer msdn wordwrap for range

ExcelWorkSheet.Cells[row, col].Style.Alignment.WrapText = true;
Mukul Varshney
  • 3,131
  • 1
  • 12
  • 19