1

I am using ExcelLibrary for creating excel sheet. I need to increase width of some columns. Is there any way to achieve this?

var ObjWorkBook = new Workbook();
var ObjWorkSheet = new Worksheet(ObjDataTable.TableName);
ObjWorksheet.Cells[0, 0] = new Cell("FirstName");
ObjWorksheet.Cells[0, 1] = new Cell("Email");
//var Width = ObjWorksheet.Cells.ColumnWidth.Default + 200;
ObjWorkBook.Worksheets.Add(ObjWorkSheet);
Rasmita Dash
  • 917
  • 5
  • 15
  • 28
  • ObjWorksheet.Columns[1].ColumnWidth = 50; – Paresh J Jan 05 '15 at 13:32
  • I guess you are talking about some other dll. But, I am using ExcelLibrary.SpreadSheet for creating spread sheet. Worksheet class is not having a property named "Columns". – Rasmita Dash Jan 06 '15 at 03:58
  • 1
    Check if this works for you: ObjWorksheet.Cells.ColumnWidth[0, 1] = 100; – Paresh J Jan 06 '15 at 04:19
  • yes, It worked out... just a little modification... as I want to change width of entire column not a single cell... so ObjWorksheet.Cells.ColumnWidth[0] = 15000; – Rasmita Dash Jan 06 '15 at 05:36

1 Answers1

1

To change the width of a column, use Range.ColumnWidth.

For example:

// Increase column A by 200
ObjWorksheet.Columns["A"].ColumnWidth += 200

// Alternately.
OjbWorksheet.Columns[1].ColumnWidth += 200

Of course you can put this in a loop to edit multiple columns.

// Increase columns A-E by 200.
for (var i = 1; i <= 5; i += 1)
{
    OjbWorksheet.Columns[i].ColumnWidth += 200
} 
Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33