 |
|
การทำ COM และ Server ทำอย่างไร จากตัวอย่าง จากตัวอย่างที่ทำไปแล้ว Run ASP ปรากฎวว่ามันมาตายที่ Excel.Application |
|
 |
|
|
 |
 |
|
จากตัวอย่าง
<% @ Language="VBScript" %>
<% Option Explicit %>
<%
Response.Buffer=True
Response.Clear
'Response.ContentType = "application/vnd.ms-excel"
Dim xlApp,xlBook,xlSheet,objConn,objRS,iRow,strConn,strQuery
Dim objFileCache,bXlsFile,strFileName,arrData
iRow = 4
strFileName = "MyChart.xls"
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.Mappath("Sales00.mdb")
strQuery = "SELECT ProductName,ProductIncome FROM ProductSales"
objConn.Open strConn
objRS.Open strQuery, objConn
If Not objRS.EOF and Not objRS.BOF Then
arrData = objRS.GetRows()
Else
bNoRecords = True
End If
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
'-------------------------------- END of DATA Acquisition---------------------
'-------------------------------- BEGIN XLS Generation -----------------------
strFileName = "MyChart.xls"
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
จากตัวอย่างที่ทำไปแล้ว Run ASP ปรากฎวว่ามันมาตายที่ Excel.Application
ก็เลยอยากถามว่า การทำ COM บน Server ทำอย่างไร ครับ ใครรู้ช่วยอธิบายให้ที
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
27 ก.ย. 2550 11:04:30 |
By :
ปู |
View :
1927 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (ASP)
<%
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Application.Visible = False
With xlApp.ActiveSheet.Cells(1,1)
.Value = "Overall Product Sales 2000"
.Font.Bold = True
.Font.Name = "Tahoma"
.Font.Size = 16
End With
With xlApp.ActiveSheet.Cells(3,1)
.Value = "Product Name"
.Font.Italic = True
.Font.Name = "Tahoma"
.Font.Size = 13
.MergeCells = True
End With
With xlApp.ActiveSheet.Cells(3,2)
.Value = "Product Income"
.Font.Italic = True
.Font.Name = "Tahoma"
.Font.Size = 13
.MergeCells = True
End With
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strConn = strConn & Server.MapPath("Sales00.mdb")
strQuery = "SELECT ProductName,ProductIncome FROM ProductSales"
While Not objRS.EOF
xlApp.ActiveSheet.Cells(iRow,1).Value = objRS("ProductName")
xlApp.ActiveSheet.Cells(iRow,2).Value = objRS("ProductIncome")
xlApp.ActiveSheet.Cells(iRow,2).NumberFormat = "$#,##0.00"
iRow = iRow + 1
objRS.MoveNext
Wend
xlSheet.SaveAs Server.MapPath("MyExcelBook.xls")
xlApp.Application.Quit
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
%>
Ref : ASP Excel (Excel.Application)
|
 |
 |
 |
 |
Date :
2009-04-25 15:50:28 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สุดยอดเลย
|
 |
 |
 |
 |
Date :
2009-09-07 13:45:27 |
By :
คนมีแผน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|