将网页导出到 Excel 时保留 CSS 样式

发布于 2024-12-10 04:38:52 字数 386 浏览 4 评论 0原文

我计划在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿与i 2024-12-17 04:38:52

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文