国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

在asp.net中使用excel模板

2024-07-10 12:57:51
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

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 function

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凌源市| 东至县| 柏乡县| 南城县| 新晃| 阿瓦提县| 湖口县| 广水市| 麻江县| 上饶县| 汉沽区| 来宾市| 新密市| 苗栗市| 云龙县| 九江市| 蓝山县| 辉南县| 北流市| 东乌珠穆沁旗| 安义县| 山阳县| 洪洞县| 蚌埠市| 尉氏县| 萝北县| 仙游县| 嘉祥县| 临洮县| 都兰县| 大厂| 普兰店市| 隆子县| 福鼎市| 东丽区| 阿鲁科尔沁旗| 武冈市| 清镇市| 盐津县| 清镇市| 莆田市|