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

Joined: 01 Mar 2009 Posts: 4 Location: South Africa
|
Posted: Sun Mar 01, 2009 5:53 am Post subject: How to find equations and edit/replace them? |
|
|
Hi All
I've got some Word documents which when opened in OO 2.4 have a few equations which are "read-only". If I select the equation and save it as an .odf file and then re-import it it works and it editable.
I'm completely new to this so I was hoping that someone could point me in the right direction on:
1. how to loop through all the equations in a document?
2. whether or not there is a way to change them from read-only to editable through the API without making an .odf file and re-importing it?
Thanks
Mark |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Mon Mar 02, 2009 2:49 pm Post subject: |
|
|
Hi,
can you post an example doc somewhere ?
ms777 |
|
| Back to top |
|
 |
marknewlyn Newbie

Joined: 01 Mar 2009 Posts: 4 Location: South Africa
|
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Mar 03, 2009 12:57 pm Post subject: |
|
|
Hi,
that was a tough one ... it seems that OO does not convert the Microsoft Equation OLE Objects automatically into OO Math objects, although OO is perfectly able to.
Save your .doc as an odt, install the below macro, and run it twice or three times ...
Good luck,
ms777
| Code: | Sub Main
oDoc = ThisComponent
oStorageFac = createUnoService("com.sun.star.embed.StorageFactory")
oStorage = oStorageFac.createInstance
Dim aProps(1) as new com.sun.star.beans.PropertyValue
aProps(0).Name = "InputStream"
aProps(1).Name = "Hidden"
aProps(1).Value = true
objText = oDoc.Text
objCursor = objText.createTextCursor
oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
for k= oDoc.EmbeddedObjects.Count-1 to 0 step -1
'for k=0 to 0
oEO = oDoc.EmbeddedObjects.getByIndex(k)
s = UCase(oEO.CLSID)
if (s = "0002CE01-0000-0000-c000-000000000046") or (s = "00021700-0000-0000-C000-000000000046") or (s = "0002CE02-0000-0000-C000-000000000046") then
sStorage = "ms777Formula" & k
'write the existing formula to an internal storage
oXEO = oEO.ExtendedControlOverEmbeddedObject
oXEO.storeToEntry(oStorage, sStorage, Array(), Array())
oStream = oStorage.openStreamElement(sStorage, com.sun.star.embed.ElementModes.SEEKABLEREAD)
aProps(0).Value = oStream
oFormula = StarDesktop.loadComponentFromURL("private:stream", "_default", 0, aProps)
sFormulaString = oFormula.Formula
oFormula.close(true)
msgbox sFormulaString
'mark the existing formula
objCursor.gotoRange(oEO.Anchor, false)
objCursor.goRight(1, true)
'generate the new formula
oTEO = oDoc.createInstance("com.sun.star.text.TextEmbeddedObject")
oTEO.AnchorType = com.sun.star.text.TextContentAnchorType.AS_CHARACTER
oTEO.CLSID = "078B7ABA-54FC-457F-8551-6147e776a997"
'insert the new formula
objText.insertTextContent(objCursor, oTEO, true)
oTEO.EmbeddedObject.Formula = sFormulaString
'activate and deactivate the new formula in order to update the view
oDoc.CurrentController.select(oTEO)
wait(200)
oDisp.executeDispatch(oDoc.CurrentController.Frame, "slot:6102", "", 0, Array())
oXEO = oTEO.ExtendedControlOverEmbeddedObject
oXEO.changeState(com.sun.star.embed.EmbedStates.RUNNING)
endif
next k
End Sub |
|
|
| Back to top |
|
 |
marknewlyn Newbie

Joined: 01 Mar 2009 Posts: 4 Location: South Africa
|
Posted: Thu Mar 05, 2009 4:03 am Post subject: Thanks |
|
|
Thanks a ton - I really appreciate your effort!
Mark |
|
| Back to top |
|
 |
|