65.9K
CodeProject 正在变化。 阅读更多。
Home

在 .Net 中导出 2 个 Excel 文件

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.08/5 (15投票s)

2005年12月9日

1分钟阅读

viewsIcon

80495

downloadIcon

442

导出到 Excel

下载源代码
引言

此代码用于将数据导出到 Excel……
只需参考并修改一些内容,即可得到结果。
此代码对 asp.net 和 vb.net 都有效。
只需将参数传递给过程,例如 datatable、文件名、文件路径、列名。
它会创建 Excel 文件,将数据导出到 Excel 文件并保存到目标文件夹。

  ' 步骤 1:解压缩文件
' 步骤 2:将 dll 文件复制到应用程序的 bin 文件夹中
' 步骤 3:引用此 .dll
' 步骤 4:复制以下代码并粘贴到程序中,在需要的地方进行一些修改,例如目录、文件名……
     

        Dim dad As New SqlClient.SqlDataAdapter("select * from authors", "server=localhost;user id=sa;password=;Initial catalog=pubs;")
 Dim ds As New DataSet
        Dim obj As New Hari_Export2Excel.NameSpace_Export2Excel.Class_Export2Excel
        Dim filepath As String = "C:\TargetDirectory\" '或者 server.mappath("../outputdirectory/")
        Dim filename As String = "abc.xls"
        dad.Fill(ds)

        '' 发送标题列名
        'Dim col() As String = {"COLUMN ONE", "COLUMN TWO", "COLUMN THREE"}
        'obj.Export2Excel_By_Srihari(filename, filepath, ds.Tables(0),  col)

        ' 从数据库获取默认列名
        obj.Export2Excel_By_Srihari(filename, filepath, ds.Tables(0), Nothing)

        ' 从保存路径访问文件
        'Response.Redirect(filepath & filename)

 

 

 

 

在 .Net 中导出 2 个 Excel 文件 - CodeProject - 代码之家
© . All rights reserved.