Microsoft Office Excel 无法访问文件“c:inetpubwwwrootTimesheetApp_DataTemplate.xlsx" [英] Microsoft Office Excel cannot access the file 'c:inetpubwwwrootTimesheetApp_DataTemplate.xlsx'
问题描述
我的代码如下:-
Microsoft.Office.Interop.Excel.Application oXL = null;Microsoft.Office.Interop.Excel.Sheets 工作表;应用程序 excel = new Microsoft.Office.Interop.Excel.Application();excel.Workbooks.Add(System.Reflection.Missing.Value);/** 这里是关于 Workbook.Open() 的完整细节** Excel.Workbooks.Open(字符串文件名,对象更新链接,对象只读,对象格式,*对象密码,对象WriteResPassword,对象IgnoreReadOnlyRecommended,对象来源,* 对象分隔符、对象可编辑、对象通知、对象转换器、对象 AddToMru、对象本地、对象损坏加载)*/工作簿工作簿 = excel.Workbooks.Open(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Template.xlsx"),Missing.Value, true, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value,缺失值);工作表 = 工作簿.工作表;
现在该行了:-
workbook = excel.Workbooks.Open(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Template.xlsx"),Missing.Value, true, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value,Missing.Value, Missing.Value, Missing.Value,缺失值);
它直接从 Visual Studio (F5) 执行,但是当我尝试使用 IIS 访问它时,它无法工作.抛出错误如下:-
<块引用>Microsoft Office Excel 无法访问文件c:inetpubwwwrootTimesheetApp_DataTemplate.xlsx".有几个可能的原因:
• 文件名或路径不存在.
• 该文件正被另一个程序使用.
• 您尝试保存的工作簿与当前打开的工作簿同名.
我已经尝试了以下解决方法:-
<块引用>- 文件夹和文件存在,允许访问文件所在文件夹中的 IUSR_###(IIS 用户)和 ASPNET 用户.
- 在组件服务 (DCOM) 中授予适当用户的访问权限.
我已经给了模板(.xlsx)所在文件夹的所有权限
有什么建议吗??
试试这个:
- 创建目录
<块引用>
C:WindowsSysWOW64configsystemprofileDesktop
(适用于 64 位 Windows 计算机上的 32 位版本的 Excel/Office)或
<块引用>C:WindowsSystem32configsystemprofileDesktop
(适用于 32 位 Windows 计算机上的 32 位版本的 Office 或 64 位 Windows 计算机上的 64 位版本的 Office).
- 对于 Desktop 目录,为相关用户(例如在 Win7 & IIS 7 & DefaultAppPool 中为用户 IIS AppPoolDefaultAppPool 设置权限).
带有答案的原始帖子:
I have my code as follows :-
Microsoft.Office.Interop.Excel.Application oXL = null;
Microsoft.Office.Interop.Excel.Sheets sheets;
Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Workbooks.Add(System.Reflection.Missing.Value);
/*
* Here is the complete detail's about Workbook.Open()
*
* Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format,
* Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin,
* Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
*/
Workbook workbook = excel.Workbooks.Open(
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Template.xlsx"),
Missing.Value, true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
sheets = workbook.Worksheets;
Now for the line :-
workbook = excel.Workbooks.Open(
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Template.xlsx"),
Missing.Value, true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
It gets executed directly from the visual studio (F5) but when i try to access it with IIS it wont work. Throws error as follows:-
Microsoft Office Excel cannot access the file 'c:inetpubwwwrootTimesheetApp_DataTemplate.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.
I have tried the work around as:-
- Folder and the file exist, giving access to the IUSR_### (IIS user) and to the ASPNET user in the folder where the file is.
- At Component Services(DCOM) given access to appropriate user.
I have already given all permission's to the folder where the template(.xlsx) exists
Any suggestions??
Try this:
- Create the directory
C:WindowsSysWOW64configsystemprofileDesktop
(for the 32-bit version of Excel/Office on a 64-bit Windows computer) or
C:WindowsSystem32configsystemprofileDesktop
(for a 32-bit version of Office on a 32-bit Windows computer or a 64-bit version of Office on a 64-bit Windows computer).
- For the Desktop directory, add Full control permissions for the relevant user (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user IIS AppPoolDefaultAppPool).
Original post with answer:
这篇关于Microsoft Office Excel 无法访问文件“c:inetpubwwwrootTimesheetApp_DataTemplate.xlsx"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!