简体   繁体   中英

Use another Add-On for Google Apps Script Google Docs

I made an app that converts a document to MLA formatted (eg Times New Roman, 12 pt, etc.) and now I would like to take it a step further as to let the user select all the links, and I want it to use the EasyBib API to make citations out of them. There is an add-on that is made by EasyBib, where if you put a link in, it gives the citation, and you click 'Add Bibliography to Doc' in order to add the MLA citation alphabetically to the Works Cited page, the last page in the Google Document. Googling this issue has proven useless.

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()

My question is what code do I need to use to use the EasyBib add-on, or any other add-on in Google Docs in Google Apps Script

There isn't a general way to use a third-party add-on from Google Apps Script. Each add-on developer should decide if they will add an API for their add-on. While it's possible what I found is that existing web services that have their own API create an add-on to make it easier to user their service not the other way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM