Header section within Google Docs

前端 未结 1 1713
别跟我提以往
别跟我提以往 2021-01-20 06:46

So, i have ammended some code to add the description field of a file search to a spreadsheet, which is potentially useful for me. However, ideally I want to conduct a file s

相关标签:
1条回答
  • 2021-01-20 07:17

    Manually insert a header into a document, then open the document and get the ID out of the url. Then run some test code:

    function getHeader() {
      var doc = DocumentApp.openById('your ID here');
      var hdear = doc.getHeader();
    
      Logger.log('hdear: ' + hdear);
    };
    

    Run the code from the script editor, then in the VIEW menu, open the LOGS. You can also run the code line by line with the debugger.

    In the log, it should show "HeaderSection"


    You should use DriveApp to get a list of files, but then you'll need to use DocumentApp to get the header.

    function myFunction() {
      var files = DriveApp.searchFiles("fullText contains '"+searchTerm.replace("'","\'")+"'");
      var output = [];
    
      while (files.hasNext()) {
        var file = files.next();
        var fileId = file.getId();
    
        var fileType = file.getMimeType();
    
        if (fileType === MimeType.GOOGLE_DOCS) {
          var doc = DocumentApp.openById(fileId);
    
          var name = doc.getName();
          var header= doc.getHeader().getText();
          var url = doc.getUrl();
    
          output.push(name);
          output.push(fileType);
          output.push(header);
          output.push(url);
        };
      };
    
      var outerArray = [];
      outerArray.push(output);
      // write data to the sheet
      sheet.getRange(2, 1, outerArray.length, output.length).setValues(outerArray);
    };
    
    0 讨论(0)
提交回复
热议问题