Calc: Assign visible cell content to a variable

Please consider the cell _E76 in _E76.ods ( Upload files for free - _E76.ods - ufile.io ).

How does one assign the string seen in E76 (=IF(AND($A39>=$A$48; $A39<=$A$56);FORECAST.LINEAR(+$A39; $B$48:$B$56; $A$48:$A$56 );"")) to a variable, say, var-e76?

We want to end up with var-e76 = "
=IF(AND($A39>=$A$48; $A39<=$A$56);FORECAST.LINEAR(+$A39; $B$48:$B$56; $A$48:$A$56 );"")"

As a Solution, reference to a method or method-detail would suffice.

Possible Resource: In Could TYPEIN() compliment the FORMULA() function? ["TYPEIN()" was "TRANSFER()" in the original question.], Lupp says, “If there is a living formula in a cell … and … you can access that cell and ask it for the resulttype and for the .Value or the .String (probably better read from t[h]e .DataArray), and assign what you get to your program variable.” But I do not know how to do that.

I looked at the LibreOffice 7.3 SDK API Reference FormulaParser Service Reference(1), but did not quite understand it.

I have looked around on the web, LO Documentation, and on ask.libreoffice, but not noticed a solution. I have scanned, and been intimidated by, the Developer’s Guide(2) and the LibreOffice Learning Materials(3).

Version: 7.3.4.2 (x64) / LibreOffice Community
Build ID: 728fec16bd5f605073805c3c9e7c4212a0120dc5
CPU threads: 8; OS: Windows 10.0 Build 22000; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded

(1) LibreOffice: FormulaParser Service Reference
(2) LibreOffice Developer's Guide - The Document Foundation Wiki
(3) Development/Learning Materials - The Document Foundation Wiki

Have you ever seen scenarios working? http://user.services.openoffice.org/en/forum/download/file.php?id=3004 Don’t feel irritated by the macro warning. This is free of macros.

2 Likes

Villeroy, thank you for giving me an example of scenarios. This is new to me.
.
TrigonometricScenarios.ods has tables and graphs of Cosinus, Sinus, Hyp_Tangens, Hyp_Cotangens, New Empty, and Tangens. Those I understand. I can Edit, Switch, Create and Delete different scenarios. This is a delightful solution for making elegant graphs and illustrating the various trigonometric functions.
.
Although I am not quite sure what to think now, in regards to a solution, I really appreciate your very kind response. To take advantage of all the new features, I have updated my version of LibreOffice to the very latest one.
.
Version: 7.4.3.2 (x64) / LibreOffice Community
Build ID: 1048a8393ae2eeec98dff31b5c133c5f1d08b890
CPU threads: 8; OS: Windows 10.0 Build 22000; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded

It appeared to me that your goal was exchanging calculations to be displayed in the chart of your sample document.

Thanks to each of the kind people who graciously added valuable information to help this succeed as an Enhancement Request. tdf#152868 (String2Push) has been added to Bugzilla.
.
ask.libreoffice.org: Villeroy, Lupp, DanniStories, erAck.de, mikekaganski, EarnestAl, JohnSUN, parsely
Libera.Chat: @cloph, intp, @mikekaganski, erAck
#libera: buZz, nckx, thumbs
#libreoffice: erAck

I have the feeling that you (@Bruce2) are constantly pulling at the wrong end of the rope. Sorry. It’s your choice where to pull. But this is a site where people look for answers. And trying to do things with Calc should start with standard means. Calc has no variables in the full sense, and advanced questions concerning programming are a different thing.
The formatted display you get shown in a cell’s area isn’t content of that cell, and (in most cases) you can’t get it as an element of a DataArray.
It is, however accessible via the cell’s .String property by a routine being able to access the cell object. This is simply a special case of “introspection” otherwise used to get attributes.
LibreOffice Basic doesn’t directly support the passing of a cell object (reference to it) to a user function. It would need parameter values for sheet, row, and column (or similar).
A module having set Option VBAsupport 1 offers a different way (which, of course, also will come with disadvantages).
See attached example. disask85651stringIntrospection.ods (12.5 KB)

Lupp, you mention, “The formatted display you get shown in a cell’s area.” And this is the very string in which we are interested. We want to place that string, character for character, into a designated cell.
.
What is the most straightforward way to do that? You say, “There is no FormulaEvaluator service in the API to Calc.”(1) We are confined neither to a module with VBA support nor to LibreOffice Basic and a user function. You say, “advanced questions concerning programming are a different thing.” If you are, in effect, saying we should get involved in development, then could the following be considered?
.
The best way to add a generally useful feature to LibreOffice is to work on the code base(2).

"Step-by-step guide for new developers

It is easy to be overwhelmed by the size and complexity of LibreOffice. The source is written in many different languages and formats — C, C++, Java, Bash, JavaScript, Python, Perl, SQL, XML — and consists of roughly 102,000 files (excluding all localizations) with 36,000,000 lines of text (7,000,000 lines of source code).
.
Nobody understands the whole code in detail, but we have many core developers who each know part of the code in detail."(3)
.
With the above options as a minimum, what would you suggest as the next step for me?
.
What does the phrase “pulling at the wrong end of the rope” mean? I googled the phrase, and noticed nothing relevent. However, I would love to increase my knowledge of aphorisms. I would appreciate it, it you would be kind enough to enlighten me.
.
Version: 7.4.3.2 (x64) / LibreOffice Community
Build ID: 1048a8393ae2eeec98dff31b5c133c5f1d08b890
CPU threads: 8; OS: Windows 10.0 Build 22000; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
.
(1) Could TYPEIN() compliment the FORMULA() function? ["TYPEIN()" was "TRANSFER()" in the original question.] - #13 by Lupp
(2) core - Gitiles
(3) Development/GetInvolved - The Document Foundation Wiki

This is the next time that I don’t understand your intentions.

  • I gave you a function supposed to do what you wanted. If I was on error insofar, tell me in what way.
  • I can’t guide you concerning the question how to implement additional standard functions for Calc.
  • The mentioned phrase I used wasn’t standard in any sense, but seemed to be sufficiently illustrative. However, I wanted to withdraw it and striked it out therefore.
1 Like

Thank you for your patience.
.
image

In disask85651stringIntrospection.ods, I understand that A2 is 15000 times π.

image
.
In D2 you used CELLSTRINGBYSHROCO to access A2 and got #VALUE! as a result. (I would love to know how to find and use CELLSTRINGBYSHROCO.)
.
image
.
In E2 you invoke FORMULA (for cell D2) and get the string =CELLSTRINIGBYSHROCO(SHEET(A2) ;ROW(A2) ;COLUMN(A2)) displayed.
.
In the case of E2, the formatted display you get shown in a cell’s area is =CELLSTRINIGBYSHROCO(SHEET(A2) ;ROW(A2) ;COLUMN(A2)).

image
.
image
.
You repeat this for D3 and E3. In the case of E3, the formatted display you get shown in a cell’s area is
=CELLSTRINBBWBAREFERENCE (A2) (another enjoyable thing to find and use).
.
In both the case of E2 and the case of E3, the Formula bar contains a formula and the cell contains a formatted display in the cell’s area. In the cases of D2 and D3, despite the presence of a formula in the Formula bar, neither cell D2 nor cell D3 contain a formatted display in the cells, area similar to that in the cases of E2 and E3.
.
image
.
Our example case is that of E76. The cases of E2 and E3 resemble it. E2 and E3 both display a formatted display in the cell’s area in which we are interested in setting equal to a variable. What is the best way to achieve this?

Your remarks starting with the quoted words, I don’t understand. Column E doesn’t show anything specifically formatted, but simply the string returned by the standard function FORMULA()

For the error you reported I couldn’t find an explanation. It doesn’t occur for me. More comments you find in the new attachment.
disask85651stringIntrospectionReRe.ods (164.3 KB)

Thank you so much for sending disask85651stringIntrospectionReRe.ods(85651ReRe)(1).
In 85651ReRe cell A3, it was a pleasure to see the formula you used and the examples you provided in A12:E21. In D3, you say, “For me cell D2 is showing the expected and correct result.” I assume this is the same for cell D3 on your machine. For cells D3and D4 in 85651ReRe, I also do not know why my machine produced a #VALUE! error, but it does not bother me for our present discussion. Your machine, showing the correct string is perfectly satisfactory.
.
In 85651ReRe D9, thank you for explaining that CELLSTRINGBYVBAREFERENCE and CELLSTRINGBYSHROCO are UserDefinedFunctions with VBASUPPORT. I appreciate this information. Thanks.
.
In 85651ReRe A6, you say, “Always have in mind that column D returns strings. The results can’t be used by ordinary calculations.”
Above, you say, “trying to do things with Calc should start with standard means(2).”
.
In our recent discussions both you and I have, at least, examined Methods’ Summary and Methods’ Details to see whether we can use ordinary calculations and standard means to meet our goal. Since you are the expert, you have been able to think of things unknown to me. My current understanding is that you (basically alone) have not found any ordinary calculations or standard means or recognized special means ex. UDF to meet our goal of copying the result to a variable. But you have shown, in 85651ReRe D4, that one may use “the UserDefinedfunction to show the formatted result based on the Sheetnumber, the RowNumber, and the ColumnNumber.” You have also shown that this is a “pure standard and should work even in very old versions.”
.
“Column E . . .[shows]. . . the string returned by the standard function FORMULA()(3).” Aren’t you are exactly right? Haven’t you have shown me that this type of string, say we name it “the-displayed-string,” can not be readily accessed through the API, the String property, a UDF or a module having set Option VBAsupport 1? We also know that what we want is too complex for macros. In D2 and D3 on my machine the-displayed-string is an error message. In D2 and D3 on your machine the-displayed-string “is showing the expected and correct result.” You have shown that the-displayed-string is either an error message or “simply the string returned by the standard function” used. If it is the case that the-displayed-string is calculated somewhere in the core code, possibly in the Parser, should one look in the core code to capture the characters comprising the-displayed-string? If so, let’s ask the " many core developers who each know part of the code in detail" to point out where in the source code the-displayed-string is calculated. They would know that since we found no API Methods’ Details or other way to set the-displayed-string to a variable, our request is, to our knowledge, valid.
.
_E76.ods (37.2 KB)
.
Version: 7.4.3.2 (x64) / LibreOffice Community
Build ID: 1048a8393ae2eeec98dff31b5c133c5f1d08b890
CPU threads: 8; OS: Windows 10.0 Build 22000; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
.
(1) …/C:/Users/Wolfgang/Documents/3Arbeit/Office/1_Forum/disask85651stringIntrospectionReRe.ods?md=20221228_001234&gv=LibreOffice/7
(2) Calc: Assign visible cell content to a variable - #3 by Bruce2
(3) Calc: Assign visible cell content to a variable - #8 by Bruce2

Could the string of interest be in
https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/XFormulaOpCodeMapper.html#AttributesSummary?