Wrap Text in column

Hi,
I want to apply wrap text on whole column rather than going and apply wrap text on each single cell

I tried following code but it does not work

private void StyleSheet(Worksheet sheet)
        {
            var cells = sheet.Cells;
            var range = sheet.Cells.MaxDisplayRange;
            for (int columnIndex = 0; columnIndex < range.ColumnCount + 1; columnIndex++)
            {
                Style style = sheet.Cells?.Columns[columnIndex]?.Style;
                sheet.Cells.SetColumnWidth(columnIndex, 20);
                sheet.Cells.ApplyColumnStyle(columnIndex,style, new StyleFlag()
                {
                    WrapText = true
                });
                /*sheet.Cells.Columns[columnIndex].ApplyStyle(style, new StyleFlag()
                {
                    WrapText = true
                });*/

            }
        }

@Amrinder_Singh,

Could you please try to update your code segment to:
e.g.
Sample code:

private void StyleSheet(Worksheet sheet)
{
var cells = sheet.Cells;
var range = sheet.Cells.MaxDisplayRange;
for (int columnIndex = 0; columnIndex < range.ColumnCount + 1; columnIndex++)
{
    Style style = sheet.Cells?.Columns[columnIndex]?.Style;
    style.IsTextWrapped = true;
    sheet.Cells.SetColumnWidth(columnIndex, 20);
    sheet.Cells.ApplyColumnStyle(columnIndex,style, new StyleFlag()
    {
        WrapText = true
    });
    /*sheet.Cells.Columns[columnIndex].ApplyStyle(style, new StyleFlag()
    {
        WrapText = true
    });*/

} 
}

Let us know if you still find the issue.

Thank you so much, i will try this

I have my excel from which i am creating the workbook, in that excel some columns or cells are already wrapped. But when i get the final excel from the workbook wrap text gets removed which was already there.

@Amrinder_Singh
Thank you for your feedback. You can try running the code provided earlier. If it does not meet your requirements, please provide sample files and expected results, and we will check it soon.