We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Columns collection of a WorkSheet

I am trying to format a column and as per the examples i need to access Columns collection and i cannot seem to find one.

Here is my code example

var dt = CreateDataTable() ; // this creates the test data
var wrkbk = new Workbook();
var indx = wrkbk.Worksheets.Add();
var wrksht = wrkbk.Worksheets[indx];
var wrksht.Cells.ImportDataTable(dt,true,“A1”);
wrksht.Columns[2] … does not work


Thanks for your posting and using Aspose.Cells.

You can access your column using the Worksheet.Cells.Columns collection. Once you access your column, you can apply style to it using the ApplyStyle() method.

Please see the following code. It applies the style to column K. It fills the column with Yellow color and apply the number format on it.

I have attached the source excel file used in this code and output excel file generated by it for your reference.


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

Style style = workbook.CreateStyle();
style.Custom = “0.00_);[Red]\(0.00\)”;
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;

StyleFlag flag = new StyleFlag();
flag.CellShading = true;
flag.NumberFormat = true;

//Access Column K and apply style on it
Column col = worksheet.Cells.Columns[10];
col.ApplyStyle(style, flag);