Parsing Excel document using PowerShell

$xlsFilePath = "C:\Excel_file.xlsx"

$xl = New-Object -comobject Excel.Application
$xl.Visible = $False
$xl.DisplayAlerts = $False
$wb = $xl.WorkBooks.Open($xlsFilePath)
$ws = $wb.Worksheets.Item(1)

$value = $ws.Cells.Item(1, "A").Value2
Write-Host $value
# ...

$wb.Close($false)
$xl.Quit()

[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl) | Out-Null
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *