简体   繁体   English

使用Powershell将Excel范围导出到csv

[英]export Excel range to csv with Powershell

I'm trying to export a range of cells to a csv file: 我正在尝试将一系列单元格导出到csv文件中:

#Specify Range
$range = $sh_in.Range("E7:F13,B17:C25").Text

#Export range to csv
$range | Export-Csv "delivery-note\del_note_csv_test.csv" -NoTypeInformation

If I take off the .Text from the Range I get a huge amount of information, including the content of the cells, and I've tried replacing .Text with the header of the info I want, but this just gives an error. 如果我从范围中删除.Text,我会获得大量信息,包括单元格的内容,并且我尝试用所需的信息标题替换.Text,但这只会产生错误。 What can I do differently? 我可以做些什么?

Use Select-Object to select what you want (ie the Text property) from the returned $range array, then export to the CSV file: 使用Select-Object从返回的$ range数组中选择所需的内容(即Text属性),然后导出到CSV文件:

$range = $sh_in.Range("E7:F13,B17:C25")
$range | select text | Export-Csv "delivery-note\del_note_csv_test.csv" -NoTypeInformation

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

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