关于在asp.net中读取excel文件的问题

关于在asp.net中读取excel文件的问题,asp.net,excel,Asp.net,Excel,我尝试在Asp.Net中读取excel文件。我有一个错误: Microsoft Excel cannot access the file 'C:\tablobilgisayar.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 t

我尝试在Asp.Net中读取excel文件。我有一个错误:

Microsoft Excel cannot access the file 'C:\tablobilgisayar.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 ExcelObj = null;
        ExcelObj = new Microsoft.Office.Interop.Excel.Application();

        Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(
           @"C:\tablobilgisayar.xlsx", 0, true, 5,
           "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false,
            0, true);
我的磁盘上有这个文件,路径为true。我也使用iis7.5。我认为这是关于IIS的。因为我将粘贴文件复制到另一个使用VisualStudio本地IIS的空asp.net项目中,并且成功了


有人对此有想法吗?谢谢。

确保IIS对该位置具有权限。

正如其他人指出的,您可以通过互操作从Excel读取文件,但不建议这样做,因为它速度慢,必须在服务器上安装Excel,并且可能会导致线程挂起。 一个很好的替代方法是使用EPPLUS库读取*xlsx/*.xlsm文件,它是免费的,使用起来更好(直接使用linq、datatable等,不需要繁琐的互操作界面),而且速度快1000%(我不是开玩笑)。
我知道,你必须更改你的应用程序,这很糟糕,但我以前尝试过Interop,但我感到震惊的是,这些替代方案要好得多。

你应该知道,Microsoft不支持或建议从ASP.NET进行Interop。从ASP.NET或其他服务器技术使用Office互操作是一个可怕的想法。这些API是为在桌面应用程序中使用而编写的,用于自动化Office(一套桌面应用程序)。服务器应用程序在许多方面都不同,因此在其中使用Office互操作是一个非常非常糟糕的主意。它也不受Microsoft支持,可能会违反您的Office许可证。看见