ArtA
ArtA

Reputation: 15

How to delete specific parts of a google docs using google Apps script

I'm would like to edit text in a google doc, specifically:
1) I want to delete an element of text between the first letter in the document and a predefined stop point ("//", in this case).

I've unsuccessuflly tried doing something like this:

    var rangeElement = DocumentApp.openById(fileID).getBody().findText("//");
          if (rangeElement.isPartial()) {
            var startOffset = rangeElement.getStartOffset([0]);
            var endOffset = rangeElement.getEndOffsetInclusive("//");
          rangeElement.getElement().asText().deleteText(startOffset,endOffset);} 

Any help would be greatly appreciated. Thank you for your time.

Upvotes: 0

Views: 2078

Answers (1)

Cooper
Cooper

Reputation: 64040

Looking inside a Google Doc

This is a tool I've used a lot and it continually changes depending upon my needs but it has been extremely useful in helping me to learn about Google Docs. Just this evening I used it to make a document for printing envelopes. Have fun. I've always had trouble making sure that all of the files needed were provided. So I decided to put everything including the kitchen sink in it but when I did stackoverflow echoed with an error about it being too big. So instead I put it on my website here until I can find a better place like github.

Upvotes: 1

Related Questions