Powershell: Programmatically Open an Excel File

Concern: I have an Excel file that I want to open using Powershell. How do I retreive this data and consume this within Powershell?

Example: You just asked a thousand systems a million questions. You are ready to check it out...but manually opening an excel file is just too much.

#-------------------------Variables----------------------------
$CsvFile = ("file.csv")

$excel = new-object -comobject Excel.Application
$excel.visible = $True

if (!$(test-path $CsvFile)) {
 write-host "File doesn't exist..."
}
else { 
 $excelfile = $excel.Workbooks.Open($CsvFile) 
}

$excel.ActiveSheet.Cells.EntireColumn.AutoFit()

No comments:

Post a Comment