开发者

force width in html excel file to be a certain width when opened in excel

开发者 https://www.devze.com 2023-03-29 15:17 出处:网络
I am havin开发者_JAVA百科g trouble setting the width in an html excel file and then opening it in excel.

I am havin开发者_JAVA百科g trouble setting the width in an html excel file and then opening it in excel.

The width works perfectly in html when viewed with the major browsers, but when loaded into excel I see a big disconnect.

I spoke with other designers and they said to use the web preview technique in excel, but that is not working either. Another person suggested using the col tag and setting the attribute width, style width, and the style mso alternate width. Also it was suggested to use span, and match table width to the sum of td width which also is not working in excel, but they all seem to work great in all the browsers.

There are multiple tables, and each table has been customized for width and height.

Also I have tried to put everything under one table and set only the first row for widths which is also not working. Should I just switch to pdf.

Thanks, Marc


I was able to fix this by loading the file in excel, adjusting all the columns and heights manually, resaving into html, and then redisplaying the file as html, and then loading the file into excel. Since my original html has certain css styles, I had to re-apply those, but the formatting widths and heights were perfect.

The only real problem with this technique is it can take a lot of time to get the formatting in html just the way you want it. I may have been faster to just save a xml, then convert from the xml into html.


FYI, I had the same issue - not being able to force the width to 1st column in HTML saved as XLS. I was using <td width="123"> too. Actually, I was able to set the column size to some bigger value, like 50px or 100px, but couldn't set it below some minimum threshold of maybe 25-30px (I needed 1px).

It turned out that the cause for this confusion was that the content of used HTML file had another tag wrapped around it - when I removed it and left just single all started working well.


If you need to generate a well-formmatted excel file. html excel file might be a bad choice.

My final choice is: use HtmlAgilityPack to load html to DocumentNode tree, use POI to create rows and cells according to the node tree.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号