Free Support Forum - aspose.com

Is it possible to get style by internal name in Excel?

Hi,


See my previous question about Aspose.Words
http://www.aspose.com/community/forums/thread/342971/is-it-possible-to-get-style-by-internal-name.aspx

Now I need to make the same but for Aspose.Cells.

So for example, we have text in Excel, I need to identify them somehow, and get fonts, colors, texts.
Is is possible to identify them via internal name, or only cell position is possible to use?

Thank you for help.

Hi,


Well, you may get Styles in the workbook by using its names or index number (zero based). See some code segments below:
e.g

1) StyleCollection styles = workbook.getStyles();
//…
Style style = styles.get(styleIndex);

//…
Style newStyle = styles.get(stringStyleName);

//…
2)
Workbook excel = new Workbook();
Cells cells = excel.getWorksheets().get(0).getCells();

Cell cell = cells.get(0, 0);

//Get style of a cell
Style style = cell.getStyle();

//Your code goes here

Hi,


Is there any analog of class StyleIdentifier in Aspose.Cells ?
I need to get style by intermal string style Name, so for example:

Style style = styles.get( StyleIdentifier.Normal ).

Or how I can be sure that Normal text will be in another Office languages ?

Thank you.

Hi,


I am afraid, there is no such identifier present in Aspose.Cells, you have to specify the Style’s Name (in string) by yourself or by providing the index number. Also, you may get the style and then user Style.getName() to get its name.

Thank you.

Hi,


I’m using Aspose.Cells for java and smart designer templates…

If I create a Cell Style in my designer template with the name “MyCustomStyle” for example will I be able to access it from java?

I tried Workbook.getStyles().get(“MyCustomStyle”) but it returned null.

Thanks.




Hi,


Yes, sure you should be able to access your custom style in the template Excel file.

I have tested your scenario using the following sample code with a template file (attached), it works fine and I can get the custom style fine.

Sample code:

Workbook workbook = new Workbook(“Book2style.xlsx”);

StyleCollection styles = workbook.getStyles();
//…
Style style = styles.get(0);

//…
String stringStyleName = “MyCustomStyle”;
Style newStyle = styles.get(stringStyleName);
//…

System.out.println(newStyle.getName()); //MyCustomStyle - OK

I am using our latest version v7.4.2 (JAVA), you may download and try it.

If you still find the issue, kindly do attach your template file and paste your runnable code here, we will check your issue soon.

Thank you.