SHARE
TWEET

Untitled

a guest Sep 12th, 2017 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from odf import text, teletype
  2. from odf.opendocument import load
  3.  
  4. textdoc = load("my document.odt")
  5. allparas = textdoc.getElementsByType(text.P)
  6. print teletype.extractText(allparas[0])
  7.    
  8. text.Change()
  9.    
  10. textdoc = load("myfile.odt")
  11. texts = textdoc.getElementsByType(text.P)
  12. s = len(texts)
  13. for i in range(s):
  14.     old_text = teletype.extractText(texts[i])
  15.     new_text = old_text.replace('something','something else')
  16.     new_S = text.P()
  17.     new_S.setAttribute("stylename",texts[i].getAttribute("stylename"))
  18.     new_S.addText(new_text)
  19.     texts[i].parentNode.insertBefore(new_S,texts[i])
  20.     texts[i].parentNode.removeChild(texts[i])
  21. textdoc.save('myfile.odt')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top