Good day everyone.
I am a starting programmer in powershell and am trying to make a program input help desk calls into an excel sheet to import into the help desk ticketing system.
My script:
$excel_file_path = 'G:\IT\Helpdesk\Daily Calls.xlsx'
## Instantiate the COM object
$Excel = New-Object -ComObject Excel.Application
$ExcelWorkBook = $Excel.Workbooks.Open($excel_file_path)
$ExcelWorkSheet = $Excel.WorkSheets.item("sheet1")
$ExcelWorkSheet.activate()
## Find the first row where the first 7 columns are empty
$row = ($ExcelWorkSheet.UsedRange.Rows | ? { ($_.Value2 | ? {$_ -eq $null}).Count -eq 7 } | select -first 1)
$test = "this is a test"
$ExcelWorkSheet.Cells.Item($row,1) = $test
$ExcelWorkBook.Save()
$ExcelWorkBook.Close()
$Excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
Now, I did take this from another page online and modified it to what I need, but it is giving me this error;
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
At H:\Scripts\Call_Log.ps1:12 char:1
+ $ExcelWorkSheet.Cells.Item($row,1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
OR
Exception from HRESULT: 0x800A03EC
At H:\Scripts\Call_Log.ps1:11 char:1
+ $ExcelWorkSheet.Cells.Item($row,1) = $test
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
I don't understand what is going on or what is mismatched. Could anyone please help?
User contributions licensed under CC BY-SA 3.0