We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

All CSS styles are not prefixed when saving as HTML

When I save a workbook to HTML, the CSS styles that use the format .x will be prefixed with the string specified in the HtmlSaveOptions.CellCssPrefix property. However, other styles in the format .font, .style, and td are not prefixed. When the HTML is embedded in a page with other content, the styles from the two sources corrupt each other.


Is there a way to save the HTML without having this problem? Note that I’m not able to use an iframe or save the workbook as an image because the user is able to convert the web page to a PDF and each solution causes problems with PDF conversion.


My code uses the following HtmlSaveOptions:
var hso = new HtmlSaveOptions(SaveFormat.Html)
{
CellCssPrefix = “WS” + wsUniqueId + cells[firstRow, firstColumn].Name,
ExportActiveWorksheetOnly = true,
ExportDataOptions = HtmlExportDataOptions.All,
ExportFrameScriptsAndProperties = false,
ExportImagesAsBase64 = true,
HiddenColDisplayType = HtmlHiddenColDisplayType.Remove,
HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,
HtmlCrossStringType = HtmlCrossType.Default,
};

And I’m saving the workbook to a MemoryStream.

Thank you

Hi,

Thanks for your posting and using Aspose.Cells.

Please provide us your sample excel file. It should be a simple excel file. Also provide us screenshots showing the wrong css and your expected css. It will help us investigate this issue properly and we will update you asap.

Please also download and try the latest version: Aspose.Cells for .NET v8.8.0.4 and see if it makes any difference and resolves your issue.

Hi,



Thank you for your response. I downloaded the version that you specified but it has the same issue.



I’ve attached the files that you requested:

1) A simple Excel file (Blank.xlsx)

2) The generated HTML file (Blank.html)

3) A screenshot of the actual and expected CSS styles. I’ve prefixed all of the .style and .font styles with the same prefix used by the .x styles. I’ve also crossed out the CSS element selectors because those are what cause the problems when embedded in another HTML document.



Here is the code used to generate the HTML document:

var wb = new Workbook(@“C:\temp\ConsoleApplication7\Blank.xlsx”);

var cells = wb.Worksheets[0].Cells;

var wsUniqueId = new Random().Next(0, UInt16.MaxValue);

int firstRow = 0, firstColumn = 0;



var hso = new HtmlSaveOptions(SaveFormat.Html)

{

CellCssPrefix = “WS” + wsUniqueId + cells[firstRow, firstColumn].Name,

ExportActiveWorksheetOnly = true,

ExportDataOptions = HtmlExportDataOptions.All,

ExportFrameScriptsAndProperties = false,

ExportImagesAsBase64 = true,

HiddenColDisplayType = HtmlHiddenColDisplayType.Remove,

HiddenRowDisplayType = HtmlHiddenRowDisplayType.Remove,

HtmlCrossStringType = HtmlCrossType.Default,

};



using (var stream = new MemoryStream())

{

wb.Save(stream, hso);



var bytes = stream.GetBuffer();

var html = Encoding.UTF8.GetString(bytes);

File.WriteAllText(@“C:\temp\ConsoleApplication7\Blank.html”, html);

}

Hi,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue as per your screenshot. The CSS styles that use the format .x are not prefixed with the string specified in the HtmlSaveOptions.CellCssPrefix property.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-44446 - All CSS styles are not prefixed when saving as HTML

Hi,

Thanks for using Aspose.Cells.

This is to inform you that we have fixed your issue CELLSNET-44446 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.8.1.4 and let us know your feedback.

Looks great. Thank you!

Hi,


Good to know that your issue is sorted out by the new fix/version. Feel free to contact us any time if you have further queries or issue, we will be happy to assist you soon.

Thank you.

The issues you have found earlier (filed as CELLSNET-44446) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

I have been having the exact same problem with Cell.Java. Not all generated styles including the requested prefix - specifically the “td” style created for displayed gridlines has no prefix and thus affects all "td"s in a page when the HTML is included.


Can I get this bug fixed in Java please.

Thank you

Mark

p.s. Here is a snipped of the generated HTML. I have specified a style prefix of “.WSI-170203-00006”

.WSI-170203-00006_font4
{
color:#595959;
font-size:9pt;
font-weight:400;
font-style:normal;
font-family:“Calibri”,“sans-serif”; }
td
{mso-style-parent:WSI-170203-00006_style0;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
background:auto;
mso-pattern:auto;
color:#000000;
font-size:11pt;
font-weight:400;
font-style:normal;
font-family:“Calibri”,“sans-serif”;
border:none;
mso-protection:locked visible;
mso-ignore:padding;}
.WSI-170203-00006_style0
{
text-align:general;
vertical-align:bottom;

Hi Mark,


Thank you for contacting Aspose support.

First of all, we humbly request you to create your own thread while providing the complete HTML string (preferably in a file) along with your code (preferably a console application) covering your complete scenario. This will help us manage your inquires in more efficient manner as well as understand your concerns. Before you move forward to provide us the above requested, please give a try to the latest version of Aspose.Cells for Java 17.1.8 (attached) to see if you can still replicate the issue.