'Replace newlines in Google Doc
Cannot find and replace newlines in a Google doc.
This works (just showing that I have a body, and can replace):
bulletinBody.getBody().editAsText().replaceText("x","y");
These do not work:
bulletinBody.getBody().editAsText().replaceText("\\n","y");
bulletinBody.getBody().editAsText().replaceText("\\r","y");
Any help would be appreciated!
Solution 1:[1]
This worked for me~
let doc = DocumentApp.openById('***')
let body = doc.getBody()
let children = body.getNumChildren()
while (children) {
children -= 1
let item = body.getChild(children)
if (item.getType() == DocumentApp.ElementType.PARAGRAPH) {
if (!item.asText().getText()) {
item.merge()
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BeRT2me |
