Width from HTML tag is not honoured


#1

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


#2

@Amithantony,

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


#3

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)


#4

@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


#5

@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.


#6

Thank you @Amjad_Sahi

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


#7

@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.


#8

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.


#9

@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.