将不同类型的ADO数据源导出到Excel(解决方案)
2007-04-03 17:01
573 查看
主 题: | 将不同类型的ADO数据源导出到Excel(解决方案) | |
作 者: | sas_razor (散步的水) | |
等 级: | ||
信 誉 分: | 100 | |
人 气: | 154 | |
所属社区: | C++ Builder 数据库及相关技术 | |
问题点数: | 0 | |
回复次数: | 0 | |
发表时间: | 2006-8-15 10:35:34 | |
**复制
You can use the SELECT INTO statement to copy data from any data source that Jet can read into any data destination, creating a new table (or, in the case of Excel, a new worksheet) on the fly. Do not use the dollar sign syntax(不要使用$符标注工作薄), for example [Sheet1$], when you refer to a sheet name as your destination. The destination workbook can exist or not exist; however, the destination sheet must not yet exist.
There are three ways to write the copy command that copies the entire Customers table from the Microsoft Access Northwind database into a new sheet in an Excel workbook. Each syntax requires a single SQL statement and creates column headings in the first row of the destination worksheet.
---------------------------------------------------------
The following example uses the SELECT INTO syntax:Dim strSQL As String
strSQL = "SELECT * INTO [Excel 8.0;Database=" & App.Path & _
"/book1.xls].[Sheet1] FROM Customers"
cnSrc.Execute strSQL
------------------------------
The following example uses the SELECT INTO ... IN syntax: strSQL = "SELECT * INTO [Sheet1] IN '' [Excel 8.0;Database=" & App.Path & _
"/book1.xls] FROM Customers"
--------------------------------------
where the bracketed destination database information is preceded by an empty pair of single quotes for the type argument (the "Excel 8.0" portion), which is included within the brackets when you use this syntax.
• The following example uses the alternate syntax for the IN clause: strSQL = "SELECT * INTO [Sheet1] IN '" & App.Path & _
"/book1.xls' 'Excel 8.0;' FROM Customers"
------------------------------------------
不知道为什么前两种不行.
** 追加
How to Append
You can use the INSERT INTO ... IN statement to append data from any data source that Jet can read into any data destination. Both the destination workbook and worksheet must exist. Now that you are referring to an existing worksheet, you must use the standard dollar sign syntax(必须使用$符标注工作薄), for example, [Sheet1$], when you refer to a sheet name as your destination. In addition, the column headings must already be present; in other words, this statement can only be used to append to an existing table.
There are two ways to write the append command that copies the entire Customers table from the Northwind database into an existing Excel worksheet, which already has the appropriate column headings. • The following example uses the SELECT INTO ... IN syntax: strSQL = "INSERT INTO [Sheet1$] IN '' [Excel 8.0;Database=" & App.Path & _
"/book1.xls] SELECT * FROM Customers"
where the bracketed destination database information is again preceded by an empty pair of quotes for the type argument, which is now included within the brackets.
• The following example uses the alternate syntax for the IN clause:
strSQL = "INSERT INTO [Sheet1$] IN '" & App.Path & _
"/book1.xls' 'Excel 8.0;' SELECT * FROM Customers"
追加也是第二种才行.
总之问题解决了,与大家分享下.
能导出excel的话,dbf,txt的应该都没有问题了.
相关文章推荐
- Java web中不同浏览器间导出Excel文件名称乱码问题解决方案
- Java web中不同浏览器间导出Excel文件名称乱码问题解决方案
- JAVA POI Excel导出,数据源可以是List<Map>或者List<Model>类型
- 封装jxl导出不同数据类型的excel
- ASP.NET 导出到EXCEL LINQ适用 自定义列 自定义数据源 解决中文乱码问题 解决方案
- 使用ADO.net将数据导出到Excel并提供下载
- Java 实现导出excel表 POI/Java实现不同excel格式(*.xls、*.xlsx)文件的读取
- delphi使用ado导出excel(2)
- vs2008 错误--找不到类型或命名空间名称“Excel”(是否缺少 using 指令或程序集)解决方案
- DataGrid导出Excel解决方案
- 将数据源DataSet导出成Excel表格形式
- Django导出excel中文乱码解决方案
- DataGrid导出Excel解决方案
- 扩展GridView控件(8) - 导出数据源的数据为Excel、Word或Text
- 导出Excel时有多个数据源(多个Sheet 连接上一篇导出Excel)
- 【源代码共享】VB+ADO导出EXCEL
- phpexcel 读取含多个sheet的excel,将从数据库中检索出的数据分别写入该excel不同的sheet中 并导出该excel
- 简单、完美的导出excel/word报表解决方案
- Java类型信息与用反射机制编写通用的Excel导入导出
- TestComplete ADO连接SQL数据库,查询数据导出到EXCEL