Hi, this is some sample code i’m trying to get to work.
Dim style As Style = xlApp.Styles(xlApp.Styles.Add)
With style.Font
.Name = “Arial”
.Size = 12
.IsStrikeout = False
.IsSubscript = False
.IsSuperscript = False
.Underline = FontUnderlineType.None
End With
style.Custom = “#,##0.00_);(#,##0.00)”
style.Pattern = BackgroundType.Solid
style.ForegroundColor = Drawing.Color.FromArgb(204, 255, 204)
column = “K”
xlWSheet.Cells(11, ExcelHelper.ColumnNameToIndex(column)).Style = style
xlWSheet.Cells(80, ExcelHelper.ColumnNameToIndex(column)).Style = style
xlWSheet.Cells(82, ExcelHelper.ColumnNameToIndex(column)).Style = style
xlWSheet.Cells(140, ExcelHelper.ColumnNameToIndex(column)).Style = style
Dim additionalstyle As Style = xlApp.Styles(xlApp.Styles.Add)
additionalstyle.Copy(style)
additionalstyle.Borders(BorderType.BottomBorder).LineStyle = CellBorderType.Thin
additionalstyle.Borders(BorderType.RightBorder).LineStyle = CellBorderType.Thin
additionalstyle.Borders(BorderType.LeftBorder).LineStyle = CellBorderType.Thin
additionalstyle.Borders(BorderType.TopBorder).LineStyle = CellBorderType.Thin
additionalstyle.Borders(BorderType.BottomBorder).Color = Drawing.Color.Black
additionalstyle.Borders(BorderType.RightBorder).Color = Drawing.Color.Black
additionalstyle.Borders(BorderType.LeftBorder).Color = Drawing.Color.Black
additionalstyle.Borders(BorderType.TopBorder).Color = Drawing.Color.Black
xlWSheet.Cells(26, ExcelHelper.ColumnNameToIndex(column)).Style = additionalstyle
xlWSheet.Cells(31, ExcelHelper.ColumnNameToIndex(column)).Style = additionalstyle
xlWSheet.Cells(128, ExcelHelper.ColumnNameToIndex(column)).Style = additionalstyle
xlWSheet.Cells(132, ExcelHelper.ColumnNameToIndex(column)).Style = additionalstyle
I get the background color but never the borders. Any suggestions?
Which version of Aspose.Cells are you using? I tried the following code which is same as yours and didn't find any problem.
Excel excel = new Excel();
excel.ChangePalette(Color.FromArgb(204, 255, 204), 55);
Style style = excel.Styles[excel.Styles.Add()];
style.Font.Name = "Arial";
style.Font.Size = 12;
style.Custom = "#,##0.00_);(#,##0.00)";
style.Pattern = BackgroundType.Solid;
style.ForegroundColor = Color.FromArgb(204, 255, 204);
Worksheet xlWSheet = excel.Worksheets[0];
string column = "K";
xlWSheet.Cells[11, ExcelHelper.ColumnNameToIndex(column)].Style = style;
xlWSheet.Cells[80, ExcelHelper.ColumnNameToIndex(column)].Style = style;
xlWSheet.Cells[82, ExcelHelper.ColumnNameToIndex(column)].Style = style;
xlWSheet.Cells[140, ExcelHelper.ColumnNameToIndex(column)].Style = style;
Style additionalstyle = excel.Styles[excel.Styles.Add()];
additionalstyle.Copy(style);
additionalstyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
additionalstyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
additionalstyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
additionalstyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
additionalstyle.Borders[BorderType.BottomBorder].Color = Color.Black;
additionalstyle.Borders[BorderType.RightBorder].Color = Color.Black;
additionalstyle.Borders[BorderType.LeftBorder].Color = Color.Black;
additionalstyle.Borders[BorderType.TopBorder].Color = Color.Black;
xlWSheet.Cells[26, ExcelHelper.ColumnNameToIndex(column)].Style = additionalstyle;
xlWSheet.Cells[31, ExcelHelper.ColumnNameToIndex(column)].Style = additionalstyle;
xlWSheet.Cells[128, ExcelHelper.ColumnNameToIndex(column)].Style = additionalstyle;
xlWSheet.Cells[132, ExcelHelper.ColumnNameToIndex(column)].Style = additionalstyle;
excel.Save("d:\\test\\abc.xls");
Attached is my output file.
This is the latest version.
thanks for your help Laurence but i’m still not getting the borders around the cells.
Never mind my last reply. I found my problem. I was working in the wrong procedure.
Thanks for your help!