使用 DocumentFormat.OpenXML 创建格式化电子表格?
我想使用 DocumentFormat.OpenXML 创建电子表格。我一直很难让它发挥作用,所以我想我应该在这里寻求帮助。
我想以编程方式在运行时创建一个电子表格,以便从 ASP.net 网站下载。
(1) 我希望电子表格包含来自 SQL 数据库的一些数据行。我希望行标题由黄色背景上的黑色文本组成。我有一些字符串数据,顺便说一句,其中可能包含数字字符串。我希望它始终被视为字符串(即,我不希望 31415926535 显示为 3.1415926e10)
(2) 我希望在最后一行数据下方显示一个 300px x 300px PNG 图像。该图像在服务器上保存为 hello.png。
我需要编写什么代码才能使(1)和(2)发生?
I want to create a spreadsheet with DocumentFormat.OpenXML. I've been having a really hard time getting it to work, so I thought I'd ask for help here.
I would like to programmatically create a spreadsheet at runtime to be downloaded from an ASP.net web site.
(1) I want the spreadsheet to contain some rows of data from a SQL Database. I want the row headers to consist of black text on a yellow background. I have some string data, which incidently, may contain strings of digits. I want it to be treated as a string at all times (ie, I don't want 31415926535 to be presented as 3.1415926e10)
(2) I would like to have a 300px x 300px PNG image appear below the last row of data. The image is saved on the server as hello.png.
What code do I need to write to make (1) and (2) happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近做了类似的事情。我相信实现您所需的最佳方法是首先创建一个模板
Excel
电子表格。然后,使用打开 XML Productivity Tool
,反映创建它所需的代码。通读有限的文档让我陷入了困境,直到我开始使用
生产力工具
。它确实会生成一些无关的代码,但它可以让您了解重点并且非常有帮助。I've recently done something similar. I believe the best way to accomplish what you need is to first create a template
Excel
spreadsheet. Then, usingOpen XML Productivity Tool
, reflect the code needed to create it.Reading through the limited documentation left me spinning my wheels until I started using the
Productivity Tool
. It does generate some extraneous code but it gets you to the meat and is very helpful.