将网页导出到 Excel 时保留 CSS 样式
我计划在 ASP.NET
网页中实现 SaveToExcel
功能,方法是将 HTML 发送回隐藏字段中的服务器,然后将其抽回作为带有 .xls
扩展名的附件。
问题在于该网页大量通过 CSS 进行样式化。由于这些样式不是 HTML 的固有部分,因此我认为它们不会转移到 Excel 文件中。 (我现在明白了为什么报告的程序员会如此大量地从使用的 FONT 标签中进行改编,这也是我想知道的。)
我突然想到,在提交回来之前可以在页面上运行 jQuery 脚本到服务器,将实际样式从 css
属性复制到元素自己的固有属性。
我不知道这会起到多大作用,但这可能比什么都没有好。
有更好的办法吗?
I'm planning on implementing a SaveToExcel
feature in an ASP.NET
web page by sending the HTML back to the server in a hidden field, and then just pumping it back out as an attachment with an .xls
extension.
The problem is that the web page is heavily styled through CSS. And since those styles aren't an intrinsic part of the HTML, I don't think they'll transfer to the Excel file. (I now see why the programmer of the report I'm adapting this from used FONT tags so heavily, which I wondered about.)
It has occurred to me that it might be possible to run a jQuery script on the page before submitting it back to the server, copying the actual styles from the css
property to the element's own intrinsic properties.
I don't know how well that would work, but it might be better than nothing.
Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Carlos Aguilar Mares 有一个我过去使用过的免费 Excel XML 库。示例代码也很有帮助。
http://www.carlosag.net/tools/excelxmlwriter/
Carlos Aguilar Mares has a free Excel XML library that I've used in the past. The sample code is helpful as well.
http://www.carlosag.net/tools/excelxmlwriter/