https://docs.google.com/document/d/1VrkXwfR24nIkX9KEGquIqFgkqPAke6MDst_N7YgSOY0/edit?usp=sharing
this is a sample doc what i am attempting to do is automize the flow of pressing: format> paragraph>borders and shading>reset
the goal is to reset the documents white background which aparrently is done via borders and shading
so to conclude i want to : 1.create the code 2.run the code on google app script and see that it works 3.add it as an add on lets focus on 1- 2
I attempted :
I attempted :
function resetParagraphFormatting() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraphs = body.getParagraphs();
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
paragraph.setAttributes({
"BORDER_WIDTH": 0,
"BORDER_COLOR": null,
"BACKGROUND_COLOR": null
});
}
}
we executes in action script but it doesn't affect the doc when i run it .
I thought that in your situation when Google Docs API is used, the script might be simple. So, in this answer, I would like to propose to achieve your goal using Google Docs API. The sample script is as follows.
Before you use this script, please enable Google Docs API at Advanced Google services.
function resetParagraphFormatting() {
const docId = DocumentApp.getActiveDocument().getId();
const obj = Docs.Documents.get(docId).body.content;
Docs.Documents.batchUpdate({ requests: [{ updateParagraphStyle: { range: { startIndex: 1, endIndex: obj.pop().endIndex }, fields: "borderBetween,borderBottom,borderTop,borderLeft,borderRight,shading", paragraphStyle: {} } }] }, docId);
}
When this script is run, the properties of "Borders and shading" are reset as follows.
spaceAbove,spaceBelow
into fields: "borderBetween,borderBottom,borderTop,borderLeft,borderRight,shading"
.