OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved] VBScript to create a math formula into a writer doc

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
epdiamantopoulos
Newbie
Newbie


Joined: 08 Jul 2010
Posts: 4
Location: Greece

PostPosted: Mon Feb 07, 2011 6:50 am    Post subject: [Solved] VBScript to create a math formula into a writer doc Reply with quote

Hi,

I use the following lines to create a Writer document using VBScript

Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set objDesktop= objServiceManager.createInstance("com.sun.star.frame.Desktop")
Dim args()
Set objDocument= objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
Set objText= objDocument.getText
Set objCursor= objText.createTextCursor
objText.insertString objCursor, "Created in " & Now() & vbLf, false

and its ok. Now I would like to create a math formula inside one line. Does anyone know how??
I would
_________________
Best regards!


Last edited by epdiamantopoulos on Mon Feb 07, 2011 11:21 am; edited 1 time in total
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Mon Feb 07, 2011 9:29 am    Post subject: Reply with quote

Like this?
Code:

Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection = objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
Dim args()
Set objDocument = objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
Set objText = objDocument.getText
Set objCursor = objText.createTextCursor
objText.insertString objCursor, "Created in " & Now() & vbLf, false

objCursor.collapseToEnd
objText.appendParagraph(args)

objCursor.gotoNextParagraph False

Set objShape = objDocument.createInstance("com.sun.star.text.TextEmbeddedObject")
objShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
objShape.TextWrap = objCoreReflection.getByHierarchicalName("com.sun.star.text.WrapTextMode.NONE")
objText.insertTextContent objCursor, objShape, False
Set objFormula = objShape.getEmbeddedObject
objFormula.Formula = "s = sqrt{alignc {1} over {N - 1} sum from i = 1 to N (x_i - bar x )^2}"
Back to top
View user's profile Send private message
epdiamantopoulos
Newbie
Newbie


Joined: 08 Jul 2010
Posts: 4
Location: Greece

PostPosted: Mon Feb 07, 2011 11:15 am    Post subject: That right! Reply with quote

I am obliged!.Thank you very much!
_________________
Best regards!
Back to top
View user's profile Send private message
swingkyd
OOo Advocate
OOo Advocate


Joined: 15 Sep 2004
Posts: 479

PostPosted: Wed Feb 09, 2011 6:40 pm    Post subject: Reply with quote

what would be really cool is if someone has figured out how to do this in CALC!
Back to top
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Thu Feb 10, 2011 2:03 am    Post subject: Reply with quote

Quote:
what would be really cool is if someone has figured out how to do this in CALC!

I wonder where do you want to place the formula.
Code:
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection = objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set objDesktop = objServiceManager.createInstance("com.sun.star.frame.Desktop")
Dim args()
Set objDocument = objDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, args)
Set objSheet = objDocument.getSheets.getByIndex(0)
Set objDrawPage = objSheet.getDrawPage

Set objShape = objDocument.createInstance("com.sun.star.drawing.OLE2Shape")
objShape.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"

objDrawPage.add(objShape)

Set objFormula = objShape.Model
objFormula.Formula = "s = sqrt{alignc {1} over {N - 1} sum from i = 1 to N (x_i - bar x )^2}"
objShape.setSize(objShape.OriginalSize)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group