Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let FOLDER_URL = "";
- function driveIt(url, i) {
- const blobushka = getBlob(url);
- const file = DriveApp.createFile(blobushka).setName(
- `${i}. файл от ${Utilities.formatDate(
- new Date(),
- Session.getScriptTimeZone(),
- "YY-MM-dd"
- )}`
- );
- FOLDER_URL
- ?
- file.moveTo(DriveApp.getFolderById(getIdFromUrl(FOLDER_URL))) :
- "";
- return file.getUrl();
- }
- function driveIts() {
- const ss = SpreadsheetApp.getActive();
- const sheets = ss.getSheets();
- const arr = sheets
- .filter((sh) => sh.getTabColor() == "#ff0000")
- .map(
- (sh) =>
- "https://docs.google.com/spreadsheets/export?id=" +
- ss.getId() +
- "&gid=" +
- sh.getSheetId() +
- "&exportFormat=xlsx"
- );
- console.log(arr);
- const msg = arr.map((url, i) => driveIt(url, i));
- Browser.msgBox(`А вот и ваш файл:\n ${msg.join("\n")}`);
- }
- function driveItsCSV(){
- const ss = SpreadsheetApp.getActive();
- const sheets=ss.getSheets()
- const isTabColorMeColor=(color,sh)=>(sh)=>sh.getTabColor()==color
- const isTabColorRed=isTabColorMeColor('#ff0000')
- const getExportLinkExt=(ss,exten,sh)=>(exten,sh)=>(sh)=>"https://docs.google.com/spreadsheets/export?id=" + ss.getId() + "&gid=" + sh.getSheetId() + "&exportFormat="+exten
- const getExportLinkSheetSS=getExportLinkExt(ss)
- const getExportLinkSheetSSToXLSX=getExportLinkSheetSS('csv')
- const redSheet=sheets
- .filter(isTabColorRed)
- const msg=redSheet
- .map(getExportLinkSheetSSToXLSX)
- .map(driveIt)
- redSheet.forEach(sh=>sh.setTabColor('#000000'))
- if (msg.length ){
- Browser.msgBox(`А вот и ваш файл:\n ${msg.join('\n')}`);
- }
- }
- function getBlob(url) {
- var token = ScriptApp.getOAuthToken();
- var response = UrlFetchApp.fetch(url, {
- headers: {
- Authorization: "Bearer " + token,
- },
- });
- return response.getBlob();
- }
- function getIdFromUrl(url) {
- return url.match(/[-\w]{25,}/);
- }
- function onOpen(e) {
- SpreadsheetApp.getUi()
- .createMenu("С к р и п т ы")
- .addItem("превратить Листы Книги в XLSX", "driveIts")
- .addItem("превратить Листы Книги в CSV", "driveItsCSV")
- .addToUi();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement