国产探花免费观看_亚洲丰满少妇自慰呻吟_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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 达尔| 柞水县| 弥勒县| 溧阳市| 花莲市| 年辖:市辖区| 宜君县| 镇赉县| 兰考县| 皋兰县| 天柱县| 会理县| 根河市| 祁连县| 泰来县| 舒兰市| 赤峰市| 长顺县| 阳原县| 宜兰县| 南溪县| 大洼县| 珠海市| 高安市| 当雄县| 澄迈县| 托克逊县| 沂源县| 临武县| 亚东县| 凯里市| 鹤岗市| 大港区| 麻栗坡县| 郯城县| 阿克陶县| 当涂县| 东光县| 霍城县| 辽阳市| 白银市|