【发布时间】:2013-10-02 12:59:01
【问题描述】:
我收到了错误:
Microsoft Excel 无法访问文件“..\services\Calculator.xlsx”。 有几个可能的原因:
• 文件名或路径不 存在。
• 文件正被另一个程序使用。
• 你的工作簿 正在尝试保存与当前打开的工作簿同名。
有什么想法吗?
我试过了,但似乎不起作用Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'
Dim xlApp As Application = New Application
Dim xlWB As Workbook
xlWB = xlApp.Workbooks.Open(Server.MapPath("~") + "\services\Calculator.xlsx", 2, True)
Dim xlSheet As Worksheet = xlWB.Sheets("input output")
xlSheet.Cells(7, 8).value = drpTrades.SelectedValue
xlSheet.Cells(12, 8).value = Convert.ToDecimal(txtIncome.Text)
xlSheet.Cells(9, 8).value = loan.Text
Dim xlRebate As Decimal = xlSheet.Cells(18, 8).value
If xlRebate < 0 Then lblRebate.ForeColor = System.Drawing.Color.Red
lblRebate.Text = "£" + Math.Round(xlRebate, 2).ToString
xlWB.Close(False)
xlApp.Quit()
ReleaseComObject(xlApp)
xlApp = Nothing
【问题讨论】:
-
尝试绝对路径(暂时)。当前的工作目录与其说是科学,不如说是一门艺术。
-
我有时会在关闭“Excel”应用程序时遇到问题。在 ASP 中,这可能会变得非常糟糕。登陆服务器并检查任务管理器以查看它是否正在运行。此外,在那里,看看您是否可以在登录到服务器时打开文件。它可能会让您了解正在发生的事情。
-
路径似乎正确。是的可以打开文件
标签: vb.net excel excel-interop