In LO Calc, I want for every row to process its cells, and modify them as needed. My problem is: I can’t figure out how do loop over rows. Suppose I have the following code:
#!python import uno # run libreoffice as: # soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" def connect_to_lo(): # get the uno component context from the PyUNO runtime localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", localContext ) # connect to the running office ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) smgr = ctx.ServiceManager desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx) return desktop.getCurrentComponent() model = connect_to_lo()
Now, if I execute
1048576. Wow! That’s a lot of rows for completely empty document! I guess Calc pre-creates rows (which is correct), and for some reason all of them counts as candidates for enumeration (which is definitely incorrect, number of rows strictly speaking should go to infinity, and none of them should be candidates). If I do
for row in model.CurrentController.ActiveSheet.Rows: cycle, it really tries all of these pre-created empty rows.
Does anybody know a way to only loop over rows that really exist?