Microsoft.Office.Interop.Excel
can be used in PowerShell: set-strictMode -version latest $null = [Reflection.Assembly]::LoadWithPartialName( "Microsoft.Office.InterOp.Excel" ) # add-type -path 'C:\Program Files (x86)\Microsoft Office\Office16\DCF\Microsoft.Office.Interop.Excel.dll' # add-type -path 'C:\Program Files (x86)\Microsoft Office\root\Office16\DCF\Microsoft.Office.Interop.Excel.dll' $xls = new-object Microsoft.Office.Interop.Excel.ApplicationClass $xls.Visible = $true $wb = $xls.Workbooks.Add() $sh = $wb.Worksheets(1) $sh.Name = "foo bar baz" $sh.Cells(1,1) = "Hello world" $wb.SaveAs("$env:temp\excel-test.xlsx") $xls.Quit()
Exception setting "Visible": "Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND)).
[System.GC]::Collect() [System.GC]::WaitForPendingFinalizers()