2016-01-08 45 views

回答

1

這是可以做到的。

想象一下你的表格是這樣的:
enter image description here

下面寫代碼的文檔的腳本編輯器,

function readFromSpreadsheetAndWriteOnDoc() 
{ 
    // get the Spreadsheet by sheet id 
    var source = SpreadsheetApp.openById('1eqaThzYmTbZzP_xGTrPnTD1JX-B8rXrBrWDW8DwMNeU'); 
    // select the sheet 
    var sourcesheet = source.getSheetByName('Chart'); 
    // get the values on selectd range 
    var srcData = sourcesheet.getRange('B2:C5').getValues(); 

    //now your table data is on var 'srcData' 

    // select this google doc 
    var doc = DocumentApp.getActiveDocument(); 
    // select the body 
    var body = doc.getBody(); 

    body.insertParagraph(0, 'My Title').setHeading(DocumentApp.ParagraphHeading.HEADING1).setAlignment(DocumentApp.HorizontalAlignment.CENTER); 
    table = body.appendTable(srcData); 
    table.getRow(0).editAsText().setBold(true); 

} 

你會得到這個,

enter image description here

享受!

相關問題