2017-07-27 12 views
2

任何人都可以告訴我如何讓生成的文件從表單中提取數據並將其作爲標題嗎?我已經看過Google腳本文檔,到目前爲止我還沒有找到任何可以回答我或給我看類似示例的東西。到現在爲止,我在這裏找到了相關的主題和代碼,但沒有一個符合我的需要。格式html google scrip

function doGet() { 
 
    return HtmlService 
 
     .createHtmlOutputFromFile('index') 
 
} 
 
function criarDocument(){ 
 
    
 
    var doc = DocumentApp.create('Doc'); 
 
} 
 
function criarSheet(){ 
 
     
 
    var sheet = SpreadsheetApp.create('Sheet'); 
 
} 
 
function createPresentation() { 
 
    var presentation = 
 
     Slides.Presentations.create({"title": "Presentation"}); 
 
    Logger.log("Created presentation with ID: " + presentation.presentationId); 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 
    <head> 
 
     <meta charset="UTF-8"> 
 
     <style> 
 
     body{ 
 
      background-color: lightblue; 
 
     } 
 
     </style> 
 
     <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> 
 
     <title>CRIE</title> 
 
     <script> 
 
      function criarDocument(){ 
 
       google.script.run.criarDocument(); 
 
       } 
 
      function criarSheet(){ 
 
       google.script.run.criarSheet(); 
 
      } 
 
      function createPresentation(){ 
 
       google.script.run.createPresentation(); 
 
      } 
 
     
 
      function titulo(){ 
 
       var st = document.getElementById('student').value; 
 
       var te = document.getElementById('teacher').value; 
 
       var wo = document.getelementById('work').value; 
 
      
 
       document.getElementById('student' + 'teacher' + 'work').value; 
 
     } 
 
     </script> 
 
    </head> 
 
    <body> 
 
    <h1><p align = "center">CRIE SEU ARQUIVO</p></h1> 
 
    <div> 
 
     <form id = 'form' onsubmit="titulo"> 
 
     <h2><p align = "center"> Student:</p></h2><p align = "center"> 
 
     <input type="text" name="estudante" id="student"> 
 
     <h2><p align = "center">Teacher: </p></h2><p align = "center"> 
 
     <input type="text" name="professor" id="teacher"> 
 
     <h2><p align = "center">Work Name</p></h2><p align = "center"> 
 
     <input type="text" name="trabalho" id="work"> 
 
     <br><br> 
 
     <button class="action" value="Submit" onclick= 'criarDocument()'>Start Document </button> 
 
     <button class="action" value="Submit" onclick='criarSheet()'>Start Sheet</button> 
 
     <button class="action" value="Submit" onclick='createPresentation()'>Start Presentation</button> 
 
     </form> 
 
    </div> 
 
    </body> 
 
</html>

回答

1

這裏有一個時間戳的文本輸入到從側邊欄電子表格的一個簡單的例子。不要忘記命名您的工作表筆記。

Code.gs

function onOpen() 
{ 
    loadSideBar(); 
    SpreadsheetApp.getUi().createMenu('My Menu').addItem('loadSidebar', 'loadSideBar').addToUi(); 
} 

function dispText(txt) 
{ 
    var ss=SpreadsheetApp.getActiveSpreadsheet(); 
    var sht=ss.getSheetByName('Notes'); 
    var ts=Utilities.formatDate(new Date(), 'GMT-6', "M/dd/yyyy HH:mm:ss"); 
    var row=[]; 
    row.push(ts); 
    row.push(txt); 
    sht.appendRow(row); 
    return true; 
} 

function loadSideBar() 
{ 
    var userInterface=HtmlService.createHtmlOutputFromFile('sidebar'); 
    SpreadsheetApp.getUi().showSidebar(userInterface); 
} 

sidebar.html

<!DOCTYPE html> 
<html> 
    <head> 
    <base target="_top"> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
    <script> 
    $(function() { 
     $('#txt1').val(''); 
     }); 
    function sendText() 
    { 
     var txt=$('#txt1').val(); 
     google.script.run 
     .withSuccessHandler(clearText) 
     .dispText(txt); 
    } 
    function clearText() 
    { 
     $('#txt1').val(''); 
    } 
    console.log("My code"); 
    </script> 
    </head> 
    <body> 
    <textarea id="txt1" rows="12" cols="35"></textarea><br /> 
    <input id="btn1" type="button" value="submit" onClick="sendText();" /> 

    </body> 
</html> 
+0

謝謝你對我的幫助。 –