See subject!
Links of the kind work in Calc correctly when used with HYPERLINK and limited (without passing an argument) when set as hyperlink for a shape.
They also work correctly as expected in Draw with shapes.
They don’t work at all in Writer.
See example documents!
(Why the inconsistency???)
vndSunStarScriptDemo.ods (38.4 KB)
vndSunStarScriptDemo.odg (14.4 KB)
vndSunStarScriptDemo.odt (481.0 KB)
[edit about 2023-08-08 10:20 UTC]
The above attached demo files are replaced by slightly improved ones.
[/edit]
Hello, @Lupp !
In Writer, macros can be assigned to shape events (see Properties / Macros).
vndSunStarScriptDemo 2.odt (45.4 KB)
Thanks! But …
I should have explained more precisely what I meant by “work as expected”.
My intention wasn’t just to call any routine, but to use the query part of the vnd.sun.star.script:
link for passing arguments to the called routine.
This works with the HYPERLINK()
function, but also with textfield.URL
in Calc.
It also works in Draw with the textfields. It doesn’t work with links made the way used in Writer: relying on a character property (Strange idea!). It also doesn’t work via event settings.
- Afaik only applicable to FrameShape objects.
- No argument passing takes place.
- Much too complicated on the API level.
Do you know an appropriate way to pass arguments to a script called from a Writer document?
It seems to me that the vnd.sun.star.script
: URI scheme supports parameters named language
and location
. In this scheme, there is no way to specify macro parameters.
language
and location
are only two predefined names of query-equation-variables in that kind of URL. As you find (roughly) demonstrated in the .odg example you can add query equations. If the calling link is passed at all, user code can evaluate those equations. In Calc I made some sheets with user code evaluating any number of additional equations, if there were urgent reasons to not use function parameters for the passing. (Functions aren’t allowed everything, you know. The queries, however were prepared with functions.)
I think I got it! You found a feature (undocumented?) in a function called by a hyperlink to parse the text of a hyperlink. Of course, this way you can get almost any additional information (it is especially convenient to use #...
).
I didn’t know about this until your post. I would like to explore most of the documented features in the coming years.
No. I wrote some Basic code for the parsing of query strings myself. The only “features” of LibO components I need to rely on are
- The full link (more precisely: the query part) must be passed to the called routine.
- The process of opening the link must not object against additional query equations or spoil anything there.
Expecting your interest I prepared a reduced demo where the creation of sorting indexes in spreadsheets is done by routines called via vnd.sun.star.script:
links with full parametrisation by query equations.
Since the original sheets were made more than a year ago I wouldn’t give an extemporaneous lecture today on the syntax I used for the values in equations defining SheetCellRange
objects and SortField
structures. The meaning shouldn’t be too difficult to understand.
(BTW: I prefer to NOT sort by transpositions or the like, but by calculating permutations. This allows to get sorted access to the same data by many sorts at the same time without any moving of data. On the other hand I know that standard sorting is implemented in very efficient ways by professional software, and want to make use of that fact.)
See attached:
createMaintainIndexesFiReduced.ods (110.8 KB)
Thank you very much for the (as always) interesting topic!
Basically language=Basic&location=document
already belongs to the arguments (mandatory in vnd.sun.star.Script:
-schema ) behind it you can put anything like &theAnswer=42
Query strings are interpreted case sensitive. The predefined variable names must therefore be lower case.
The post above uses a font somehow making this not quite clear. I qouted it a bit differently.