스프레드 시트에 정의 된 프로세스에 대한 규칙 목록이 있습니다. 그건 백엔드 물건이야. 최종 사용자는 규칙 스프레드 시트의 내용을 기반으로 동적 메뉴가있는 Google 문서를 복사합니다. 필자는 스프레드 시트에서 읽고 시트 용으로 명명 된 메뉴 항목을 만드는 onOpen 함수를 작성했습니다. 이러한 메뉴 항목은 시트에있는 규칙을 처리하는 기능을 실행합니다.스프레드 시트에 액세스 할 때 Google Doc onOpen이 실행되지 않습니다.
내 문제는 스크립트 편집기에서 트리거 될 때 onOpen 함수가 올바르게 실행되지만 문서가 열릴 때 실행되지 않는다는 것입니다. 주석을 달아서 놀아서 놀아서 SpreadsheetApp.openById() 명령으로 인해 onOpen 함수가 초기 문서로드시 실패하게됩니다. 명령이 사용되지 않을 때 실행됩니다.
시트 정의를 함수의 내부와 외부에서 모두 설정 했으므로 결과에는 차이가 없으므로 아래 코드는 가설을 세워야한다고 생각합니다. 실제로는 문서가 열릴 때 자동으로 실행되지 않습니다. 흥미 롭군요, 그렇죠? 여기
https://docs.google.com/document/d/1dQb5RYntMsbTIxDCh6uEoNur3oOlVisxP7hD_sK3Fsk/edit
그리고 메뉴 항목을 정의하는 스프레드 시트된다 :
https://docs.google.com/spreadsheet/ccc?key=0AjR3e-R75aP8dHR0WWpGNF9vdEhvcy12eHJTMmF3aXc#gid=0
// from this spreadsheet, I want function names based on the sheet names
var ss = SpreadsheetApp.openById("0AjR3e-R75aP8dHR0WWpGNF9vdEhvcy12eHJTMmF3aXc");
var sheets = ss.getSheets();
function onOpen() {
var menu = DocumentApp.getUi().createMenu("Menu Title");
// dynamic menu based on tabs in spreadsheet
for (sheet in sheets) {
var thisCaption = sheets[sheet].getName();
var thisFunction = "sheet_" + sheet;
menu.addItem(thisCaption, thisFunction);
}
menu.addToUi();
}
// I precreate dummy functions based on sheet number
function sheet_0() { process_sheet(0); }
function sheet_1() { process_sheet(1); }
function sheet_2() { process_sheet(2); }
function sheet_3() { process_sheet(3); }
function sheet_4() { process_sheet(4); }
function sheet_5() { process_sheet(5); }
function sheet_6() { process_sheet(6); }
function sheet_7() { process_sheet(7); }
function sheet_8() { process_sheet(8); }
function sheet_9() { process_sheet(9); }
function process_sheet(sheetNum) {
var thisSheet = sheets[sheetNum];
// at this point I do some processing based on the contents of the sheet
// for the sake of example, I'll just set the document name to the sheet name
var sheetName = thisSheet.getName();
DocumentApp.getActiveDocument().setName(sheetName);
}
감사합니다. Henrique. "이 메뉴를 클릭 한 다음 다른 메뉴가 있기 때문에 지금은 다른 메뉴로 돌아갑니다"라는 흐름이 마음에 들지 않지만 그럴 것 같습니다. – ccombs