(30 분마다) 트리거 또는 이벤트를 사용하여 Google 드라이브에있는 Google 스프레드 시트를 .xls
또는 .xlsx
으로 자동으로 내보내는 Google Apps 스크립트를 원합니다. -driven (파일을 편집 할 때마다). 내가 스택 질문에 here 오래된 오버플로 기반으로했지만 이후 oAuthConfig
은 중단되었습니다, 나는 OAuth1
라이브러리를 기반으로 새 스레드를 열 것이라고 생각합니다.Google 스프레드 시트를 Excel로 자동 내보내기
파일이 내가
Tools -> Script Editor...
에 가서 나는 최신OAuth1
라이브러리 (12 절 라이브러리 프로젝트 키를 설치하려면 다음 instructions을 따라 열려있는 동안 : 여기난 다음 모든 단계는 내가 사용
Mb2Vpd5nfD3Pz-_a-39Q4VfxhMjh3Sh48
)입니다. 또한Development mode
사용 또는 사용 안 함으로 시도했습니다.- 가 그럼 난 구글 API의 모든 변경 사항에 따라 위의 스크립트를 변경하려고합니다 (here, here, here 및 here).
googleOAuth_(...)
을 제외한 모든 기능을 실행하고 요청한 권한이 부여되었습니다.마지막으로
Resources -> Current project's triggers
에서 트리거를 작성하여 모든 편집시 함수myOnEdit
을 스프레드 시트에 호출하고 실패 할 경우 전자 메일로 알려줍니다. 여기
function myOnEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
var r = s.getActiveCell();
if(r.getColumn() != 1) { //checks the column
var row = r.getRow();
var time = new Date();
time = Utilities.formatDate(time, ss.getSpreadsheetTimeZone(), "MM/dd/yy, hh:mm:ss");
var id = ss.getId();
s.getRange('A' + row.toString()).setValue(time);
var url = 'https://docs.google.com/feeds/';
var doc = UrlFetchApp.fetch(url+'download/spreadsheets/Export?key='+id+'&exportFormat=xls',
googleOAuth_('docs',url)).getBlob()
DriveApp.createFile(doc).setName('newfile.xls')
}
}
function authorise(){
// function to call to authorize googleOauth
var id=SpreadsheetApp.getActiveSpreadsheet().getId();
var url = 'https://docs.google.com/feeds/';
var doc = UrlFetchApp.fetch(url+'download/spreadsheets/Export?key='+id+'&exportFormat=xls',
googleOAuth_('docs',url)).getBlob()
}
function googleOAuth_(name,scope) {
var service = OAuth1.createService(name);
service.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
service.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
service.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
service.setConsumerKey('anonymous');
service.setConsumerSecret('anonymous');
return {oAuthServiceName:name, oAuthUseToken:"always"};
}
, 코드가 오류를 생성하지 않는 것처럼 보이지만이 문제가 있습니다
심지어 파일
newfile.xls
을 경우는 나는 그것이 원하는 것이 아니다. 기본적으로 Excel에서 열면 ""newfile.xls "파일 형식과 확장명이 일치하지 않습니다. 파일이 손상되거나 안전하지 않을 수 있습니다. 원본을 신뢰하지 않는 한 열지 마십시오. 어쨌든 열어보고 싶습니까? "라는 메시지가 표시되면 잠시 기다렸다가 파일이 열리면 엑셀 형식의 Google 로그인 페이지처럼 보입니다.행을 편집 할 때마다 해당 행의 첫 번째 열에 해당하는 셀이 원래 스프레드 시트의 "07/03/16, 03:58:30"과 같은 현재 타임 스탬프로 변경됩니다 .
파일을 XLSX로 수동으로 내보내는 경우 열 수 있습니까? UrlFetch 대신 콘텐츠 서비스를 사용 해본 적이 있습니까? –
@Ruben 예 가능합니다. 당신이 제안한 방법이나'File' 메뉴에 의해. – mgus
관련 항목 : http://stackoverflow.com/questions/31809987/google-app-scripts-email-a-spreadsheet-as-excel –