简体   繁体   English

Microsoft Excel 无法访问文件“...”。 使用 Microsoft Office 2010 的 Windows Server 2008 R2 有多种可能的原因

[英]Microsoft Excel cannot access the file “…”. There are several possible reasons Windows Server 2008 R2 with Microsoft Office 2010

I have a problem with starting the Excel Application under a particular user.我在特定用户下启动 Excel 应用程序时遇到问题。

I try to schedule this script (C#) through an application X (not Windows Task Scheduler. And this application will always use a service account to run services on the server).我尝试通过应用程序 X(不是 Windows 任务计划程序。并且此应用程序将始终使用服务帐户在服务器上运行服务)调度此脚本 (C#)。 If I run the C# script in command prompt under the same user, it runs.如果我在同一用户的命令提示符下运行 C# 脚本,它就会运行。 Under the application X, which uses the exact same user, to initiate the C# script, it fails to open the Excel application (not sufficient permission?).在使用完全相同用户的应用程序 X 下,启动 C# 脚本时,无法打开 Excel 应用程序(权限不足?)。

This script calls: app.Workbooks.Open(ExcelFileName,0,false,Type.missing....), yet it gives the following error:此脚本调用:app.Workbooks.Open(ExcelFileName,0,false,Type.missing....),但它给出了以下错误:

Microsoft Excel cannot access the file "...". Microsoft Excel 无法访问文件“...”。 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 tried all the methods that I found online to no avail.网上找到的所有方法都试过了。

  1. Create directory “C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop” (for 64 bit Windows) or “C:\\Windows\\System32\\config\\systemprofile\\Desktop” (for 32 bit Windows).创建目录“C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop”(对于 64 位 Windows)或“C:\\Windows\\System32\\config\\systemprofile\\Desktop”(对于 32 位 Windows)。 Then Set full control permissions on Desktop directory above (for example in Win7 & IIS 7 & DefaultAppPool set permissions for user “IIS AppPool\\DefaultAppPool”)然后在上面的桌面目录上设置完全控制权限(例如在 Win7 & IIS 7 & DefaultAppPool 中为用户“IIS AppPool\\DefaultAppPool”设置权限)
  2. Changed the DCOM config for the Microsoft Excel application to include this user for Local/Remote Launch and Access更改了 Microsoft Excel 应用程序的 DCOM 配置以包含此用户进行本地/远程启动和访问
  3. Enabled all macros in Excel and set the Trust Center.在 Excel 中启用所有宏并设置信任中心。
  4. Add the user to have full control on all folders that contain the Excel file.添加用户以完全控制包含 Excel 文件的所有文件夹。
  5. Under DCOM config, Microsoft Excel Application, if I modify the Identity tab to check on "This User" and enter the username/password to let Excel always run under that user.在 DCOM 配置、Microsoft Excel 应用程序下,如果我修改身份选项卡以检查“此用户”并输入用户名/密码以让 Excel 始终在该用户下运行。 Then the application runs perfectly.然后应用程序运行完美。 However, other users can't run the excel application on their own with the following error: "Cannot use object linking and embedding".但是,其他用户无法自己运行 Excel 应用程序,并出现以下错误:“无法使用对象链接和嵌入”。 If I check "Use the launching user", then Excel can't be launched.如果我选中“使用启动用户”,则无法启动 Excel。 No errors in the logs or events anywhere to check.日志或事件中没有任何错误可供检查。

Yet, still the same error.然而,仍然是同样的错误。 I think it's permission but I am not sure where and what to do for this to work.我认为这是许可,但我不确定在何处以及如何进行此操作。

Now, normally, when I run this excel report, I can double-click on the file and it'd automatically run, save the new parameters into the current file and generate a new excel file (with date attached to the file name).现在,通常,当我运行这个 excel 报告时,我可以双击该文件,它会自动运行,将新参数保存到当前文件中并生成一个新的 excel 文件(文件名附加日期)。 That means there is a change (save) to the original file.这意味着对原始文件进行了更改(保存)。

I appreciate all your help!我感谢您的所有帮助!

I found the problem is the layer of security in the server!我发现问题是服务器中的安全层!

Creating the Desktop folder inside the C:\\Windows\\System32\\config\\systemprofile and giving the service account permission to access the desktop folder is not enough.在 C:\\Windows\\System32\\config\\systemprofile 内创建桌面文件夹并授予服务帐户访问桌面文件夹的权限是不够的。

I modified the C:\\Windows\\System32\\config (or C:\\windows\\SysWOW64\\config) folder to allow permission to the service account in security tab.我修改了 C:\\Windows\\System32\\config(或 C:\\windows\\SysWOW64\\config)文件夹以允许在安全选项卡中访问服务帐户。

Then I also had to set up the same permission for the sub folder C:\\Windows\\System32\\config\\systemprofile (or C:\\windows\\SysWOW64\\config\\systemprofile) for the service account.然后我还必须为服务帐户的子文件夹 C:\\Windows\\System32\\config\\systemprofile(或 C:\\windows\\SysWOW64\\config\\systemprofile)设置相同的权限。

This works!这有效!

Microsoft Excel cannot access the file in Server 2012 Excel 2016.. checked various solutions online to create folder desktop in C:\\Windows\\SysWOW64\\config\\systemprofile\\desktop.. didn't work for this but then i added a folder desktop in System32 and that definitely worked. Microsoft Excel 无法访问 Server 2012 Excel 2016 中的文件.. 在线检查了各种解决方案以在 C:\\Windows\\SysWOW64\\config\\systemprofile\\desktop 中创建文件夹桌面.. 对此不起作用,但随后我在其中添加了一个文件夹桌面System32,这绝对有效。

Since I have 64-bit Excel installed, the proper directory turned out to be the c:\\windows\\system32\\config\\systemprofile\\desktop由于我安装了 64 位 Excel,正确的目录原来是 c:\\windows\\system32\\config\\systemprofile\\desktop

I ran across another way you can get this error: when you try to save a file with an "illegal" name, such as one with whacks (forward slashes) in it.我遇到了另一种可能会出现此错误的方法:当您尝试使用“非法”名称保存文件时,例如其中带有重击(正斜杠)的文件。

For that reason, it would seem reasonable that the err msg would give that as one possible explanation of the problem, but...no!出于这个原因,错误消息将其作为问题的一种可能解释似乎是合理的,但是......不!

Specifically, I was trying to save a file named C:\\RoboReporter\\ABUELITOS\\20160524_1327\\ABUELITOS - Fill Rate - 4\\1\\61910B10具体来说,我试图保存一个名为C:\\RoboReporter\\ABUELITOS\\20160524_1327\\ABUELITOS - Fill Rate - 4\\1\\61910B10 的文件

The whacks (shown as backwhacks in the copied exception text, but seen as forwardwhacks when hovering over the value when debugging) were the cause of the discombobulation.重击(在复制的异常文本中显示为后重击,但在调试时将鼠标悬停在值上时被视为前重击)是导致混乱的原因。 Once I fixed that by replacing whacks with underscores:一旦我通过用下划线替换 whacks 来解决这个问题:

filename = String.Format("{0}\\{1} - Fill Rate - {2}.xlsx", uniqueFolder, _unit, _begDate.ToShortDateString());
filename = filename.Replace("/", "_");

...all went swimmingly. ……一切顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 错误:Microsoft Excel 无法访问文件“...”。 有几个可能的原因 - C# Error: Microsoft Excel cannot access the file '…'. There are several possible reasons Microsoft Windows Server 2008 R2中的Microsoft Media Foundation - Microsoft Media Foundation in Microsoft Windows Server 2008 R2 Microsoft Office Excel 无法访问 IIS 上的文件 - Microsoft Office Excel cannot access the file on IIS 在Microsoft Windows Server 2008 R2上运行的SQL通知错误 - sql notification error running on Microsoft Windows Server 2008 R2 Microsoft Office Interop Excel 无法保存在 Windows Server 2008 中 - Microsoft Office Interop Excel doesn't save in Windows server 2008 Microsoft Excel无法访问Windows Server 2012上的文件 - Microsoft Excel cannot access the file on Windows Server 2012 Microsoft Jet oledb 4.0提供程序未在本地计算机上注册Windows Server 2008 R2 Standard - microsoft jet oledb 4.0 provider is not registered on the local machine Windows Server 2008 R2 Standard Microsoft SQL Server 2008 R2中的水平分区? - Horizontal partitioning in Microsoft SQL Server 2008 R2? Windows Server 2008 R2上的Office(Outlook)互操作问题 - Office (Outlook) Interop Issue on Windows Server 2008 R2 Microsoft Server 2008 R2不从任务计划程序写入文本文件 - Microsoft Server 2008 R2 not writing to text file from task scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM