Python Forum

Full Version: win32com — How to resolve “AttributeError: xlUp” for Excel files?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Similar to Excel VBA, win32com has a 'xlUp' command. But do I use it? I tried the below code but get
AttributeError: xlUp

Or how do I find all the methods available in a Python library? Thanks in advance!

import win32com.client as wc

xl=wc.DispatchEx("Excel.Application")
wb=xl.Workbooks.Open(Filename='TEST', ReadOnly=False, UpdateLinks=0, IgnoreReadOnlyRecommended=True)
ws=wb.Worksheets('sht1')

print(ws.cells(ws.rows.count, 1).End(wc.constants.xlUp).Address)
see: https://python-forum.io/thread-34648.html (your other thread)
I'm not a regular windows user so not sure if pywin32com is same, but is suspect so.
(Aug-18-2021, 01:16 AM)JaneTan Wrote: [ -> ]Or how do I find all the methods available in a Python library?
>>> import win32com.client as wc
>>> 
>>> dir(wc)
['CDispatch',
 'CLSIDToClass',
 'CastTo',
 'CoClassBaseClass',
 'Constants',
 'Dispatch',
 'DispatchBaseClass',
 'DispatchEx',
 'DispatchWithEvents',
 'EventsProxy',
 'GetActiveObject',
 'GetObject',
 'Moniker',
 'Record',
 'VARIANT',
 'WithEvents',
 '_PyIDispatchType',
 '__WrapDispatch',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '_event_setattr_',
 '_get_good_object_',
 '_get_good_single_object_',
 'build',
 'constants',
 'dynamic',
 'gencache',
 'getevents',
 'pythoncom',
 'pywintypes',
 'sys']
>>> 
>>> dir(wc.constants)
['__class__',
 '__delattr__',
 '__dict__',
 '__dicts__',
 '__dir__',
 '__doc__',
 '__eq__',
 '__format__',
 '__ge__',
 '__getattr__',
 '__getattribute__',
 '__gt__',
 '__hash__',
 '__init__',
 '__init_subclass__',
 '__le__',
 '__lt__',
 '__module__',
 '__ne__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 '__weakref__']
>>> 
>>> help(wc.constants)
Help on Constants in module win32com.client object:

class Constants(builtins.object)
 |  A container for generated COM constants.
 |  
 |  Methods defined here:
 |  
 |  __getattr__(self, a)
 |  
 |  __init__(self)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
Using a good Editor(eg VS Code) or REPL function/method(with help) will automatic show when type wc.