Hi,
I’m not able to get the default cell style.
SCENARIO
For the I7 cell I did’n set any style explicitly, “Normal” style is added by default by Excel
for the I8 cell, I’ve set the style to “Bad”.
C# CODE
string filePath = @“c:\ExcelFile.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
//i7 cell style name
Cell i7 = worksheet.Cells[“I7”];
var i7Style = i7.GetStyle();
var i7ParentStyle = i7Style.ParentStyle;
Debug.WriteLine("i7 Parent Style Name: " + (i7ParentStyle == null ? “null” : i7ParentStyle.Name));
//i8 cell style name
Cell i8 = worksheet.Cells[“I8”];
var i8Style = i8.GetStyle();
var i8ParentStyle = i8Style.ParentStyle;
Debug.WriteLine("i8 Parent Style Name: " + (i8ParentStyle == null ? “null” : i8ParentStyle.Name));
DEBUG OUTPUT
i7 Parent Style Name: null
i8 Parent Style Name: Bad
EXPECTATION :
The style for I7 should be "Normal"
If I’m gettig the style using VBA, like this:
Public Sub GetStyle()
MsgBox Worksheets(“Sheet1”).Range(“I7”).Style.Name
End Sub
the result is “Normal”.
Thank you,
Catalin Cristea
Software Developer
IBM Romania
Hi,
Thanks for the template file and sample code with details.
After an initial test, I observed the issue as you mentioned. I found that I could not get the default style set for the cell (in the worksheet) for the template Excel file. I used the following sample code with your template file using Aspose.Cells for .NET v8.5.2.1 (latest version/fix):
e.g Sample code: string filePath = @“e:\test2\TestCellStyle.xlsx”; Workbook workbook = new Workbook(filePath); Worksheet worksheet = workbook.Worksheets[0]; //i7 cell style name Cell i7 = worksheet.Cells[“F7”]; Style i7Style = i7.GetStyle(); Style i7ParentStyle = i7Style.ParentStyle; Debug.WriteLine("i7 Parent Style Name: " + (i7ParentStyle == null ? “null” : i7ParentStyle.Name)); //i8 cell style name Cell i8 = worksheet.Cells[“F8”]; Style i8Style = i8.GetStyle(); Style i8ParentStyle = i8Style.ParentStyle; Debug.WriteLine("i8 Parent Style Name: " + (i8ParentStyle == null ? “null” : i8ParentStyle.Name));
output:
i7 Parent Style Name: null – Not OK
i8 Parent Style Name: Bad --OK
I have logged a ticket with an id “CELLSNET-43851” for your issue. We will look into it soon.
Once we have any update on it, we will let you know here.
Thank you.
Hi,
Thanks for using Aspose.Cells.
Please change your code as the following:
C#
Debug.WriteLine("i7 Parent Style Name: " + (i7ParentStyle == null ? “Normal” : i7ParentStyle.Name));