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

How to find equations and edit/replace them?

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


Joined: 01 Mar 2009
Posts: 4
Location: South Africa

PostPosted: Sun Mar 01, 2009 5:53 am    Post subject: How to find equations and edit/replace them? Reply with quote

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
View user's profile Send private message Yahoo Messenger
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Mon Mar 02, 2009 2:49 pm    Post subject: Reply with quote

Hi,

can you post an example doc somewhere ?

ms777
Back to top
View user's profile Send private message
marknewlyn
Newbie
Newbie


Joined: 01 Mar 2009
Posts: 4
Location: South Africa

PostPosted: Tue Mar 03, 2009 2:49 am    Post subject: Example file Reply with quote

Hi

I've attached a file to a blog post -

http://marknewlyn.net/files/Math_Gr8_m3_stripped_down.doc

The first 3 equations are some of the offending ones.

Mark
Back to top
View user's profile Send private message Yahoo Messenger
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Tue Mar 03, 2009 12:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
marknewlyn
Newbie
Newbie


Joined: 01 Mar 2009
Posts: 4
Location: South Africa

PostPosted: Thu Mar 05, 2009 4:03 am    Post subject: Thanks Reply with quote

Thanks a ton - I really appreciate your effort!

Mark
Back to top
View user's profile Send private message Yahoo Messenger
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