excel - 从 Excel 自定义函数返回到 Powershell
问题描述
我无法将 Excel 文档中的 VBA 函数结果检索到 Powershell 脚本中。
Powershell 文件
$suite = "<some_path>"
$excel = new-object -comobject excel.application
$workbook = $excel.workbooks.open($suite)
$specs = $excel.Run("ThisWorkbook.ftp_specs")
IF([string]::IsNullOrEmpty($specs)) {
Write-Host "Your string is EMPTY or NULL"
} else {
Write-Host "Your string is not EMPTY"
}
Excel 文件(在 ThisWorkbook 中)
Function ftp_specs()
ftp_specs = "hello"
End Function
Powershell 运行结果
Your string is EMPTY or NULL
MS Office VBA 参考声明Application.Run返回一个 Variant。
在过去的几个小时里,我在网上看到的任何东西都没有暗示任何相关的东西。
解决方案
您不需要ThisWorkbook (?) 命名空间。只需使用Run
带有函数名称的方法。像这样:
$specs = $excel.Run("ftp_specs")
推荐阅读
- delphi - 显示在包含 tchart 的面板顶部的 tPanel 是透明的(Delphi)
- r - 没有标签或轴标题 - WaveleComp 包的 wc.image 问题(?)
- c++ - 我的 Visual Studio 找不到文件,因此无法进行基本操作。它出什么问题了?
- reactjs - Storybook 无法导入 Swiper 模块
- php - 如果浏览器必须滚动到空字段,则不会显示空的必填字段的 HTML 表单工具提示
- mysql - 无法让 CASE 和 GROUP BY 在同一行中显示所有值
- flutter - 颤振中的 sqflite 问题
- rust - 从可变引用中引用内部值的可变规则是什么?
- bash - \# 不在 bash 中提供命令号
- flutter - 使用 Image Picker 和 Flutter 将头像上传到 API