【发布时间】:2017-10-24 17:58:12
【问题描述】:
大家好,我们正在尝试自动化一些 Excel 并遇到了一些错误,所以我们有下面列出的脚本,但我们遇到了 3 个不同的错误。
有人可以帮我们找出脚本出错的地方吗?
我们得到的错误是:
Exception calling "Open" with "1" arguments : "Server error. (excpetion HRESULT: 0x80010105 (RPC_E_SERVERFAU
LT))"
C:\Users\Montage\Desktop\blockadp.ps1:9 char:34
+ $workbook = $excel.workbooks.open <<<< ($excelMacrosFile);
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
Cant call a method with NULL.
C:\Users\Montage\Desktop\blockadp.ps1:10 char:39
+ $worksheet = $workbook.worksheets.item <<<< (1);
+ CategoryInfo : InvalidOperation: (item:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "Run" with "31" arguments: "server error. (excpetion from HRESULT: 0x80010105 (RPC_E_SERVERFAU
LT))"
C:\Users\Montage\Desktop\blockadp.ps1:11 char:11
+ $excel.Run <<<< ("Convert", $inputExcelFile, $outputADSFile);
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
cannot call a method with NULL.
C:\Users\Montage\Desktop\blockadp.ps1:13 char:16
+ $workbook.close <<<< ();
+ CategoryInfo : InvalidOperation: (close:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
脚本本身:
$excelMacrosFile = "C:\Users\Montage\Desktop\friday.xls";
$inputExcelFile = "C:\Users\Montage\Desktop\25.05.17.xls";
$outputADSFile = "C:\Users\Montage\Desktop\25.05.17.adp";
$excel = new-object -comobject excel.application;
$workbook = $excel.workbooks.open($excelMacrosFile);
$worksheet = $workbook.worksheets.item(1);
$excel.Run("Convert", $inputExcelFile, $outputADSFile);
#$workbook.save();
$workbook.close();
$excel.quit();
$excelMacrosFile = "C:\Users\Montage\Desktop\friday.xls";
$excel = new-object -comobject excel.application;
$workbook = $excel.workbooks.open($excelMacrosFile);
然后我仍然得到同样的错误
Exception calling "Open" with "1" argument(s): "The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))"
它也不是下面提到的权限,因为它有效:
$test = Get-Content 'C:\Users\Montage\Desktop\25.05.17.xls
【问题讨论】:
-
很难破译西里尔字母。也许你可以把它们翻译给我们?看起来他们中的一个提到某些东西包含一个 NULL
-
搜索第一个错误会得到这个Q&A on SO,表明存在权限问题。其他错误是后续的
-
你可以做一个 $test = Get-Content 'C:\Users\Montage\Desktop\25.05.17.xls' 吗?这将巩固这样一个事实,即不是权限——至少在文件级别——这就是问题
-
我同意,这听起来不像是权限问题。下一步是验证所有变量中的数据,直到出现错误。一次运行一行。那你就会离答案更近了
-
您是否在打开工作簿之前尝试通过
$excel.Calculation = -4135禁用自动计算?
标签: excel powershell cmd automation