Free Support Forum - aspose.com

Cell stylename in Aspose.Cells

I am not able to retrieve cell stylename i.e Normal or any custom cell stylename applied on a cell using Aspose.Cellls. Aspose.Cellls.Cell.GetStyle() method always returns null value.


I am using Aspose.Cells version 7.2.0.0

Hi,


If you are getting an existing named style, Please try:
//Get the custom style and create a style object.
Style style = workbook.Styles[“
styleName”];

Let us know if you still find the issue. Moreover, please use latest fix/version: Aspose.Cells for .NET v7.3.3.2

If you still find the issue, kindly give us your template file and complete runnable sample code to show the issue on our end. We will check it soon.

Thank you.

How to get the style name as for now I am seeing only styleId in the available property of the cell style. Is there anyway to get the style name from this StyleId ?

Hi,


There is also Style.Name property, you may use this.

Could you provide us the sample code (using Aspoe.Cells component’s APIs) that you are using so that we could check your issue.

Thank you.


How to convert the Excel file into Aspose by knowing the Path of excel file where the Excel Styles and everything be preserved ?

Hi,


Do you need to get the Excel file into Workbook object of Aspose.Cells APIs, see the sample code below.

Workbook workbook = new Workbook(filePath);

Please see the Aspose.Cells Wiki Docs (Programmer’s Guide) for complete reference:
http://www.aspose.com/docs/display/cellsnet/Aspose.Cells
Corporateitcompliance:
How to convert the Excel file into Aspose by knowing the Path of excel file where the Excel Styles and everything be preserved ?
Hi,

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

We are afraid, it's not very clear what you are trying to achieve. Could you please elaborate your requirements more?

Also, if you want to modify existing Styles, then please see this article.

Actually the code fragment is meaningless so it will not be of any use, So I will try my best to explain the scenerio :-

Actually we have a excel file and Cell Styles are "Normal","Style 1" to A1 and B3 Cell in Attached Excel


Now my goal is to get these style names as well as what are the property in the styles. But bellow written line is not giving these things.Its just giving the local formating applied to the Cell.

//intRow and intCol is the Row and Column position ForEach for reading cell by cell of Excel files
Aspose.Cells.Cell asposeCell = asposeWorkbook.Worksheets[0].Cells[intRow, intCol];
Style asposeCellStyle = asposeCell.GetStyle();
But this asposeCellStyle.Name is Null always, it should give for A1 style Name = 'Normal' and B3 Name = 'Style 1'
Is there any way to acheive this ??
s

Hi,

Thanks for your clarification.

You can iterate all the Named Styles in your Excel file using the Workbook.Styles collection.

For your cell B3, if you want to access the Named Style, you can use the Style.Parent property.

Please check the code below that illustrates these things. Please also see the Debug Output of this code at the bottom.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\ExcelFile.xlsx”;


//Create a workbook object from the template file

Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


Cell b3 = worksheet.Cells[“B3”];

Style b3Style = b3.GetStyle();


//This is the parent style which you have applied to cell B3

Style parentStyle = b3Style.ParentStyle;

Debug.WriteLine("B3 Parent Style Name: " + parentStyle.Name);



int styleCount = workbook.Styles.Count;


for (int i = 0; i < styleCount; i++)

{

Style style = workbook.Styles[i];


Debug.WriteLine("Style Name: " + style.Name);

}


Debug Output:
B3 Parent Style Name: Style 1
Style Name: Normal
Style Name: Percent
Style Name: Currency
Style Name: Currency [0]
Style Name: Comma
Style Name: Comma [0]
Style Name: Style 1