본문 바로가기
ITC/Windows

[Powershell] Excel COM 오브젝트 이용하기

by Un光 2019. 7. 15.
728x90
반응형
$excel=new-object -comobject excel.application

#Open Workbook Object
$workbook=$excel.workbooks.open("PathToTheFileI'mUsing.csv")

#Define Variables
$worksheets=$workbook.worksheets
$sheet=$worksheets.item(1)
$range=$sheet.usedrange

#Convert Text To Columns
$range.texttocolumns("Destination=Range('A:A')", "DataType=xlFixedWidth", "ConsecutiveDelimiters=$true")

#Set Workbook Properties
$excel.visible=$false
$range.entirecolumn.autofit()

#Ignore Prompt for Overwriting existing file
$excel.displayalerts=$false

#Save as XLSX
$workbook.saveas("PathToTheSaveLocation.xlsx",51)
$workbook.saved=$true
반응형