Python modules for calc

Hello, I am trying to add some python scripting, macros etc, to a calc to get started with. But the only choices I seem to have are for Basic. Is there something extra I need to install to make this happen? Python runtime for instance (have not, or it is an oldish version IIRC). I just upgraded Libre to the latest versions 25.x.

Perhaps to clarify a bit, I’m not sure hte level of SourceForge support. Does not seem like a full fledged editor organizer, if I understand correctly. In other words, bit disillusioned that “python is supported” then in the next sentence “in your favorite text editor” which is far from the point, I WANT TO EDIT IN THE SOURCEFORCE ENVIRONMENT, that is where the macros are being organized, managed, etc, from Calc, etc.

I took a side step into Code and now have the basic function I wish to run on my data cell to start with. Assuming I can get that linkage working from the cell data, then I want for that function to place its data into a columns array which I would provide it next.

>>> parseLocation('X=1 Y=2 Z=3|P=4 Y=5 R=6')
{'x': 1.0, 'y': 2.0, 'z': 3.0, 'orientation': {'p': 4.0, 'y': 5.0, 'r': 6.0}}

Which parses as expected to a py dictionary.

To be honest, still struggling loading my py script into the organizer. I seems as though these steps are vaguely mentioned or there does not appear to be a way to either create, import, or load my py file into the calc document.

This is what I see:
image

With no apparent way to organize python.

This is hilarious. So considering where things are at with python LO comprehension, why does this not surprise me. APSO? Seriously?!

Seriously! 120658 – Reworking of dialogues Organize macros (make from 5 existing only one)
.
If you have a problem with that then don’t try Base.

Taking a step back, my goal is to take a range of columns each of which in the form {X=1 Y=2 Z=3|P=4 Y=5 R=6}. My python core functions are ready to parse. The results should land in columns in proximity of the source cell. Perhaps can do some cell math add or subtract columns, or be given a range, let’s say, by whatever BASIC or other proxy call that is required. I’m not sure how to bridge that gap from a cell formula, to the exported py functions, via VBA.

If you have a problem with that then don’t try Base.

That’s funny, why is that? (Rhetorical)… :stuck_out_tongue:

I’m guessing that the best thing would be a BASIC function but I’m not sure how to specify receiving a source cell, or the destination range. From there I’d guess it would not be that difficult, hopefully, to get the string from the source cell, and to iterate the range setting the values accordingly.

The LibreOffice macro tools are half baked. A number of languages are supported, kind of. As a minimum these should be supported directly through the interface without requiring an extension.
.
Regarding Base, it’s a database manager though it can encapsulate a HSQL or Firebird database (depending on version), or SQLite by using an extension. The tables are in the database, queries, forms and reports are in the base document.

I understand a workaround can be good to satisfy immediate project needs but it is tiring when the ultimate vision is what was developed back in the '80s.

Have a look at https://python-ooo-dev-tools.readthedocs.io/ (it doesn’t cover Base).

Bit of a deeper dive that I am needing or wanting here. I just need a qnd TL;DR primer connecting the dots, Basic proxy to python exported function. Is that available somehow somewhere? The basics what I need include how to relay cell and range addresses and begin working with them in python via Basic. I can figure out how to get the string from a source cell, and how to set values in a destination range. And perhaps a modest return value from the Basic function. Not sure Basic knows how to work with python returned dict() though, that’s a bit more knowledge.

To be clear I’m not asking about Base. Calc.

Multiple parse a string in the Basic with an array output (you can called it as an Array Function):
Parse.ods (12.2 KB)

1 Like

That’s interesting. Then just a matter of aligning rows indexes columns and what not.

Trying to adapt that a little bit. I’d like to pass the range of cells in, and if I can, just set the values in the trailing cells of that range. Having a devil of a time referencing anything opposite the range, not sure what’s going on. Mostly getting object not set which makes no sense whatsoever. What am I missing? I put oRange in the watch, and it looks like a 2 dimensional array understandably, but I do not know how to iterate the cross section.

Function ParseLocation(oRange As Variant)

  Dim oRangeCells(7) As Variant

  oRangeCells = oRange(1)

  Dim oCell As Object
  Dim strSourceText As String

  oCell = oRangeCells(1)
  strSourceText = oCell.getString()

  ' ...
End Function

Have this in my watch which if I read it correctly, I am halfway there, the range is correct, I want the first value out and will parse it. Then I will feed the trailing Variant Empty parts with the values, if possible. Question is how to get through to the first value, then of course setting each of the other values. Assuming those are all references passing back and forth to the sheet itself.

image

Function ParseLocation(strSourceText As String, oDest() As Variant)
  ' ...
End Function

I do see the strSourceText on the way in. But cannot set anything through oDest for whatever reason. It does show, I think accurately, Variant/Empty, but not sure how to set things there.

Minor breakthrough but it is definitely not doing what I think it is doing. Will need actual addresses, probably sheets, indexes, etc.

Good news is that oDest at least can be set in this way. Bad news is these are the values drawn from the sheet, not references to the cells themselves.

Function ParseLocation(strSourceText As String, ByRef oDest() As Variant)

	ReDim oDest(1, 6)

	oDest(0, 0) = 1
	oDest(0, 1) = 1
	oDest(0, 2) = 2
	oDest(0, 3) = 3
	oDest(0, 4) = 4
	oDest(0, 5) = 5

	ParseLocation = True

End Function

Please uplod your ODF type sample fille (with the embedded macro code) here.
.
Otherwise you can not modify other cell contents by a FUNCTION. You can modify the cell (and cell range) contents where the function was called from.
.
Use SUBs for modifying other cells. (you must know how you will launch the subroutine…)

At the moment I am doing a minor pivot to purely BASIC Function, or as you suggested Sub, if necessary. What I need is an example code in order to template my approach. Need to know both source cell, as well as destination cells, and how to navigate both. Source I can parse through; destination will receive the parsed values. Intention is to do so one cell and or row range at a time.