Page 1 of 1

[Solved] Macro Inserting OOo Math Formula in Calc

PostPosted: Sun Nov 13, 2011 7:08 pm
by mctomac
I'm really desperated. I have spent two days looking for any solution but i found only information how to insert formula in Writer or how to start editing MathFormula in Calc, but nothing about how to make and edit Math Formula in Calc....

Authomatic recorded macro using "record macro" gives such a result:
Code: Select all   Expand viewCollapse view
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertObjectStarMath", "", 0, Array())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertObjectStarMath", "", 0, Array())

It opens Math Formula Editor, and nothing more :(

In Writer it is easy. It's only needed to use o >>CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"<< formula to an object.
Then I set the "formula" property of my object which is EmbeddedObjcet (for example: oObj.EmbeddedObject.formula = "My formula") and then it works good. But it's in Writer. How to get it in Calc? Is there any equivalent of "EmbeddedObject" object from Writer's document in Calc Spreadsheets? Can anyone help me? :(
Sorry for my complicated explanation and poor english.... And thank You very much for every suggestion.

Re: Macro Inserting OO Math Formula in Calc

PostPosted: Sun Nov 13, 2011 8:07 pm
by Charlie Young
Avoid the dispatcher here, use the API. This inserts a famous formula at top left of the first sheet:

Code: Select all   Expand viewCollapse view
sub InsertEulerFormula
   Dim oDoc As Object
   Dim oSheet As Object
   Dim oShape As Object
   oDoc = ThisComponent
   oSheet = oDoc.Sheets(0)
   oShape = oDoc.createInstance("")
   oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
   oShape.Model.Formula = "size 20 e^{i%pi} + 1 = 0"
end sub

The shape must be inserted into the Drawpage before the formula string can be assigned. I'll leave aside considerations like manipulating the position and size for the moment.

Re: Macro Inserting OO Math Formula in Calc

PostPosted: Sun Nov 13, 2011 8:50 pm
by mctomac
Yes,yes! :D It works! Great :bravo: :D That's it! :D So it's quite similar to this Writer command. :) That's what I needed. Thank You very very very very much :) :super:

Re: [Solved] Macro Inserting OOo Math Formula in Calc

PostPosted: Tue Dec 20, 2011 2:33 pm
by mctomac
Now I have a new problem. I want to make a function, but i need to get the ardess of the cell in which this function is written. Of course ther are instructions like ThisComponent.getCurrentSelection. But it is not a solution because if calculating of the value of the cell will be started in the moment when cell is not selected it may cause mistakes...
I need something like funcions Column() and row(), which are available from spreadsheet's cell level. and when You leave function without argument it gives the number of the cell in which the function is written. But it does'nt work ina basic. ...

It's difficult to explain it in english. sorry.

i want sth like this:
Code: Select all   Expand viewCollapse view
   S1 = thiscomponent.Sheets(0)
   S2 = thiscomponent.Sheets(1)

S2.getCellByposition(X,Y).string="it works!"

But how to get X, and Y?

Re: [Solved] Macro Inserting OOo Math Formula in Calc

PostPosted: Tue Dec 20, 2011 6:03 pm
by rudolfo
Please use a new thread if this is a new problem. Even if it is related with the old one, if the old one is marked as solved, it is not very likely that all forum participants will look into it. And you can also place a reference to the old thread in your new thread: viewtopic.php?f=45&t=45282.
In this case I don't see any similarities or relations of the two problems. Okay, same author, same Application modul, and both are macro issues, but all three doesn't justify placing this under the old thread.
Start a new one with a subject that is better matching your current problem and maybe also specify what kind of function you mean. First I thought a spreadsheet function for calculation of cell value. On furhter reading I rather think you are looking for something like column() and row() functions. In the latter case look at the api XCellRangeAddressable and struct CellRangeAddress.