Cell[0-0] Losses Font Color After Applying Style to Column 256

Hello,


I was wondering if someone could help me. We are currently producing an Excel Sheet with more than 255 columns. For each column we set a Style then for the first Cell of each column we set a black background and white font (Column Header). However after applying the style for Column 256 the Cell Style (font color, etc.) for the first header is lost.

// It resets first Cell on Colmn 256 on the below line
headerColumn.ApplyStyle(headerColumnStyle, headerColumnStyleFlag);

I have tried saving the file as 2007

excel.Save(ms, FileFormatType.Excel2007Xlsx);

with the .XLSX extension but this issue seems to occur even before we save and may have to do with the objects we are using.

Any help / suggestions would be appreciated.

Thanks,

Adam

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version:
Aspose.Cells
for .NET v7.2.2.1

and see if it resolves your problem.

If the problem still occurs, we will need your complete code to replicate the problem and source xls/xlsx files.

Also, when you save your workbook in xlsx format, then please use the following code.

C#


workbook.Save(“output.xlsx”, SaveFormat.Xlsx);


If you are looping all columns and setting column headers style this will remove an settings you have to cells styles after 255 columns.

The fix I used was create a method that uses a range. After I loop and setup all my column header styles.

private void ApplyColumnCellStyleUsingRange(string lastCellString, int columnCount, Worksheet sheet)
{
if (columnCount > 0 && !string.IsNullOrEmpty(lastCellString))
{
// Select column headers
Range cellRange = sheet.Cells.CreateRange("A1", lastCellString);

// Create Style
int newStyleIndex = sheet.Workbook.Styles.Add();
Style headerColumnStyle = sheet.Workbook.Styles[newStyleIndex];
headerColumnStyle.Font.Name = "Arial";
headerColumnStyle.Font.Size = 8;
headerColumnStyle.Font.IsBold = true;
headerColumnStyle.Font.Color = Color.White;
headerColumnStyle.Pattern = BackgroundType.Solid;
headerColumnStyle.BackgroundColor = Color.Black;
headerColumnStyle.ForegroundColor = Color.Black;
headerColumnStyle.HorizontalAlignment = TextAlignmentType.Center;

// Apply column header style to range
cellRange.Style = headerColumnStyle;
}
}

Im using version 4.0 and upgrading to latest wasn't an option for use this seems to work fine.

FYI: cell.Name gives you "A1" etc. so you would need to get the last column name. range = A1 to D1.

Hi,

Thanks for your feedback and sharing your solution.

It will be helpful for other forum members. Please also download and try the latest fix:
Aspose.Cells
for .NET v7.2.2.7
in case you still encounter any problem.

Please feel free to post any of your other problem, we will help you asap.