Google 사이트에서 a를 처리하고, 양식 데이터를 Google 시트의 행에 덤프하고, 스프레드 시트의 데이터를 사용하여 Google 문서를 만들고 형식을 지정하는 Google AppsScript 용 코드를 만들려고합니다. 저는 아직 프로그래머가 아니며이 문제를 해결하기 위해 다른 코드를 빌 렸습니다. 스프레드 시트의 마지막 행에서 값을 가져올 수없는 것 외에는 모든 것이 작동합니다. 처음에는 작동하지만 두 번째로 양식 데이터를 제출할 때 값을 통해 여전히 행 1에서 가져옵니다. 데이터의 마지막 행에서 값을 가져오고 싶습니다. 아래에 AppScript 코드를 배치했습니다. Google Apps Script 정보를 읽은 후 다양한 조합을 시도했지만 제대로 작동하지 않습니다.
function doGet(request) {
return HtmlService.createTemplateFromFile('Index').evaluate();
}
/* @Include JavaScript and CSS Files */
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
/* @Process Form */
function processForm(formObject) {
var url = "https://docs.google.com/spreadsheets/d/1nz2uIWab1eSirljzvNn6SyNyxz3npDTu4mqVYV0blsU/edit#gid=0";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Data");
ws.appendRow([formObject.company_name,
formObject.identity_transformation]);
}
/* This function creates a new document from a template and updates the placeholder with info from a Google Sheet*/
function AutofillDocFromTemplate(){
// Get the current spreadsheet & sheet
var url = "https://docs.google.com/spreadsheets/d/1nz2uIWab1eSirljzvNn6SyNyxz3npDTu4mqVYV0blsU/edit#gid=0";
var ss = SpreadsheetApp.openByUrl(url).getSheetByName("Data");
var data = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn()).getValues();
// Set the range to the last row of data in the Sheet
// Get the original template Doc
const templateDoc = DriveApp.getFileById("1yu5jzg4NbRtTy_UjwzBmnpc-3_pNOqA-l1_UVsiAIWQ");
// Get the folder for where the docs should go
const folder = DriveApp.getFolderById("1prOQxp5jmDvJqiwIfLbbkLYWoz5QlTUC");
// Create the new file name
const newFileName = ("BrandScript ")
// Create a copy of the template doc
const newTempFile = templateDoc.makeCopy(newFileName, folder);
// Open the new temp doc
const openDoc = DocumentApp.openById(newTempFile.getId());
// Get the body of the new temp doc
const body = openDoc.getBody();
// Replace placeholders with spreadsheet data from last row
body.replaceText("%company_name%", data[1][0]);
body.replaceText("%identity_transformation%", data[1][1]);
// Save and close the new doc
openDoc.saveAndClose();
}
function AutoDeleteLastRow() {
var url = "https://docs.google.com/spreadsheets/d/1nz2uIWab1eSirljzvNn6SyNyxz3npDTu4mqVYV0blsU/edit#gid=0";
var ss = SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName("Data");
ss.deleteRow(2);
}
마지막 행만 가져 오기-단일 행 :
내용이있는 데이터 의 마지막 행 을 얻으려면 다음을 수행하십시오.
바꾸다:
var data = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn()).getValues();
와:
var data = ss.getRange(ss.getLastRow(), 1, 1, ss.getLastColumn()).getValues();
모든 행을 가져 오지만 마지막 행부터 시작-여러 행 :
당신은 모든 데이터를 가져하려는 범위 이외의 시작 으로부터 마지막 행 다음 현재의 솔루션을 사용할 수 있지만, 반대로data
데이터 뒤로를 얻을 수 배열 :
바꾸다:
var data = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn()).getValues();
와:
var data = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn()).getValues().reverse();
관련 :
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다