What is the best way to set alignment of columns

Aug 28, 2012 at 5:59 AM

HI all,

I am using following code to set alignment of the columns.

 

for (int index = 0; index <= noOfColumns; index++)
                    {
                        worksheet.Column(index).Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;

                         worksheet.Column(index).Style.Numberformat.Format = @"#,##0_);[Red]\(#,##0\)";
                    }

 

While it works great when i have 20 odd columns but it takes massive time when i have more than 30 columns. Do we have any faster way of setting alignment and formatting for columns?

Please provide your suggestions

 

Aug 29, 2012 at 8:29 PM
Edited Aug 29, 2012 at 8:29 PM

You can set multiple columns at once using:

worksheet.Cells("A:Z").Style.HorizontalAlignment = Style.ExcelHorizontalAlignment.Right