[Solved] Macro Inserting OOo Math Formula in Calc

Keyboard macros or custom scripts

[Solved] Macro Inserting OOo Math Formula in Calc

Postby mctomac » Sun Nov 13, 2011 7:08 pm

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("com.sun.star.frame.DispatchHelper")

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.
Last edited by Hagar Delest on Sun Nov 13, 2011 9:35 pm, edited 1 time in total.
Reason: tagged [Solved].
Tomek
OpenOffice.ux 3.2.0 on Windows 7 Professional
mctomac
 
Posts: 3
Joined: Sun Nov 13, 2011 7:06 pm

Re: Macro Inserting OO Math Formula in Calc

Postby Charlie Young » Sun Nov 13, 2011 8:07 pm

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("com.sun.star.drawing.OLE2Shape")
   oShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
   
   oSheet.Drawpage.Add(oShape)
   oShape.Model.Formula = "size 20 e^{i%pi} + 1 = 0"
   
   oShape.setSize(oShape.OriginalSize)
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.
Apache OpenOffice 4.1.1
Windows XP
User avatar
Charlie Young
Volunteer
 
Posts: 1559
Joined: Fri May 14, 2010 1:07 am

Re: Macro Inserting OO Math Formula in Calc

Postby mctomac » Sun Nov 13, 2011 8:50 pm

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:
Tomek
OpenOffice.ux 3.2.0 on Windows 7 Professional
mctomac
 
Posts: 3
Joined: Sun Nov 13, 2011 7:06 pm

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

Postby mctomac » Tue Dec 20, 2011 2:33 pm

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)

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



But how to get X, and Y?
Tomek
OpenOffice.ux 3.2.0 on Windows 7 Professional
mctomac
 
Posts: 3
Joined: Sun Nov 13, 2011 7:06 pm

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

Postby rudolfo » Tue Dec 20, 2011 6:03 pm

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.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
rudolfo
Volunteer
 
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 6 guests