excel - Powershell 代码无法识别当前位置的所有 excel 文件(*.xlsm)
问题描述
我目前正在使用 Powershell 来处理 excel 文件(*.xlsm)。问题是下面的代码只能读取“test.xlsm”。当名称不是 test 像 "this.xlsm" 时,该代码无法读取该文件。有什么帮助...?提前感谢您的回答:)
$destination = "C:\JJ\"
$dirName = Get-ChildItem -Name -Filter *.xlsm
$saveAs = $destination + "new\"
foreach($z in $dirName){
$excel=New-Object -ComObject Excel.Application
$excel.visible=$false
$excel.Displ`ayAlerts=$false
$book=$excel.Workbooks.Open($destination + $z)
$sheet=$book.Worksheets.item(1)
$sheet.Cells.Item(1,5)="=max(B2:B6)"
$book.SaveAs($saveAs + $z)
$excel.Quit()
$excel=$null
}
解决方案
# remove -name to get a directory object instead of a string
$dirName = Get-ChildItem -Filter *.xlsm
# you need the file name from the directory object listing
foreach($z in $dirName.name){ ...... }
推荐阅读
- html - 如何在引导程序 4.3.1 中垂直对齐具有不同标签长度的输入字段?
- ios - iOS - 使用不同 iPhone 尺寸的自动布局
- asp.net-mvc - 实体框架核心:无法打开登录请求的数据库
- c - 变量应该总是用文字初始化吗?
- python-3.x - 如何打印保存的模型所做的预测的准确性?
- python - 如果我将用户提供的值作为函数参数,如何使其成为全局变量?
- ios - Cordova - 你可以覆盖插件设置的 plist NSPhotoLibraryUsageDescription 值吗?
- javascript - 如何在不触及外部功能的情况下使此代码连续
- python - 如何将 python 脚本作为参数传递?
- r - Remove all words in string containing punctuation (R)