完整的代码如下: using System;using System.Data;using System.Collections;using System.Data.SqlClient;using System.IO;namespace DtsExcel} 用法如下: string strdespath="c:\\File\\File\\abc.xls";//该文件夹和文件都可以实际不存在,程序能自动创建 string tablename="authors"; //表名(用于导入到EXCEL里Sheet的名字,对程序毫无用处) //以下几种都可以 // 第一种// string strsql="SELECT [au_lname]"+ // " FROM [pubs].[dbo].[authors]";//要显示的列信息// //第二种// string strsql="SELECT [au_lname]"+ // " FROM [pubs].[dbo].[authors] WHERE au_id='172-32-1176'";//要显示的列信息 //第三种 string strsql="SELECT * "+ " FROM [pubs].[dbo].[authors]";//要显示的列信息 string connctionstring="server=(local);uid=sa;pwd=;database=pubs";//数据库连接 DtsExcel.AppExportData dtsclass=new DtsExcel.AppExportData(strdespath,tablename,strsql,connctionstring); if(dtsclass.ExportData())//导出 这种方式性能比较好,特别适用于数据量很大的情况,但是灵活性不高。各位看着用吧。 相关文章: 2022-01-08 2021-07-06 2021-08-15 2022-12-23 2022-12-23 2021-12-04 2021-07-18