小编Sal*_*Sal的帖子

在 powershell 中打开受密码保护的 Excel

我正在尝试在 powershell 中打开受密码保护的 Excel 工作表,并输出有关工作表中有多少行的报告。

如果工作表没有密码保护,脚本工作得绝对正常,但如果设置了密码,我似乎无法让 powershell 打开它。

我当前的脚本是

$Report = "S:\Business Support\excel tests\MI Tool - Live.csv"
$path = "S:\Business Support\excel tests"
[Array]$Results = $null
$excelSheets = Get-Childitem -Path $path -Include "MI Tool - Live.xlsm" -Recurse
$excel = New-Object -comobject Excel.Application
$excel.visible = $false
$password = "blablabla"
$updatelinks = 0


foreach($excelSheet in $excelSheets)
{
 $workbook = $excel.Workbooks.Open($excelSheet,$updatelinks,$password)
 $rowCount = $null

  $worksheet = $workbook.sheets.item("Data")
  $rowMax = ($worksheet.usedRange.rows).count
  $rowCount += $rowMax

$Results += New-Object Psobject -Property @{
    "File Name"=$excelSheet.Name
    "Row Count"=$rowCount}
$excelSheet.Name …
Run Code Online (Sandbox Code Playgroud)

excel powershell password-protection

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

excel ×1

password-protection ×1

powershell ×1