Width from HTML tag is not honoured

Hi,
I am generating a workbook from HTML. The width attribute in the HTML is not considered in the workbook created.

I have attached the snip of my code.

HTMLLoadOptions loadOptions = new HTMLLoadOptions(LoadFormat.Html);
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(htmlData)))
{
Workbook wb = new Workbook(stream, loadOptions);
var sheet = wb.Worksheets[0];
sheet.AutoFitRows();
using (var documentStream = new MemoryStream())
{
wb.Save(documentStream, SaveFormat.Xlsx);
}
workBooks.Add(wb);
}

Regards,
Amith Antony

@Amithantony,

Please share the source HTML file for our analysis here. Also please provide some snapshot showing the issue if possible.

I have attached the HTML I use also the excel generated. When the HTML is viewed in browser the table columns are with the given width. But in excel the column width is ignored.

Table width.zip (26.4 KB)

@Amithantony,

We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46219 - Width from HTML tag is not followed while converting HTML to XLSX

@Amithantony,

Please try to set auto-fit rows and columns on while loading the HTML file, it will work better as I tested:
e.g
Sample code:

        HTMLLoadOptions opts = new HTMLLoadOptions(LoadFormat.Html);

opts.AutoFitColsAndRows = true;
Workbook workbook = new Workbook(“e:\test2\Table Width Sample.html”, opts);
string output = “e:\test2\out1.xlsx”;
workbook.Save(output);

Let us know if you still find the issue.

Thank you @Amjad_Sahi

Your solution works perfectly for my case. Once again thank you so much.

@Amithantony,

Good to know that your issue is sorted out by the suggested line(s) of code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Hi @Amjad_Sahi,
I face one more issue in the same xslx generation. The multiline text is displayed as a single line.

image.png (14.0 KB)
image.png (12.8 KB)

I use the same HTML to generate PDF document and it works fine.

@Amithantony,

Thanks for the screenshots.

Well, I noticed this but we think it is a minor thing as setting HTMLLoadOptions.AutoFitColsAndRows attribute to true might not mimic 100% with your original HTML file, so you have to live with it.

@Amithantony,

Please try our latest version/fix: Aspose.Cells for .NET v18.7.5:

Your issue should be fixed in it.

Let us know your feedback.

Please use the following code to test it:
e.g
Sample code:

HTMLLoadOptions loadOptions = new HTMLLoadOptions(LoadFormat.Html);
loadOptions.AutoFitColsAndRows = true;
Workbook wb = new Workbook(filePath + "Table Width Sample.html", loadOptions);
wb.Save(filePath + "out.xlsx");

Than you so much. The issue is resolved.

@Amithantony,

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

The issues you have found earlier (filed as CELLSNET-46219) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi