I’m working on a Python script that interacts with SAP GUI using the win32com.client module. My goal is to retrieve a specific cell value from a table within SAP. However, I’m encountering an error when I attempt to use the getCellValue method. Below is the traceback:
Traceback (most recent call last):
File "C:UsersaaaaDesktoptest.py", line 69, in <module>
value = shell.getCellValue(1, "Status do sistema")
File "<COMObject <unknown>>", line 2, in getCellValue
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SAP Frontend Server', '', None, 0, -2147024809), None)
Here is the relevant part of my code:
My code
id = 'wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell'
shell = sap.session.findById(id)
value = shell.getCellValue(1, "Status do sistema")
print(value)
Based on the SAP GUI Scripting API documentation, the getCellValue method has the following signature in VBScript:
Public Function GetCellValue( _
ByVal Row As Long, _
ByVal Column As String _
) As String
What I’ve Tried
-
Verification: Ensured that SAP GUI scripting is enabled on my system.
ID Path: Double-checked the ID path
(wnd[0]/usr/cntlCUSTOM/shellcont/shell/shellcont/shell) to ensure it
correctly points to the table I want to interact with. -
Column Reference: Tried using both the column name (“Status do
sistema”) and the column index (e.g., 0, 1) to retrieve the value. -
Testing Different Parameters: I also experimented with different row
indices and column names to see if the issue was specific to certain
cells.
I expected the getCellValue method to return the value from the specified cell in the table, which I would then print to the console.
-
Python Version: 3.11.8
-
SAP GUI Version: (SAP GUI version 770)
-
win32com.client Version: 306
-
Operating System: Windows 10
Question
What could be causing this pywintypes.com_error when I try to use getCellValue? Is there something wrong with how I am referencing the column, or might there be an issue with the SAP GUI setup? I would appreciate any guidance on how to correctly retrieve the cell value.