Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 通过Powershell运行Access.Application.DoCmd时类型不匹配_Excel_Vba_Powershell_Ms Access_Com - Fatal编程技术网

Excel 通过Powershell运行Access.Application.DoCmd时类型不匹配

Excel 通过Powershell运行Access.Application.DoCmd时类型不匹配,excel,vba,powershell,ms-access,com,Excel,Vba,Powershell,Ms Access,Com,我的代码有问题。我希望使用PowerShell打开Access文件,然后将表导出到Excel文件。到目前为止,这是我的代码 $MsAccess = New-object -com Access.Application $MsAccess.OpenCurrentDatabase('<Filepath>',$false) $MsAccess.Application.DoCmd.OpenTable("<TableName>") $MsAccess.Application.DoC

我的代码有问题。我希望使用PowerShell打开Access文件,然后将表导出到Excel文件。到目前为止,这是我的代码

$MsAccess = New-object -com Access.Application
$MsAccess.OpenCurrentDatabase('<Filepath>',$false)
$MsAccess.Application.DoCmd.OpenTable("<TableName>")
$MsAccess.Application.DoCmd.OutputTo('acOutputTable, "<TableName>" , acFormatXLS , "OutputName.xls", true')
$MsAccess.CloseCurrentDatabase()
$MsAccess.Quit()
错误说明:

 $MsAccess.Application.DoCmd.OutputTo('acOutputTable, "TableName" , acFormatXLS , "OutputName.xls", true')
Exception calling "OutputTo" with "1" argument(s): "Type mismatch. (Exception 
from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
我尝试将表格导出到excel已有一段时间了,但我似乎找不到太多有关通过PowerShell使用excel的文档。有人对如何解决这个问题有什么建议吗

note: placeholders such as TableName, filepath, etc are not actual names, just replacements
试试这个:

$MsAccess.Application.DoCmd.OutputTo(0, "<TableName>" , 0, "OutputName.xls", $true)
$MsAccess.Application.DoCmd.OutputTo(0,”,0,“OutputName.xls”,$true)

为了解决这个问题,我最终使用了docmd.transfer电子表格命令。我猜powershell不喜欢outputto。

看起来您只是将参数作为一个字符串传递。而不是由多个元素组成的数组。这行得通吗?
$MsAccess.Application.DoCmd.OutputTo(“acOutputTable”、“TableName”、“acFormatXLS”、“OutputName.xls”、“true”)
@BenH我刚试过,但数据不匹配似乎也有同样的问题。
$MsAccess.Application.DoCmd.OutputTo(0, "<TableName>" , 0, "OutputName.xls", $true)