这是我的代码。家庭和大小的工作,但它不是中心。
function styleFooter() {
var body = DocumentApp.getActiveDocument();
var foot = body.getFooter();
var style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Helvetica Neue';
style[DocumentApp.Attribute.FONT_SIZE] = 9;
foot.setAttributes(style);
}
这是因为您需要获取段落()
并迭代页脚的每个段落。试试这个,它对我有用:
function styleFooter() {
var body = DocumentApp.getActiveDocument();
var foot = body.getFooter().getParagraphs(); // gets a list of your footer paragraphs
var style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Helvetica Neue';
style[DocumentApp.Attribute.FONT_SIZE] = 9;
// iterates each of your footer paragraphs
foot.forEach(function(element) {
element.setAttributes(style);
})
}
从Google Docs文档中:
HorizontalRule可以包含在ListItem或段落中,但它本身不能包含任何其他元素。