Search code examples
c#epplus

EPPlus row height size different


I am creating and filling an excel file from a table in my app. Once it's done, some rows do not have the same height than some others. There is no difference between the data. I can not figure it out.

You can see in the pic' the rows with blue stars and green stars do not have the same height.

enter image description here

I want them all have the green star height.

using (ExcelPackage package = new ExcelPackage(streamDest, streamTemp))
{

ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
    worksheet.DefaultRowHeight = 14.25;

for (...)
{
    if (...)
    {
        if (...)
        {
            AddExcelRow(worksheet, currentPosition, lstFlightsDisplayed[i]);
            currentPosition++;
        }
        else
        {
            worksheet.InsertRow(currentPosition, 1, startPos);
            worksheet.Row(i).Height = 14.25;
            worksheet.DefaultRowHeight = 14.25;
            AddExcelRow(worksheet, currentPosition, lstFlightsDisplayed[i]);
            currentPosition++;
        }
    }
}
}

I tried to use :

worksheet.Row(i).Height = 14.25;
worksheet.DefaultRowHeight = 14.25;

But it does not work. Do you have any ideas ? Thank you.


Solution

  • Perhaps your data contains a newline in the beginning. You can try to disable WrapText:

    for(int i = 1; i <= sheet.Dimension.End.Column; i++)
       sheet.column(i).Style.WrapText = false;