One of the ways that I have done this is using Office XML to generate the documents. Since you have a specific format that the document needs to be in, things might be a bit harder, but the way I have done things before in the past is to export the data that needs to be displayed on the report to an XML file (either saved on disk or in the memory) and then apply an XSL transform to convert things over to the correctly formatted document that Excel can load. For reference, here are some links for you:
use OpenOffice (they have a mode where no UI is loaded/shown)
use the FileHelpers library (you can read/write data to an excel file)
I must say I don't have experience with either of them... but they sound like solid alternatives beside the JET.OLEDB provider and the Xml-to-Excel through Xsl (which I both have used in the past) mentioned by Chris and Rob.
Just wanted to help you on your way and mention some alternatives (I don't expect much points :) )
Although this won't process your existing spreadsheets, a really simple and low-tech way to generate Excel files is to create a html file with the correct content-type and use the .xls extension. When Excel (on the client) opens the file, it is treated as if it was a native spreadsheet.
发布评论
评论(7)
我很确定你可以使用 OleDB 打开 Excel 文件(带有模板)
示例 1
链接到文章 1
示例 2
链接到第 2 条
打开连接后,您应该能够按照您喜欢的方式读取和写入!
I am pretty sure you can can use OleDB to open the excel file(with the template)
Example 1
Link to article 1
Example 2
Link to Article 2
Once you have opened the connection you should be able to read and write to it however you like!
您可以尝试 Spire.XLS ( http://www.e-iceblue.com/xls /xlsintro.htm )
它不是免费的,但可以很好地读取和创建 XLS 文档,而无需在服务器上安装 Excel。
You can try Spire.XLS ( http://www.e-iceblue.com/xls/xlsintro.htm )
It's not free, but does a great job of reading and creating XLS documents without having to have Excel present on the server.
我完成此操作的方法之一是使用 Office XML 生成文档。 由于文档需要采用特定的格式,所以事情可能会有点困难,但我过去所做的事情是将需要在报表上显示的数据导出到 XML 文件(保存在磁盘或内存中),然后应用 XSL 转换将内容转换为 Excel 可以加载的格式正确的文档。 作为参考,以下是一些供您参考的链接:
One of the ways that I have done this is using Office XML to generate the documents. Since you have a specific format that the document needs to be in, things might be a bit harder, but the way I have done things before in the past is to export the data that needs to be displayed on the report to an XML file (either saved on disk or in the memory) and then apply an XSL transform to convert things over to the correctly formatted document that Excel can load. For reference, here are some links for you:
尝试Aspose。 Cells - 它非常适合这个。
Try Aspose.Cells - it works great for this.
Telerik RAD Grid for Asp.NetAJAX 具有很好的 Excel 导出功能。
Telerik RAD Grid for Asp.NetAJAX has nice Excel export.
另外两个解决方案是:
我必须说我对它们都没有经验...但它们听起来像是 JET.OLEDB 提供程序和通过 Xsl 的 Xml-to-Excel 之外的可靠替代品克里斯和罗布提到过(我过去都用过)。
只是想帮助您并提及一些替代方案(我不期望太多:))
Another two solutions are:
I must say I don't have experience with either of them... but they sound like solid alternatives beside the JET.OLEDB provider and the Xml-to-Excel through Xsl (which I both have used in the past) mentioned by Chris and Rob.
Just wanted to help you on your way and mention some alternatives (I don't expect much points :) )
虽然这不会处理您现有的电子表格,但生成 Excel 文件的一种非常简单且技术含量较低的方法是创建具有正确内容类型的 html 文件并使用 .xls 扩展名。 当 Excel(在客户端上)打开该文件时,它会被视为本机电子表格。
示例:
警告:当然,您不会在真实文件中包含所有缩进和空格! 我正在使用 Excel 2003。
该技术的另一个小好处是这些文件的生成效率非常高。
缺点:我还没有找到将 html 转换为多个工作表的方法,或者做任何特别技术性的事情。
Although this won't process your existing spreadsheets, a really simple and low-tech way to generate Excel files is to create a html file with the correct content-type and use the .xls extension. When Excel (on the client) opens the file, it is treated as if it was a native spreadsheet.
Example:
Caveats: Of course you would not include all the indentation and spacing in the real file! I am using Excel 2003.
Another small bonus of this technique is that these files are very efficient to generate.
Downsides: I've not found a way to turn html into multiple Worksheets, or to do anything particularly technical.