Converting Excel to HTML

We are trying to convert Excel to HTML and attach to an email. So using the regular SaveFormat options with HTML generates external CSS files. We did modify it to be able to generate a single page HTML but the CSS was included in the section rather than inline in the actual HTML elements.


Is there a way to generate the HTML with styles inline so that attaching that HTML to an email will work?

Hi Jordan,


Thank you for contacting Aspose support.

I am afraid, it is not possible to write inline CSS while converting spreadsheets to HTML while using Aspose.Cells APIs. Please note, Aspose.Cells APIs follow Excel’s guidelines and specifications in its process, and it is Excel’s behavior to write CSS to separate file if spreadsheet contains multiple worksheets. In case the spreadsheet contains only one worksheet the CSS will be part of the HTML itself but will be in the HEAD section.

Hi - Is this still the official position?

We have a use case to include single worksheet content as an email html body but due to the separate element which seems stripped out by most email clients it does not render properly.

It would be great if Aspose.Cells considered adding an inline option.

@chris23,

As mentioned in the previous response, if an Excel file contains only one worksheet, the CSS elements will be embedded within the HTML file itself and will be located in the HEAD section. Therefore, you can export a single worksheet (by removing or hiding any other worksheets in the file) to HTML using Aspose.Cells.

Hi - Yes I am aware of that but I believe Aspose places the styles in a style <> element inside the html output and this gets stripped out by many/most email clients.

@chris23,

Aspose.Cells follows MS Excel standards when rendering Excel spreadsheet to HTML. Anyways, could you please share your current (sample) output HTML by Aspose.Cells and your desired output HTML file. We will evaluate it (if possible).

Hi. I don’t think it’s that valuable me sharing a specific html example, this is about putting all styles inline and not having anything in a separate <style> section which uses css classes.

Here is an example of a cell output as html via Aspose:
<td class=‘x22’>Header</td>

The styling for this is located further down the document:
<style>

.x22
{
mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
background:#9BBB59;
mso-pattern:auto none;
color:#000000;
font-size:11pt;
font-weight:700;
font-style:normal;
font-family:Calibri,sans-serif;
mso-protection:locked visible;
}

</style>

This gets stripped out by many/most email clients. So for example the background colour is lost.

As far as I understand it all this styling can be placed inside the html elements. I understand this will lead to an increase in the size of the output but I think it’s the only way to guarantee correct rendering inside email and if it could be added as e.g. an option on HtmlSaveOptions it would be great.

@chris23,

Thanks for providing further details.

We will evaluate on your requirements, i.e., place inline styling/formatting inside HTML elements. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes (if feasible) according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-57167

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks - I am sure this could be useful to anybody using Aspose in any sort of email based pipeline.

@chris23,

We will keep you posted with new updates (once available) on it.

1 Like

@chris23 ,

Hi. Do you send the HTML as an email attachment? Does the recipient download it and then open it or preview it online directly? I downloaded it and it displays well in the browser.

Hi. No we set it as the content/body of the email. This is about how email clients (browser or desktop based) display the actual contents of the email (not about attachments).

From what I have read it is quite well known that they commonly strip out style elements as mentioned above. We have also verified this in our tests (i.e. checked that when e.g. a colouring was moved from the style element to inline on the actual html element it then rendered as expected).

@chris23,

Thanks for providing more details.

We will evaluate your requirements and get back to you soon.

@chris23 , @jordandev ,

We are pleased to inform you that your issue has been resolved. The fix will be included in an upcoming release (Aspose.Cells v24.12) that we plan to release in the first half of December 2024. You will be notified when the next version is released.

Please try the following code after the new version is released:

Workbook workbook = new Workbook(srcfile);
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html);
saveOptions.DisableCss = true;
workbook.Save(destfile, saveOptions);

That’s amazing - thank you!

@chris23,

You are welcome. We will keep you posted with updates on the next version.