简体   繁体   English

Powershell 读取 Excel 中的一个选项卡并导出为 CSV

[英]Powershell read one tab in Excel and Export as CSV

I want to read a hidden tab in excel file and copy that tab and export it to csv.我想读取 excel 文件中的隐藏选项卡并复制该选项卡并将其导出到 csv。

I did this command, but it only output the meta data of that tab我做了这个命令,但它只输出那个选项卡的元数据

$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"

how should i get the actually content in that Tab (index No.4) and save as test.csv ?我应该如何获取该选项卡(索引号 4)中的实际内容并保存为test.csv

Well you were close.好吧,你很接近。 This should do it.这应该这样做。

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

Make sure, the path exists.确保路径存在。

I would try to make the spreadsheet visible first.我会先尝试使电子表格可见。

use some code similar to this:使用一些类似于此的代码:

ws.sheet_state = 'visible' ws.sheet_state = '可见'

This is a guess!这是一个猜测!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM