我创建了每行读取excel文件的Web应用程序,当我从本地主机运行它时,它可以正常工作。 但是当我将它部署到Web服务器[win 7 64 bit]时,会产生如下错误:
Microsoft Excel cannot access the file 'C:\TestReadExcel\testdata.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):
Line 195: Dim workbook = xlApplication.Workbooks.Open(fileName)
..
..
我已经尝试了各种方式:
1. add folder **desktop** C:\Windows\System32\config\systemprofile\ and in C:\Windows\SysWOW64\config\systemprofile -it not working
2. add security account for network services and iis_iusrs in DCOM config - microsoft excel application (allow all) - it not working
3. already restart my web server after i configured step 1-2 , and still not working
4. already test to add security account full control in folder C:\TestReadExcel\ , and still not working
我还有什么需要做的才能解决这个问题吗? 或者有没有办法比使用interop excel?
需要你的帮助,谢谢你。
答案 0 :(得分:0)
使用Server.Mappath获取文件路径。并确保IIS_User对您放置Excel文件的文件夹具有读取权限。