when setting up style on cell conatinaing formulas (created in .net using cells.Formula =) the bnorders are not displayed properly as per the style set to the cell. if I set the value property fo the same cell no problem. only prblem with formula.
Hi,OliJ:when setting up style on cell conatinaing formulas (created in .net using cells.Formula =) the bnorders are not displayed properly as per the style set to the cell. if I set the value property fo the same cell no problem. only prblem with formula.
Thanks for your posting and using Aspose.Cells for .NET.
We have tested your issue with the latest version: Aspose.Cells for .NET v7.3.4.3 and found, it works fine.
Please see the following test code and screenshot for your reference. I have also attached the output xls/xlsx files for your reference.
In this code, you see, cell D2 has a formula (=Sum(B1:B10) and the code applies blue borders on it successfully.
If you still face this issue using the latest version, then please provide us your complete but simple runnable sample code to investigate this issue further.
We will soon look into your issue and help you asap.
C#
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first (default) worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["D2"];
//Adding some value to the "A1" cell
cell.Formula = "=Sum(B1:B10)";
//Create a style object
Style style = cell.GetStyle();
//Setting the line style of the top border
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the top border
style.Borders[BorderType.TopBorder].Color = Color.Blue;
//Setting the line style of the bottom border
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the bottom border
style.Borders[BorderType.BottomBorder].Color = Color.Blue;
//Setting the line style of the left border
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the left border
style.Borders[BorderType.LeftBorder].Color = Color.Blue;
//Setting the line style of the right border
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the right border
style.Borders[BorderType.RightBorder].Color = Color.Blue;
//Apply the border styles to the cell
cell.SetStyle(style);
//Saving the Excel file
workbook.Save("output.xls", SaveFormat.Excel97To2003);
workbook.Save("output.xlsx", SaveFormat.Xlsx);
Workbook workbook = new Workbook();
//Obtaining the reference of the first (default) worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["D2"];
//Adding some value to the "A1" cell
cell.Formula = "=Sum(B1:B10)";
//Create a style object
Style style = cell.GetStyle();
//Setting the line style of the top border
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the top border
style.Borders[BorderType.TopBorder].Color = Color.Blue;
//Setting the line style of the bottom border
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the bottom border
style.Borders[BorderType.BottomBorder].Color = Color.Blue;
//Setting the line style of the left border
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the left border
style.Borders[BorderType.LeftBorder].Color = Color.Blue;
//Setting the line style of the right border
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick;
//Setting the color of the right border
style.Borders[BorderType.RightBorder].Color = Color.Blue;
//Apply the border styles to the cell
cell.SetStyle(style);
//Saving the Excel file
workbook.Save("output.xls", SaveFormat.Excel97To2003);
workbook.Save("output.xlsx", SaveFormat.Xlsx);
Screenshot: