【发布时间】:2019-10-23 06:33:24
【问题描述】:
我制作了一个应用程序,可以将文档转换为 MLA 格式(例如 Times New Roman、12 pt 等),现在我想更进一步,让用户选择所有链接,我想要它使用 EasyBib API 来引用它们。有一个由 EasyBib 制作的附加组件,如果您在其中放置链接,它会提供引文,然后单击“将参考书目添加到 Doc”以按字母顺序将 MLA 引文添加到“被引作品”页面,最后一个Google 文档中的页面。谷歌搜索这个问题已被证明是无用的。
function myFunction() {
/*
This function turns the document's format into standard MLA.
*/
var body = DocumentApp.getActiveDocument().getBody();
body.setFontSize(12); // Set the font size of the contents of the documents to 12
body.setForegroundColor('#000000'); // Set the color to black
body.setFontFamily("Times New Roman"); // Set the font family to Times New Roman (standard MLA)
body.editAsText().setBold(false); // Make everything not bold
// Set the four headings at the top
var datum = '3 February 1976';
var course = 'Social Studies';
var teacher = 'Your Teacher\'s Name Here';
var student = 'Your Name Here';
if (body.getParagraphs().length >= 4) {
var firstPar = body.getParagraphs()[0].getText();
var secondPar = body.getParagraphs()[1].getText();
var thirdPar = body.getParagraphs()[2].getText();
var lastPar = body.getParagraphs()[3].getText();
if (!(firstPar == student && secondPar == teacher && thirdPar == course && lastPar == datum)) {
body.insertParagraph(0, datum).setIndentFirstLine(0);
body.insertParagraph(0, course).setIndentFirstLine(0);
body.insertParagraph(0, teacher).setIndentFirstLine(0);
body.insertParagraph(0, student).setIndentFirstLine(0);
}
} else if (body.getParagraphs().length >= 1 && body.getParagraphs()[0].getText() !== '') {
body.insertParagraph(0, datum).setIndentFirstLine(0);
body.insertParagraph(0, course).setIndentFirstLine(0);
body.insertParagraph(0, teacher).setIndentFirstLine(0);
body.insertParagraph(0, student).setIndentFirstLine(0);
}
// Loops through paragraphs in body and sets each to double spaced
var paragraphs = body.getParagraphs();
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
// Double-spaced
paragraph.setLineSpacing(2);
// Left align the first cell.
paragraph.setAlignment(DocumentApp.HorizontalAlignment.LEFT);
if (i > 3) {
// Set to 1 indent per paragraph
Logger.log(paragraph.getIndentFirstLine());
paragraph.setIndentFirstLine(36);
}
}
}
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('AutoFormat')
.addItem('MLA', 'myFunction')
.addToUi();
}
onOpen()
我的问题是我需要使用什么代码来使用 EasyBib 插件或 Google Apps 脚本中的 Google Docs 中的任何其他插件
【问题讨论】:
-
问题是什么?
-
我不知道如何在 Google Apps 脚本代码中使用插件
标签: google-apps-script google-docs google-apps-script-addon