计划任务Powershell访问Excel 排错

网友投稿 731 2022-09-14

计划任务Powershell访问Excel 排错

计划任务Powershell访问Excel 排错

最近有个新的需求要使用Powershell 访问Excel 并根据业务逻辑把Excel 当中的数据进行逻辑处理, 发送邮件

一开始觉得这个需求很好实现, 事实也是如此, 只是在通过任务计划来调用powershell 读取Excel 时陷入了一个未知问题当中, 接下来就是一系列的排错过程

单步测试输出log引入了Try Catch 捕获了错误 (自己在单步测试过程中没有报错所以没有加入try catch), 错误信息如下

Microsoft Excel cannot access the file 'D:\Userlist.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.add workbook into new excel

看到这个日志之后,自上而下逐步排除可能出现问题的原因, 最后确定了问题点在The workbook you are trying to save has the same name as a currently open workbook. 根据这个信息从网上找到了答案​​链接如下​​

Try this:

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).

For theDesktopdirectory, addFull controlpermissions for the relevant user (for example in Win7 & IIS 7 & DefaultAppPool set permissions for userIIS AppPool\DefaultAppPool).

最后总结一句话, 使用32 位Office运行在64位的系统当中, 如果使用任务计划来访问是需要访问路径"C:\Windows\System32\config\systemprofile\Desktop", 默认情况下64位系统当中是没有Desktop 文件的, 只需要创建该文件即可

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:奇安信天擎软件导致windows服务器备份失败的问题
下一篇:巨屏电视暗战:“性价比”走向“质价比”
相关文章

 发表评论

暂时没有评论,来抢沙发吧~