这段代码在我的本地很好地运行,但当我将它部署到服务器时,它说“无法创建对象Excel.Application”
我试图将它运行到另一台本地计算机,它运行良好。我不知道这个问题是什么。请帮忙。谢谢
Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range
' Start Excel and get Application object.
appXL = CreateObject("Excel.Application")
appXL.Visible = True
' Add a new workbook.
wbXl = appXL.Workbooks.Add
shXL = wbXl.ActiveSheet
'Add table headers going cell by cell.
Dim heads() As String = {"", "MONo", "PostingDate", "DocDate", "SBU", "Operation", "Resource", "TimeType", "StartDate", "StartTime", "EndDate", "EndTime", "NoofResources", "Remarks", "Quantity", "Rejects"}
For head1 As Integer = 1 To 15
shXL.Cells(1, head1).Value = heads(head1)
Next
Dim remarks1 As String = ""
If lblrem.Text = "" Then
remarks1 = Application("rec_remarks")
Else
remarks1 = lblrem.Text
End If
Dim body() As String = {"", txtmo.Text, lbleDate.Text, lbleDate.Text, Sap_routing, Operation, machinename, UCase(lblrem2.Text), lblsDate.Text, lblsTime.Text, lbleDate.Text, lbleTime.Text, no_ofres, remarks1, txtgoods.Text, txtrejects.Text}
For body1 As Integer = 1 To 15
shXL.Cells(2, body1).Value = body(body1)
Next
appXL.Visible = True
appXL.UserControl = True
' Release object references.
Dim sql_getsettings As String = "select * from path_settings where id = 1"
Dim readSettings As New SqlCommand(sql_getsettings, conn)
Dim settingsRow As SqlDataReader
conn.Open()
settingsRow = readSettings.ExecuteReader
While settingsRow.Read
strSetting = settingsRow(1)
End While
conn.Close()
Dim myXlsFileName As String = "MO" & txtmo.Text & Format(Now, "yyyyMMdd") & Format(Now, "hhmmss")
If Not File.Exists("C:\Documents and Settings\All Users\Desktop\" & myXlsFileName & ".xls") Then
wbXl.SaveAs(Filename:=strSetting & myXlsFileName & ".xls")
End If
raXL = Nothing
shXL = Nothing
wbXl = Nothing
appXL.Quit()
appXL = Nothing
Exit Sub
Err_Handler:
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
当我尝试在我的本地iis中发布我的网站时,它会在
中出现服务器错误错误'/' Application.
Cannot create ActiveX component.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: Cannot create ActiveX component.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
但是当我尝试在visual studio下运行我的程序时效果很好