【问题标题】:Powershell read one tab in Excel and Export as CSVPowershell 在 Excel 中读取一个选项卡并导出为 CSV
【发布时间】:2019-12-06 21:11:24
【问题描述】:

我想读取 excel 文件中的隐藏选项卡并复制该选项卡并将其导出到 csv。

我做了这个命令,但它只输出那个标签的元数据

$file = Get-ChildItem $sp | Where-object {$_.Name -match $patten} | sort LastWriteTime -Descending | select -first 1    
$wb = $excel.Workbooks.open($file.Name)    
$wb.Sheets.Item(4) | Export-Csv -Path "c:\Users\path\test.csv"

我应该如何获取该选项卡(索引号 4)中的实际内容并保存为test.csv

【问题讨论】:

标签: excel powershell csv


【解决方案1】:

嗯,你很接近。应该这样做。

$ws = $wb.Sheets.Item(4)
$ws.SaveAs("c:\Users\path\test.csv", 6)

确保路径存在。

【讨论】:

    【解决方案2】:

    我会先尝试让电子表格可见。

    使用一些类似的代码:

    ws.sheet_state = '可见'

    这是一个猜测!

    【讨论】:

      猜你喜欢
      • 2017-04-11
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 1970-01-01
      相关资源
      最近更新 更多