I want to generate an Excel programmatically (Salesforce Apex) something similar to below screenshot. The number of Cells, background color of the cells will be decided at the run time and hence using programmatic way.

To achieve this I tried to apply inline styles for Cell > Data but it seems we can't apply inline styles there. For example styles get applied to first Cell with ss:StyleID="s66". But for the second Cell it doesn't work inline styles in that manner. In my requirement since I can't pre-define the style I need some dynamic way. Can anyone confirm if this is not possible or provide any guidance?
<Row>
<Cell ss:StyleID="s66"><Data ss:Type="String">Test Sheet1</Data></Cell>
<Cell ><Data ss:Type="String"><Font ss:Color="#FF0000">Sample Text</Font></Data></Cell>
</Row>
The
XMLyou are trying to use isOffice 2003 SpreadsheetML. The reference is XML Spreadsheet Reference.If you look at the "XML Spreadsheet Tag Hierarchy", you will see, that the namespace
ssis always prefixed there. So it is not the default namespace. The default namespace ishtml. So theFont,B,Suptags are not prefixed by namespace.But in current
Excelversions, if saved asOffice 2003 SpreadsheetML, the default namespace is set toxmlns="urn:schemas-microsoft-com:office:spreadsheet"which isss. So if one wants usinghtmltags, they must be prefixed byhtml.Example:
Another option would be changing the default namespace to
xmlns="http://www.w3.org/TR/REC-html40"which ishtml. Then thehtmltags needs not be prefixed byhtmlbut then thesstags must.Example: