返回   ShareGet 社群討論 > ≡ 電腦網路 ≡ > □ -- 程式設計討論

發表新主題 回覆
 
主題工具 顯示模式
  #1  
舊 2005-12-02, 11:33 AM
刀狂劍痴 的頭像
元老級
 
註冊日期: 2004-11-21
文章: 1,103
給予: 128 | 感謝 6 | 共 5 篇
積分: 4074 | 給分能力: 28
[轉貼] [.NET]以 ASP.NET 建立 MS-Excel 檔

熱絡一下吧~~

1. add Reference "COM object - Microsoft Excel 10.0 Object Library" in your project.
2. Run dcomcnfg.exe in DOS mode.
set the security for DCOM objects
- in Security tab
- Lauch and Activation permisson
- Access Permissin
- Configuration permisson
add the following users:
IWAN_xxxxxxxxxx
IUSR_xxxxxxxxxx
ASPNET
VS Developer

3. 加入以下程式
[code]
代碼:
Imports System.Runtime.InteropServices.Marshal
Imports System.Diagnostics
Imports System.Data
Imports System.IO
Imports Microsoft
..
..
..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
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 WBcnt As Integer
Dim ObjFS
ObjFS = Server.CreateObject("Scripting.FileSystemObject")

GC.Collect()
GC.WaitForPendingFinalizers()

oExcel.Visible = False : oExcel.DisplayAlerts = False
oBooks = oExcel.Workbooks
oBook = oBooks.Add
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), Excel.Worksheet)
oCells = oSheet.Cells

WBcnt = oBook.Worksheets.Count

With oExcel
.Range("A1").Select()
.ActiveCell.FormulaR1C1 = "Hello Excel"
With .Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
End With
'Dim TFName As String = Server.MapPath("my" & Session.SessionID & ".xls")
oBook.SaveAs(Server.MapPath("my" & Session.SessionID & ".xls"))
oBook.Close()
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()

End With
End Sub
===================
**轉貼出處:藍色小舖**
===================

此文章於 2005-12-05 10:15 PM 被 刀狂劍痴 編輯.
回覆時引用此文章
發表新主題 回覆

書簽

主題工具
顯示模式

發文規則
不可以發表新主題
不可以發表回覆
不可以上傳附件
不可以編輯自己的文章

啟用 BB 代碼
論壇啟用 表情符號
論壇啟用 [IMG] 代碼
論壇禁用 HTML 代碼
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用
論壇跳轉


所有時間均為GMT -5。現在的時間是 11:03 PM


Powered by vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.