简体   繁体   中英

export Excel range to csv with Powershell

I'm trying to export a range of cells to a csv file:

#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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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