Howdy!
Recently, we moved to .NET Core (version 5.0) and upgraded Aspose from 20.6.0.0 to 21.9.0
This has caused some problems with formatting “Html Cells”. Here is how to duplicate the issue.
Keep in mind that my code is with .NET Core 5 (which may or may not matter).
Also, the code below outlines a fix (I mean a hack which resolves the issue).
var myDir = @"YourDirectory";
var htmlString = "<font style=\"font-size:20pt;\">Test</font><br/>";
var htmlSaveOptions = new HtmlSaveOptions
{
CellCssPrefix = "Av",
ExportActiveWorksheetOnly = true,
ExportImagesAsBase64 = true,
PresentationPreference = true,
};
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];
var cell = ws.Cells[1, 1];
cell.HtmlString = htmlString;
wb.Worksheets.ActiveSheetIndex = 0;
wb.Save(myDir + "TestAsPoseExcel_NetCore_21_9_0_Bad.html", htmlSaveOptions);
// Please check that the file above has bad font.
// Now, before disposing we save the file in Xlsx format , to reopen it and save as Html again.
// This is to show that after saving and re-opening and then saving as Html everything works
wb.Save(myDir + "TestAsPoseExcel_NetCore_21_9_0.xlsx", SaveFormat.Xlsx);
wb.Dispose();
wb = new Workbook(myDir + "TestAsPoseExcel_NetCore_21_9_0.xlsx");
wb.Worksheets.ActiveSheetIndex = 0;
wb.Save(myDir + "TestAsPoseExcel_NetCore_21_9_0_Good.html", htmlSaveOptions);
wb.Dispose();
One more observation, if one removes “
” from the end of “htmlString” then things appear to be working as well. But, on the other hand there is nothing wrong with “
” tag …
Thx,
Bogdan