vba 在excel中打开html excel文件中的强制宽度为一定的宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7126692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
force width in html excel file to be a certain width when opened in excel
提问by RetroCoder
I am having trouble setting the width in an html excel file and then opening it in excel.
我在 html excel 文件中设置宽度然后在 excel 中打开它时遇到问题。
The width works perfectly in html when viewed with the major browsers, but when loaded into excel I see a big disconnect.
当使用主要浏览器查看时,宽度在 html 中完美运行,但是当加载到 excel 时,我看到了很大的断开。
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.
我与其他设计师交谈过,他们说在 excel 中使用 Web 预览技术,但这也行不通。另一个人建议使用col标签并设置属性宽度、样式宽度和样式mso交替宽度。还建议使用跨度,并将表格宽度与 td 宽度的总和匹配,这在 excel 中也不起作用,但它们似乎在所有浏览器中都运行良好。
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.
此外,我试图将所有内容都放在一张桌子下,并仅设置第一行的宽度,这也不起作用。我应该切换到pdf吗?
Thanks, Marc
谢谢,马克
采纳答案by RetroCoder
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.
我能够通过在 excel 中加载文件、手动调整所有列和高度、重新保存为 html,然后将文件重新显示为 html,然后将文件加载到 excel 中来解决此问题。由于我的原始 html 具有某些 css 样式,我不得不重新应用这些样式,但格式宽度和高度是完美的。
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.
这种技术唯一真正的问题是,按照您想要的方式在 html 中获得格式可能需要很多时间。我可能会更快地保存一个 xml,然后从 xml 转换为 html。
回答by userfuser
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).
仅供参考,我遇到了同样的问题 - 无法将宽度强制设置为保存为 XLS 的 HTML 中的第一列。我也在用<td width="123">
。实际上,我可以将列大小设置为更大的值,例如 50 像素或 100 像素,但无法将其设置为低于 25-30 像素的某个最小阈值(我需要 1 像素)。
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.
事实证明,造成这种混乱的原因是使用的 HTML 文件的内容有另一个标签包裹在它周围 - 当我删除它并只留下一个时,一切都开始正常工作。
回答by Will Wu
If you need to generate a well-formmatted excel file. html excel file might be a bad choice.
如果需要生成格式良好的excel文件。html excel 文件可能是一个糟糕的选择。
My final choice is: use HtmlAgilityPack to load html to DocumentNode tree, use POI to create rows and cells according to the node tree.
我最后的选择是:使用 HtmlAgilityPack 将 html 加载到 DocumentNode 树中,使用 POI 根据节点树创建行和单元格。