Microsoft Office Excel无法访问文件'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx' [英] Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'

查看:142
本文介绍了Microsoft Office Excel无法访问文件'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的代码如下: -

  Microsoft.Office.Interop.Excel.Application oXL = null; 
Microsoft.Office.Interop.Excel.Sheets sheet;
应用程序excel = new Microsoft.Office.Interop.Excel.Application();


excel.Workbooks.Add(System.Reflection.Missing.Value);

/ *
*以下是关于Workbook.Open()
*
* Excel.Workbooks.Open(String Filename,Object UpdateLinks,Object ReadOnly ,对象格式,
*对象密码,对象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,
Missing.Value);
sheets = workbook.Worksheets;

现在为: -

  workbook = excel.Workbooks.Open(
System.Web.HttpContext.Current.Server.MapPath(〜/ App_Data / Template.xlsx),
缺少。 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);

它直接从可视化工作室(F5)执行,但是当我尝试使用IIS访问它不工作
抛出错误如下: -


Microsoft Office Excel无法访问文件'c:\inetpub\wwwroot\ Timesheet\App_Data\Template.xlsx。有几个可能的原因:
•文件名或路径不存在。

•该文件正被另一个程序使用。$
•您尝试保存的工作簿与当前打开的工作簿具有相同的名称。


我已经尝试过作为: -



  • 文件夹和文件存在,访问IUSR _ ###(IIS用户)和文件所在文件夹中的ASPNET用户。_


    • 给予访问适当用户的组件服务(DCOM)。 li>


我已经给了该文件夹所有权限

解决方案



p>尝试这样:


  1. 创建目录 C:\Windows\SysWOW64\config\systemprofile\Desktop (对于32位64位Windows计算机上的Excel / Office版本)或 C:\Windows\System32\config\systemprofile\Desktop (对于32位版本的Office在32位64位Windows计算机上的64位版本的Office)。

  2. 对于 Desktop 目录,添加完全控制相关用户的权限(例如在Win7& IIS 7& DefaultAppPool设置用户的权限 IIS AppPool\DefaultAppPool

原始帖子与答案:




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:\inetpub\wwwroot\Timesheet\App_Data\Template.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:

  1. Create the directory C:\Windows\SysWOW64\config\systemprofile\Desktop (for the 32-bit version of Excel/Office on a 64-bit Windows computer) or C:\Windows\System32\config\systemprofile\Desktop (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).
  2. For the Desktop directory, add Full control permissions for the relevant user (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user IIS AppPool\DefaultAppPool).

Original post with answer:

这篇关于Microsoft Office Excel无法访问文件'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆