数据表转换到Excel 2007(.xlsx)格式 [英] Convert datatable to excel 2007(.xlsx)

查看:118
本文介绍了数据表转换到Excel 2007(.xlsx)格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表我需要把到Excel 2007格式,并将其保存为Excel文件格式(.xlsx)2007。

I have an DataTable I need to put into Excel 2007 format and save it as an excel file(.xlsx) 2007.

谁能帮我实现这一目标?

Can anyone help me to achieve this?

推荐答案

您可以使用OLEDB数据提供程序和公正的对待Excel中如以遍历您的DataTable行的另一个ADO.NET数据源,将它们插入到Excel电子表格。以下是指导您完成了很多细节的Microsoft知识库文章。

You can use an OLEDB data provider and just treat Excel as another ADO.NET data source in order to loop through your DataTable rows and insert them into the Excel spreadsheet. Here's a Microsoft KB article that walks you through a lot of the details.

http://support.microsoft.com/kb/316934/en-us

最重要的事情要记住的是,你可以在工作簿中创建工作簿和床单,你可以通过在名称末尾附加一个$引用现有的表。如果省略了$在工作表名称的结尾,OLEDB提供程序会认为这是一个新的工作表,并会尝试创建它。

The big thing to keep in mind is that you can create workbooks and sheets within the workbook, and you can reference existing sheets by appending a '$' at the end of the name. If you omit the '$' at the end of the sheet name, the OLEDB provider will assume that it's a new sheet and will try to create it.


工作表名称的美元符号为b的表中存在$ b $的指示。如果您正在创建$ B $巴新表,如
讨论创建新的工作簿和第表
节,不要使用
中的美元符号。

The dollar sign following the worksheet name is an indication that the table exists. If you are creating a new table, as discussed in the Create New Workbooks and Tables section of this article, do not use the dollar sign.

您可以创建并于2003年(的.xls)或2007格式(XLSX)的电子表格,这对您的连接字符串定义 - 您指定的文件,你是打算写,只是指定扩展。确保你使用正确的OLEDB提供程序的版本。

You can create and spreadsheet in 2003 (.xls) or 2007 format (xlsx), and that's defined on your connection string -- you specify the file that you're going to write to, and just specify the extension. Make sure you use the right OLEDB provider version.

如果你想创建一个2003(.xls的)版本,您可以使用此连接字符串:

If you want to create a 2003 (.xls) version, you use this connection string:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties="Excel 8.0;HDR=YES

如果你想创建一个2007(.xlsx)格式的版本,您可以使用此连接字符串:

If you want to create a 2007 (.xlsx) version, you use this connection string:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Book1.xlsx;Extended Properties="Excel 12.0;HDR=YES

您可能不得不从微软下载ACE提供商,以创建XLSX文件。你可以找到它这里

You may have to download the ACE provider from Microsoft in order to create XLSX files. You can find it here.

我通常使用的XLS供应商,所以我还没有与XLSX提供尽可能多的工作。

I usually use the XLS provider, so I haven't worked with the XLSX provider as much.

希望这帮助。让我知道,如果你有其他的问题。

Hope this helps. Let me know if you have other questions.

这篇关于数据表转换到Excel 2007(.xlsx)格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆