How do I extract the the "default excel style" from an excel workbook

I have a requirement to extract the default styles from an Excel file

http://support.microsoft.com/KB/291321

How do I extract them using Aspose Cell

Thanks,
Rohit

if you look into the code within the support article there are these default theme


For Each CurStyle In MyBook.Styles

'If CurStyle.Name <> "Normal" Then CurStyle.Delete

Select Case CurStyle.Name

Case "20% - Accent1", "20% - Accent2", _

"20% - Accent3", "20% - Accent4", "20% - Accent5", "20% - Accent6", _

"40% - Accent1", "40% - Accent2", "40% - Accent3", "40% - Accent4", _

"40% - Accent5", "40% - Accent6", "60% - Accent1", "60% - Accent2", _

"60% - Accent3", "60% - Accent4", "60% - Accent5", "60% - Accent6", _

"Accent1", "Accent2", "Accent3", "Accent4", "Accent5", "Accent6", _

"Bad", "Calculation", "Check Cell", "Comma", "Comma [0]", "Currency", _

"Currency [0]", "Explanatory Text", "Good", "Heading 1", "Heading 2", _

"Heading 3", "Heading 4", "Input", "Linked Cell", "Neutral", "Normal", _

"Note", "Output", "Percent", "Title", "Total", "Warning Text"

'Do nothing, these are the default styles

Case Else

CurStyle.Delete

End Select


How do I extract these using Aspose Cells ?

Hi,

Thanks for your posting and considering Aspose.Cells.

I have check the source.xlsx file which I created with Microsoft Excel, then I unzipped it and extracted the Styles.xml file which is attached by me and found there are not any default styles inside it. Please have a look at it. I have also attached the screenshot showing Styles.xml file.

So actually default styles are not saved inside the Excel file but Microsoft Excel generates them on runtime.

In the same way, you can create built-in default styles using Aspose.Cells. For example the following code creates 20% Accent style.

C#


Style style = workbook.Styles.CreateBuiltinStyle(BuiltinStyleType.TwentyPercentAccent1);


Please also see the BuiltinStyleType enumeration for your reference.



BuiltinStyleType Enumeration

public enum BuiltinStyleType

Members

Member Name Description Value
TwentyPercentAccent1 30
TwentyPercentAccent2 34
TwentyPercentAccent3 38
TwentyPercentAccent4 42
TwentyPercentAccent5 46
TwentyPercentAccent6 50
FortyPercentAccent1 31
FortyPercentAccent2 35
FortyPercentAccent3 39
FortyPercentAccent4 43
FortyPercentAccent5 47
FortyPercentAccent6 51
SixtyPercentAccent1 32
SixtyPercentAccent2 36
SixtyPercentAccent3 40
SixtyPercentAccent4 44
SixtyPercentAccent5 48
SixtyPercentAccent6 52
Accent1 29
Accent2 33
Accent3 37
Accent4 41
Accent5 45
Accent6 49
Bad 27
Calculation 22
CheckCell 23
Comma 3
Comma1 6
Currency 4
Currency1 7
ExplanatoryText 53
Good 26
Header1 16
Header2 17
Header3 18
Header4 19
Hyperlink 8
FollowedHyperlink 9
Input 20
LinkedCell 24
Neutral 28
Normal 0
Note 10
Output 21
Percent 5
Title 15
Total 25
WarningText 11
RowLevel 1
ColumnLevel

Thanks, I will check this but can you quickly confirm if this is available in Aspose Cell for Java.

Just verified that BuiltinStyleType is available in Aspose Cell for Java. Will play around and will let you know incase we face any issues

How do I know if the cell is using the default built in Style ?

To elaborate to the point in the attached excel file the cell A2 is using “Accent 6 79” as the background color. How do I extract this info



Also the entire cell is using “__builtInStyle5” as a style where __builtInStyle5 is



{

“name”: “__builtInStyle5”,

“backColor”: “Accent 6 79”,

“hAlign”: 3,

“vAlign”: 2,

“font”: “normal normal 14.7px Arial”,

“themeFont”: “Body”,

“locked”: true,

“wordWrap”: false,

“textDecoration”: 0

}







Thanks,

Rohit

Any updates ?

Thanks,
Rohit

Hi,

Thanks for your posting and considering Aspose.Cells.

Fortunately, you can find the built-in style applied to a cell using the Style.ParentStyle property. Whenever, you will apply built-in style to any cell, this property will return the built-in style.

Please check the attached source.xlsx file for your reference and also see this code and its console output.

Java


String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.getWorksheets().get(0);


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

{

Cell cell = worksheet.getCells().get(i, 0);


Style style = cell.getStyle();


Style parentStyle = style.getParentStyle();


System.out.println("Built-in Style Name: " + parentStyle.getName());

}

Console Output:
Built-in Style Name: Bad
Built-in Style Name: Good
Built-in Style Name: Check Cell
Built-in Style Name: 40% - Accent2
Built-in Style Name: Input
Built-in Style Name: Linked Cell
Built-in Style Name: Accent1
Built-in Style Name: Heading 1
Built-in Style Name: Explanatory Text
Built-in Style Name: 20% - Accent4