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

Free Support Forum - aspose.com

When adding styles to rows- aspose add hundreds of columns

Hi, i have attached a file that we are using when adding data/fomatting to the excel.
As you can see from the original copy, the columns only go up to ‘U’.
But after applyting style formatting to particular rows, the spreadsheet becomes hundreds of columns long. Obviously, i want the result sheet to be exactly the same column length long as the original template.
Thanks for your help.


here is thecode that I am using to add formatting to specific rows

private static void CreateCellsHeaderFormatting(Workbook workbook, int rowNum)
{
Style headerStyle = workbook.Styles[workbook.Styles.Add()];
headerStyle.Font.IsBold = true;
headerStyle.Font.Color = Color.Blue;
headerStyle.BackgroundColor = Color.Tan;
headerStyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Medium;
headerStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Medium;
StyleFlag flag = new StyleFlag();
flag.FontColor = true;
flag.FontBold = true;
flag.Borders = true;

Row row = workbook.Worksheets[1].Cells.Rows[rowNum-1];
row.ApplyStyle(headerStyle,flag);

}

Hi,

If you do not apply style to the whole row,please use Range.ApplyStyle method.See following codes:

Workbook workbook = new Workbook();
workbook.Open(@"F:\FileTemp\UniversalSpreadsheetTemplate.xls");

Style headerStyle = workbook.Styles[workbook.Styles.Add()];
headerStyle.Font.IsBold = true;
headerStyle.Font.Color = System.Drawing.Color.Blue;
headerStyle.BackgroundColor = System.Drawing.Color.Tan;
headerStyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Medium;
headerStyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Medium;
StyleFlag flag = new StyleFlag();
flag.FontColor = true;
flag.FontBold = true;
flag.Borders = true;
Cells cells = workbook.Worksheets[1].Cells;
Range range = cells.CreateRange(2, 0, 1, cells.MaxDataColumn + 1);
range.ApplyStyle(headerStyle, flag);
//Row row = workbook.Worksheets[1].Cells.Rows[2];
//row.ApplyStyle(headerStyle, flag);

workbook.Save(@"F:\FileTemp\dest.XLS");