Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, July 23, 2020 9:52 AM
I'm trying to read data from an individual excel cell, based on the input of a serial number the user enters previously. Below is my code:
#create excel object
$excel = New-Object -ComObject Excel.Application
# open Excel file
$workbook = $excel.Workbooks.Open("C:\Users\NAME\Documents\Reports\Database.xlsx")
$sheet = $workbook.ActiveSheet
$column = 2
$row = $serial
$info = $sheet.cells.Item($column, $row).Text
Write-Output($info)
When this runs I receive the following error:
Exception from HRESULT: 0x800A03EC
At C:\Users\NAME\Documents\Reports\report_script-v0.3.ps1:27 char:1
- $info = $sheet.cells.Item($column, $row).Text
-
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
All replies (2)
Thursday, July 23, 2020 7:35 PM ✅Answered
The cell you are asking for does not exist. "$serial" is null and must be a legal row number.
\(ツ)_/
Tuesday, July 28, 2020 7:24 AM
Hi,
As this thread has been quiet for a while, so here is a quick question.Was your issue resolved?
If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Yang Yang
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].