问题
Using Method: documents.get I can retrieve a document. The result is structured as described at Resource: documents. However, I need to select the whole document and change the line-height to 1.5, but I am unable to find a way to do it.
var updateObject = {
documentId: documentId,
resource: {
requests: [{
'updateTextStyle': {
'range': {
'startIndex': 1,
'endIndex': 0
},
'textStyle': {
'line-height': 1.5
},
'fields': 'line-height'
}
}],
},
};
docs.documents.batchUpdate(updateObject)
.then(function(res) { // Modified
console.log(res);
}, function(err) {
console.error(err);
});
回答1:
Get your document and calculate start and end indexes of all
paragraphs
within thebody
.Issue updateParagraphStyle request for each of the above
paragraphs
with linespacing as150
for 1.5 times the normal space.
回答2:
I managed to do this using Google Apps Script...
function setLineHeight() {
var d = DocumentApp.getActiveDocument();
var b = d.getBody()
var pars = b.getParagraphs();
// for each paragraph in the active document...
pars.forEach(function(e) {
// clean up paragraphs that only contain whitespace
e.setLineSpacing(1.5);
})
}
来源:https://stackoverflow.com/questions/60394199/change-the-line-height-of-all-content-in-a-google-doc-using-the-api-via-nodejs-u