Enum FontFamily

FontFamily

已弃用getFontFamily()setFontFamily(String) 方法现在使用字体字符串名称(而不是此枚举)。虽然此枚举已废弃,但仍可用于与旧脚本兼容。

支持的字体的枚举。

使用 FontFamily 枚举为一系列文本、元素或文档设置字体。

var body = DocumentApp.getActiveDocument().getBody();

// Insert a paragraph at the start of the document.
body.insertParagraph(0, "Hello, Apps Script!");

// Set the document font to Calibri.
body.editAsText().setFontFamily(DocumentApp.FontFamily.CALIBRI);

// Set the first paragraph font to Arial.
body.getParagraphs()[0].setFontFamily(DocumentApp.FontFamily.ARIAL);

// Set "Apps Script" to Comic Sans MS.
var text = 'Apps Script';
var a = body.getText().indexOf(text);
var b = a + text.length - 1;
body.editAsText().setFontFamily(a, b, DocumentApp.FontFamily.COMIC_SANS_MS);