Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let FOLDER_URL = '';
- function driveIt(){
- const ss = SpreadsheetApp.getActive();
- const sh = ss.getActiveSheet();
- const blobushka = getBlob(ss, sh);
- const file = DriveApp
- .createFile(blobushka)
- .setName(`файл от ${Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'YY-MM-dd')}`);
- FOLDER_URL ? file.moveTo(DriveApp.getFolderById(getIdFromUrl(FOLDER_URL))) : ''
- Browser.msgBox(`А вот и ваш файл: ${file.getUrl()}`);
- }
- function getIdFromUrl(url) { return url.match(/[-\w]{25,}/); }
- function getBlob(ss, sh) {
- var url = "https://docs.google.com/spreadsheets/export?id=" + ss.getId() + "&gid=" + sh.getSheetId() + "&exportFormat=xlsx"
- var token = ScriptApp.getOAuthToken();
- var response = UrlFetchApp.fetch(url, {
- headers: {
- 'Authorization': 'Bearer ' + token
- }
- });
- return response.getBlob();
- }
- function onOpen(e){
- SpreadsheetApp.getUi()
- .createMenu("С к р и п т ы")
- .addItem("превратить выбранный лист в XLSX", "driveIt")
- .addToUi();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement