我的问题:如何使用Google Apps脚本将文字设置为Google文档中的标题或副标题? (见下面的视觉示例)
在有关格式化段落的Google Apps脚本文档中,它们会在ParagraphHeading class中显示不同类型的ParagraphHeadings,然后可以将Attribute class分配给具有某些样式属性的段落。但是,这些都没有办法将任何文本设置为文档中的标题或副标题。这是如何完成的?
我正在寻找类似的东西:
var doc = DocumentApp.getActiveDocument();
// Append a paragraph, with title.
var par1 = doc.appendParagraph("Title");
par1.setHeading(DocumentApp.ParagraphHeading.TITLE);
// Append a paragraph, with subtitle.
var par2 = doc.appendParagraph("SubTitle");
par2.setHeading(DocumentApp.ParagraphHeading.SUBTITLE);
// Append a paragraph, with heading 1.
var par3 = doc.appendParagraph("Heading 1");
par3.setHeading(DocumentApp.ParagraphHeading.HEADING1);
这就是我的意思:
答案 0 :(得分:1)
我明白你的意思了...我认为这是appscript中的那些功能之一,其中真的没有解释.....听起来你可能只需要使用普通的旧fontstyle,fontsize, fontcolor等试图模仿它。
答案 1 :(得分:0)
如果选择“为......文档创建脚本”,则获得的示例脚本根本不使用setHeading()
,而是显式操作WYSIWYG属性。 (我讨厌当人们在文档中这样做时,我只是在脚本中对它稍微不那么恼火,但那是另一天的话题!)
示例,直接从该示例脚本中提取,包括错误的语法:
function createDocument() {
var title = 'Script Center Report';
var summaryContents = 'This reports addresses...';
var overviewContents = 'We undertook this project because...';
var dataContents = 'We collected three samples of data...';
var doc = DocumentApp.create(title);
var footer = doc.getFooter();
var reportTitle = doc.appendParagraph(title);
reportTitle.setFontFamily(DocumentApp.FontFamily.ARIAL);
reportTitle.setFontSize(24);
reportTitle.setForegroundColor('#4A86E8');
reportTitle.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
...
这只是一种解决方法 - 如果你还没有这样做,你应该针对apps-script创建一个问题报告,以确保脚本可以使用所有“段落类型”。
答案 2 :(得分:0)
不幸的是,DocumentApp目前不提供对这些段落样式的访问。请在问题跟踪器上提交功能请求以添加它们。