以前用代码读取Excel的时候从没有遇到过此错误,开始以为是权限问题,但是用普通的Console Application时却能够读取,放到web application里面就出现此错误:
导致错误的是第三行:
object missing = Missing.Value;
Excel.Application excelApp = new Excel.Application();
Excel.WorkbookClass wbclass = (Excel.WorkbookClass)excelApp.Workbooks.Open("c:\\timesheet_template.xls", missing, false, missing, missing, missing, true, missing, missing, true, missing, missing, missing, missing, true);
最终的解决办法:
Windows Server 2008 X64:
需要建目录:C:\Windows\SysWOW64\config\systemprofile\Desktop
Windows Server 2008 X86:
需要建目录:C:\Windows\System32\config\systemprofile\Desktop
参考如下讨论:http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91