在asp.net中使用excel模板
来源:互联网 发布:阿里云个人邮箱登录 编辑:程序博客网 时间:2024/06/06 17:23
在asp.net中使用excel模板
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中使用excel模板
- 在asp.net中使用excel模板
- 在asp.net中使用excel模板
- 在asp.net中使用excel模板
- 在asp.net中使用excel模板
- 在ASP.NET中使用EXCEL
- ASP.NET 中 NPOI & LinqToSql 使用模板 导出 Excel
- 在ASP.NET中使用EXCEL之一 权限设置
- asp.net两种方式在模板excel中插入图片:npoi和c# com组件
- ASP.NET MVC 4.0 中使用NPOI 2.2.0 按模板生成Excel报表
- 在asp.net中调用Excel 文件
- 在ASP.NET中访问Excel文件
- 在ASP.NET中读写Excel文件
- 在ASP.Net中生成Excel
- 在asp.net中调用Excel 文件
- 在ASP.NET中导出excel表
- Asp.net 中Excel通过模板导出中发布问题
- 在ASP.NET中使用EXCEL之二 读取Excel文件
- 函数热身 练习一
- POJ 2208 Pyramids&&HDU 1411 校庆神秘建筑(欧拉四面体公式)
- C++ Set 容器
- Linux中inode的理解
- Libcurl使用OpenSSL编译出现undefined reference to `COMP_CTX_free'错误备忘
- 在asp.net中使用excel模板
- 二叉树的遍历
- 为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?
- 数据结构 - 表插入排序 详解 及 代码(C++)
- 一个小问题。
- jquery的ajax请求与springMVC交互
- 什么是反向代理?
- 使用js判断是手机访问还是电脑访问
- 获取屏幕尺寸大小和密度