This project has moved and is read-only. For the latest updates, please go here.

What is the best way to set alignment of columns

Aug 28, 2012 at 6: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 9:29 PM
Edited Aug 29, 2012 at 9:29 PM

You can set multiple columns at once using:

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