| View previous topic :: View next topic |
| Author |
Message |
epdiamantopoulos Newbie

Joined: 08 Jul 2010 Posts: 4 Location: Greece
|
Posted: Mon Feb 07, 2011 6:50 am Post subject: [Solved] VBScript to create a math formula into a writer doc |
|
|
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 |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Mon Feb 07, 2011 9:29 am Post subject: |
|
|
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 |
|
 |
epdiamantopoulos Newbie

Joined: 08 Jul 2010 Posts: 4 Location: Greece
|
Posted: Mon Feb 07, 2011 11:15 am Post subject: That right! |
|
|
I am obliged!.Thank you very much! _________________ Best regards! |
|
| Back to top |
|
 |
swingkyd OOo Advocate

Joined: 15 Sep 2004 Posts: 479
|
Posted: Wed Feb 09, 2011 6:40 pm Post subject: |
|
|
| what would be really cool is if someone has figured out how to do this in CALC! |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Thu Feb 10, 2011 2:03 am Post subject: |
|
|
| 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 |
|
 |
|