Embed external CSS file in Excel file

Hi,

I am new to Aspose.Cells.

Will you please help as on how to embed an external CSS file while creating a new Excel file?

Awaiting your reply.

Thanks !

Rohan

Hi,

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

Could you please elaborate your issue more? What you are trying to achieve? Does such a thing is supported by Ms-Excel 2010.

I am writing a Report generation tool.

For this i want to give styles to cell,row,link,etc specified in CSS file, which the user will pass to this tool.

Is there any way that Excel can recognize the styles specified in CSS ?

Thanks !

Hi,

Please see the following demo, it creates a worbook from html, the html uses style, it does not use the external style, but you can modify it and see if external styles could work.

In case, external styles could not work, this html is using the embedded styles, but you can easily import your embeded styles from your external files.

I have also attached the output files both in xlsx and html formats.

Please download and use the latest version:
Aspose.Cells
for .NET v7.2.0.2



Please also see the screenshot for your reference.

C#



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



// input

string html = @“













<td class=”“highlight”“>Time<td style=”“color:red;”“>10:10:10 AM

NameValue
SkyBlue
Year2012
EUR-USD1.3275
Date2/8/2012
”;

html = @“<!doctype html><style type=”“text/css”">.highlight{color: green;} " + html + “”;


// aspose XLS prep

byte[] byteArray = Encoding.ASCII.GetBytes(html);


File.WriteAllBytes(filePath + “.out.htm”, byteArray);


MemoryStream stream = new MemoryStream(byteArray);

Workbook workbook = new Workbook(stream);

Worksheet sheet = workbook.Worksheets[0];

sheet.AutoFitColumns();


workbook.Save(“output.xlsx”);



Screenshot:

Thanks a lot.

Hi,

It’s good to know your issue is now resolved.

We have now also supported the reading and writing of MHTML files.

Please download and use the latest version: Aspose.Cells for .NET 7.3.0

See the topic for reference:

  • Converting to MHTML Files

Hi there,

I'm new to Aspose and was trying to find more information about converting an HTML file to an Excel - specifically using css styles. Is there anymore documentation or examples of what tags Aspose does recognize? For example, I've noticed that if I place a style="color:red" on a

element, it's not recognized in the resulting XLS, but if the style attribute is on a element, it is recognized. Also, it seems as though some of the style properties are not recognized - I tried using text-align:center - and that didn't seem to work.

Thanks for your help!

Hi,

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

HTML conversion to Ms-Excel is not complete. Not all types of html files can be converted into Ms-Excel files.

Aspose.Cells can currently convert only Ms-Excel generated html files or simple html files. Suppose, if you generate some html file using Ms-Excel, Aspose.Cells will be able to load it and convert it back to Ms-Excel (xls/xlsx) file.

It is better for you to restrict your Html to only those subset of Html tags which are generated by Ms-Excel.

Normally, these tags are fully supported.