[英]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.网上找到的所有方法都试过了。
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.