1

I need to do find and replace in a Google doc. Essentially, I have a template Google Doc that I want to copy and customize, programatically.

The original and the copy should both be in the native Gdoc format, and it should look the same before and after, in terms of visual layout and formatting.

Tried downloading HTML (and other formats) via the exportLink, doing my find-and-replace on the output, then updating the content to be the output of the find-and-replace. But that screws up the formatting, and seems very... roundabout.

I'm using the Ruby client, for what that's worth, but the main question is, what's the best practice for doing a find-and-replace in a native Doc?

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
Altay
  • 81
  • 3

1 Answers1

1

I think the easiest solution would be to use the replaceText method of the Document service in Apps Script:

https://developers.google.com/apps-script/class_document#replaceText

Claudio Cherubino
  • 14,896
  • 1
  • 35
  • 42
  • There's no equivalent method in the SDK? So then how do I integrate my Rails app -- which is on my server and which uses the Drive SDK -- with Apps Script? Can I write an Apps Script, and then trigger that script from my app (e.g. by hitting a url)? – Altay Jan 11 '13 at 04:47