資料|網頁|owc
ASP通過OWC組件把網頁資料匯出EXECL檔案,實現代碼如下:
<%
'先要用regsvr32.exe msowc.dll註冊owc組件(msowc.dll安裝office2000後就有了,在office的安裝目錄下搜尋*owc*.chm可找到這關於owc的協助文檔)
Dim objOWC
Dim ExeclFileName
ExeclFileName = server.mappath("ExeclText.xls")
Set objOWC = Server.CreateObject("OWC.Spreadsheet")
With objOWC
.cells(1,1) = "以下資料來自企業財富[不鏽鋼報價交易平台]"
.cells(1,5) = "訂貨號:No.2006072815350096014"
.range("a1:d1").merge()
.range("e1:g1").merge()
.range("e1:g1").HAlignment = 3
.range("a1:g1").rowHeight=14.25*1.33
.range("a1:g1").Font.Name = "宋體"
.range("a1:g1").Font.Size = 9
.range("a1:g1").VAlignment = 1
.range("a1:g1").Borders(1).weight =1 '僅顯示下邊框 1,2,3,4分別對應右,下,左,上四個邊框(順時針)
.range("a1:g1").Borders.Color = "Black"
.cells(2,1) = "上海精鑄不鏽鋼製品有限公司"
.range("a2:g2").merge()
.range("a2:g2").Font.Name = "黑體"
.range("a2:g2").RowHeight = 50
.range("a2:g2").Font.Size = 14
.range("a2:g2").HAlignment = 2
.range("a2:g2").VAlignment = 1
.range("a2:g2").Font.Bold = true
.cells(3,1) = "Shang Hai Jing Zhu Bu Xiu Gang Zhi Pin You Xian Gong Si"
.cells(4,1) = "電話:021-63609459 傳真:021-63609453 地址:上海廈門路180號-3"
.range("a3:g3").merge()
.range("a4:g4").merge()
.range("a3:g3").Font.Name = "Arial"
.range("a4:g4").Font.Name = "宋體"
.range("a3:g4").Font.Size = 10
.range("a3:g4").RowHeight = 25
.range("a3:g4").HAlignment = 2
.range("a3:g4").VAlignment = 1
.cells(5,1) = "訂 貨 單"
.range("a5:g5").merge()
.range("a5:g5").Font.Name = "黑體"
.range("a5:g5").Font.Size = 16
.range("a5:g5").HAlignment = 2
.range("a5:g5").VAlignment = 1
.range("a5:g5").RowHeight = 30*1.33
.range("a5:g5").Font.Bold = true
.cells(6,1) = "序號"
.cells(6,2) = "產品名稱"
.cells(6,3) = "產品規格"
.cells(6,4) = "單位"
.cells(6,5) = "數量"
.cells(6,6) = "單價(含稅)"
.cells(6,7) = "合計"
.range("a6:g6").Font.Name = "宋體"
.range("a6:g6").Font.Size = 10
.range("a6:g6").Font.Bold = True
.range("a6:g6").VAlignment = 1
.range("a6:g6").HAlignment = 2
.range("a6:g6").RowHeight = 18 *1.33
.range("e6:g6").HAlignment = 3
For i = 1 to 5
.cells(6+i,1) = i
.cells(6+i,2) = "301A不鏽鋼無縫鋼管"
.cells(6+i,3) = "22*2.5"
.cells(6+i,4) = "Kg"
.cells(6+i,5) = "1.00"
.cells(6+i,6) = "0.00"
.cells(6+i,7) = "0.00"
Next
.range("a7:d" & 6+i).HAlignment = 2
.range("a6:g" & 6+i+1).Borders.Weight = 1
.range("a6:g" & 6+i+1).Borders.Color = "Black"
.cells(6+i,1) = "總計:"
.range("a" & 6+i & ":d" & 6+i).merge()
.range("a" & 6+i ).HAlignment = 1
.cells(6+i,5) = "5.00"
.cells(6+i,7) = "0.00"
.cells(6+i+1,1) = "銷售金額(大寫):零元零角零分"
.range("a" & 6+i+1 & ":g" & 6+i+1).merge()
.range("b6:b6").ColumnWidth = 18*10
.range("f6:f6").ColumnWidth = 7.5*10
.range("a7:g" & (6+i+2)).Font.Size = 10
.range("a7:g" & (6+i+2)).Font.Name = "宋體"
.cells(6+i+2,1) = "需方資訊"
.range("a" & 6+i+2 & ":g" & 6+i+2).merge()
.range("a" & 6+i+2 & ":g" & 6+i+2).RowHeight = 20 *1.33
.range("a" & 6+i+2 & ":g" & 6+i+2).HAlignment = 2
.range("a" & 6+i+2 & ":g" & 6+i+2).VAlignment = 1
.range("a" & 6+i+2 & ":g" & 6+i+2).Font.Size = 12
.range("a" & 6+i+2 & ":g" & 6+i+2).Font.Name = "黑體"
.cells(6+i+3,1) = "單位名稱:"
.cells(6+i+3,2) = "上海企購網路科技資訊發展有限公司(測試資料)"
.range("b" & 6+i+3 & ":g" & 6+i+3).merge()
.range("a" & 6+i+3).HAlignment = 3
.cells(6+i+4,1) = "單位地址:"
.range("a" & 6+i+4).HAlignment = 3
.cells(6+i+4,2) = "上海閔行區莘莊水清三村49號1501室"
.range("b" & 6+i+4 & ":g" & 6+i+4).merge()
.cells(6+i+5,1) = "電 話:"
.range("a" & 6+i+5).HAlignment = 3
.cells(6+i+5,2) = "021-54172198"
.cells(6+i+5,3) = "傳 真:"
.range("c" & 6+i+5).HAlignment = 3
.cells(6+i+5,4) = "021-54172196"
.range("d" & 6+i+5 & ":e" & 6+i+5).merge()
.cells(6+i+5,6) = "連絡人:"
.range("f" & 6+i+5).HAlignment = 3
.cells(6+i+5,7) = "張三"
.range("a" & 6+i+3 & ":g" & 6+i+5).Font.Name = "宋體"
.range("a" & 6+i+3 & ":g" & 6+i+5).Font.Size = 9
.range("a" & 6+i+3 & ":g" & 6+i+5).Borders.Weight=1
.range("a" & 6+i+3 & ":g" & 6+i+5).Borders.Color="Black"
.range("e7:g" & 6+i).NumberFormat = "0.00"
'偶的著作權資訊^_^(QQ:278919507)
.cells(6+i+6,1) = "Powered by Jimmy(菩提樹下的楊過) QQ:278919507 "
.range("a" & 6+i+6 & ":g" & 6+i+6).merge()
.range("a" & 6+i+6 & ":g" & 6+i+6).HAlignment = 3
.range("a" & 6+i+6 & ":g" & 6+i+6).RowHeight = 30*1.33
.range("a" & 6+i+6 & ":g" & 6+i+6).Hyperlink.Address = "http://blog.1jq.net"
End With
call objOWC.ActiveSheet.Export(ExeclFileName,0)
Set objOWC = Nothing
Response.Write "<a href='" & ExeclFileName & "' target=_blank>" & ExeclFileName & " 產生完畢</a>"
%>