在asp.net中使用excel模板
文章来源:http://www.itnose.net/detail/6027733.html
更多文章:http://www.itnose.net/type/15.html
Imports System.Runtime.InteropServices.Marshal
Then, replace the default Page_Load event with the code in Figure 1.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim oExcel As New Excel.Application()
Dim oBooks As Excel.Workbooks, oBook As Excel.Workbook
Dim oSheets As Excel.Sheets, oSheet As Excel.Worksheet
Dim oCells As Excel.Range
Dim sFile As String, sTemplate As String
Dim dt As DataTable = _
CType(Application.Item("MyDataTable"), DataTable)
sFile = Server.MapPath(Request.ApplicationPath) & _
"\MyExcel.xls"
sTemplate = Server.MapPath(Request.ApplicationPath) & _
"\MyTemplate.xls"
oExcel.Visible = False : oExcel.DisplayAlerts = False
'Start a new workbook
oBooks = oExcel.Workbooks
oBooks.Open(Server.MapPath(Request.ApplicationPath) & _
"\MyTemplate.xls") 'Load colorful template with chart
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
oSheet.Name = "First Sheet"
oCells = oSheet.Cells
DumpData(dt, oCells) 'Fill in the data
oSheet.SaveAs(sFile) 'Save in a temporary file
oBook.Close()
'Quit Excel and thoroughly deallocate everything
oExcel.Quit()
ReleaseComObject(oCells) : ReleaseComObject(oSheet)
ReleaseComObject(oSheets) : ReleaseComObject(oBook)
ReleaseComObject(oBooks) : ReleaseComObject(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
System.GC.Collect()
Response.Redirect(sFile) 'Send the user to the file
End Sub
'Outputs a DataTable to an Excel Worksheet
Private Function DumpData(ByVal _
dt As DataTable, ByVal oCells As Excel.Range) As String
Dim dr As DataRow, ary() As Object
Dim iRow As Integer, iCol As Integer
'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
oCells(2, iCol + 1) = dt.Columns(iCol).ToString
Next
'Output Data
For iRow = 0 To dt.Rows.Count - 1
dr = dt.Rows.Item(iRow)
ary = dr.ItemArray
For iCol = 0 To UBound(ary)
oCells(iRow + 3, iCol + 1) = ary(iCol).ToString
Response.Write(ary(iCol).ToString & vbTab)
Next
Next
End Fun
相关推荐
【ASP.NET编程知识】ASP.NET之Excel下载模板、导入、导出操作.docx
主要介绍了asp.net使用npoi读取excel模板并导出下载的示例,大家参考使用吧
ASP.NET中数据库数据导入Excel并打印
ASP.NET/C# 使用NPOI 将数据导入到模板Excel里[源代码] . 支持xlsx,如果需要支持xls,请使用HSSFWorkbook
asp.net 导出图片到excel .net导出excel
主要给大家介绍了关于ASP.NET Core中如何使用EPPlus导入出Excel文件的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
源代码,注释,asp.net sqlsever等
这个类库没有提供Excel样式设置的方法,建议使用模板,可以在模板中把格式控制好;ExcelHelper提供了实现Excel的基本操作的一些方法,包括: 1、将二维数组和DataTable的数据导入Excel,可以按指定每页的记录行数...
YYControls应用之TreeView实现复选联动及GridView导出Excel、Word、Text 联动复选框(复选框的全选和取消全选)。选中指定的父复选框,则设置其所有子复选框为选中状态;取消选中指定的父复选框,则设置其所有子复...
本文介绍了ASP.NET下Excel下载模板、导入、导出操作,供大家参考,具体内容如下 1.下载模板功能 protected void btnDownload_Click(object sender, EventArgs e) { var path = Server.MapPath((upfiles\\) + test....
基于ASP.NET MVC框架的学习项目,包含MVC的框架的设计思路,通俗易懂学习MVC框架,项目中包含NPOI控件的使用方法(优点:导出几万条数据几秒即可下载下来)以及NPOI导出Excel表到数据库,Aspose.Cells的使用(导入、...
.net开发,网页excel导入导出功能模板,网页表格直接导出为excel 2003和2007格式。
ASP.NET Maker 注册版是一套非常容易使用的代码生成工具,同 ASPMaker,它能快速地根据数据库连接资料来源中生成一套完整的 ASP.NET 程序。 ASP.NET Maker 2016 英文特别版ASP.NET Maker 2020 英文特别版 支持以下...
在ASP.NET中使用WINDOWS验证方式连接SQL SERVER数据库 改进ADO.Net数据库访问方式 ASP.NET 2.0 绑定高级技巧 简单实用的DataSet更新数据库的类+总结 [ADO.NET]由数据库触发器引发的问题 为ASP.NET封装的SQL数据库...
//pdf模板文件 string tempFile = Path.Combine(fileDire, "temppdf.html"); saveDoc = Path.Combine(fileDire, "viewFiles/onlinepdf.html"); result = PdfToHtml( sourceDoc, System.Web.HttpContext....
内含excel,owc使用的类库,其中excel类库特别详细,使用方便,还附带样式操作。 并且可以动态设置报表模板
Aspose生成 导出 导入 excel word 例子+帮助文档【CSDN11个例子】
使用 Free Spire.XLS for .NET,开发人员可以在 .NET(C#, VB.NET, ASP.NET, .NET Core) 应用程序中快速对 Excel 文档进行各种编程操作,如根据模板创建新的 Excel 文档,编辑现有 Excel 文档以及对 Excel 文档进行...