【发布时间】:2011-01-27 10:39:49
【问题描述】:
在我支持的现有 Web 应用程序中,有一个页面用于为某些数据生成 Excel 电子表格。 Web 服务器安装了 Excel 2002(太旧了...),并利用 Excel 对象的自动化来完成这项工作。
我完全清楚微软不推荐像这样自动化 Excel,但这是目前的工作方式,我从来没有分配任何时间来改变这一点。
这里是一些示例代码
Dim xlApp, xlBook, xlSheet
'create the Application Object and workbook object
Set xlApp = Server.CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets.Add
'turn off any alerts
xlApp.DisplayAlerts = False
xlApp.Visible = False
xlApp.ScreenUpdating = False
xlApp.DisplayFormulaBar = True
xlApp.CommandBars("Standard").Visible = True
xlApp.CommandBars("Formatting").Visible = True
xlApp.CommandBars("Chart").Visible = True
xlApp.CommandBars("Control Toolbox").Visible = True
xlSheet.Cells(1, 1).Value = "Test"
xlApp.ScreenUpdating = True
xlApp.ActiveWorkbook.SaveAs ("C:\Temp\Test.xls"), -4143
xlApp.Quit
Set xlApp = Nothing
Web 服务器是 Windows 2003 服务器,运行 IIS6,一切正常。但是,我们目前正在升级到使用 Windows 2008 服务器,运行 IIS7.5,上面的代码不再工作。返回的消息如下:
Microsoft Excel error '800a03ec'
SaveAs method of Workbook class failed
xxxxxx/Test_Excel.asp, line 42
问题是,如果我使用上面的代码创建一个简单的 .vbs 文件并运行它,一切都会按预期工作。只有在作为 ASP 页面运行时才会失败。
它试图写入的文件夹应该具有正确的权限(我向其中添加了“所有人”,具有完全访问权限)。
有人对为什么会发生这种情况有任何建议吗?
谢谢!
【问题讨论】:
标签: excel asp-classic windows-server-2008 iis-7.5