客户端打开时找不到服务器上的Excel文件

时间:2015-02-18 07:56:47

标签: c# asp.net excel interop

使用C#和ASP.NET,我试图通过Microsoft Interop在服务器上读取Excel文件,对其应用一些处理,保存然后在客户端计算机上下载。在本地主机上,它工作正常但在客户端计算机上显示此消息

Server Error in '/' Application.

Microsoft Office Excel cannot access the file 'C:\inetpub\wwwroot\ICNMS\Mysheet.xlsx'. There are several possible reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.

这是我的代码:

    Microsoft.Office.Interop.Excel.Application objApp;
    Microsoft.Office.Interop.Excel.Workbook workBook;

    Microsoft.Office.Interop.Excel.Sheets objSheets;
    Microsoft.Office.Interop.Excel._Worksheet workSheet;

    Microsoft.Office.Interop.Excel.Range range;

    objApp = new Microsoft.Office.Interop.Excel.Application();
    workBook = objApp.Workbooks.Open("Mysheet.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, false, false);

Excel文件的路径不超过218个字符,并且不会被任何其他应用程序打开或使用。顺便说一下,该文件与网页存在于同一目录中#39 ; S。任何帮助都会非常有用。谢谢。

1 个答案:

答案 0 :(得分:1)

谢谢大家。问题解决了;我按照这个问题的答案中提供的步骤进行了操作:

Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'

创建目录" C:\ Windows \ SysWOW64 \ config \ systemprofile \ Desktop" (对于64位Windows)或" C:\ Windows \ System32 \ config \ systemprofile \ Desktop" (对于32位Windows)