|
1 |
| -function onOpen() { |
2 |
| - const ui = SpreadsheetApp.getUi(); |
3 |
| - const menu = ui.createMenu('TOOLS BỔ TRỢ'); |
4 |
| - |
5 |
| - menu.addItem('Mở tool gán nhãn', 'loadLabelingForm'); |
6 |
| - menu.addSeparator(); |
7 |
| - |
8 |
| - menu.addItem('Sắp xếp sheets theo tên', 'sortSheets'); |
9 |
| - menu.addItem('Xóa urls trùng trong sheets', 'removeDuplicates'); |
10 |
| - // menu.addItem('Download urls trong sheets', 'downloadUrls'); |
11 |
| - menu.addItem('Đồng bộ sheets vào Google Drive', 'syncToDrive'); |
12 |
| - menu.addSeparator(); |
13 |
| - |
14 |
| - menu.addItem('Đặt kích thước ô chứa ảnh', 'setImageCellsSize'); |
15 |
| - menu.addItem('Move ảnh đang chọn qua nhãn Khác', 'moveImage'); |
16 |
| - menu.addToUi(); |
17 |
| -} |
18 |
| - |
19 |
| -function loadLabelingForm() { |
20 |
| - const service = HtmlService.createTemplateFromFile('index'); |
21 |
| - const html = service.evaluate().setTitle('TOOL GÁN NHÃN'); |
22 |
| - const ui = SpreadsheetApp.getUi(); |
23 |
| - ui.showSidebar(html); |
24 |
| -} |
25 |
| - |
26 |
| -function sortSheets() { |
27 |
| - const spreadSheet = SpreadsheetApp.getActiveSpreadsheet(); |
28 |
| - const sheets = spreadSheet.getSheets(); |
29 |
| - const sheetNameArray = []; |
30 |
| - |
31 |
| - for (let i = 0; i < sheets.length; i++) |
32 |
| - sheetNameArray.push(sheets[i].getName()); |
33 |
| - sheetNameArray.sort(); |
34 |
| - |
35 |
| - for (let j = 0; j < sheets.length; j++) { |
36 |
| - spreadSheet.setActiveSheet( |
37 |
| - spreadSheet.getSheetByName(sheetNameArray[j]) |
38 |
| - ); |
39 |
| - spreadSheet.moveActiveSheet(j + 1); |
40 |
| - } |
41 |
| -} |
42 |
| - |
43 |
| -function removeDuplicates() { |
44 |
| - const response = myMsgBox('Xóa urls trùng trong sheet'); |
45 |
| - if (response === 'yes') { |
46 |
| - runOnAllSheets(removeDuplicatesInSheet, []); |
47 |
| - Browser.msgBox( |
48 |
| - 'Xóa urls trùng trong sheet', |
49 |
| - 'Đã xóa urls trùng của tất cả sheets', |
50 |
| - Browser.Buttons.OK |
51 |
| - ); |
52 |
| - } else if (response === 'no') { |
53 |
| - const result = runOnActiveSheet(removeDuplicatesInSheet, []); |
54 |
| - Browser.msgBox( |
55 |
| - 'Xóa urls trùng trong sheet', |
56 |
| - `Số ảnh còn lại hiện tại: ${result} ảnh`, |
57 |
| - Browser.Buttons.OK |
58 |
| - ); |
59 |
| - } |
60 |
| -} |
61 |
| - |
62 |
| -function downloadUrls() { |
63 |
| - const response = myMsgBox('Download urls'); |
64 |
| - const sourceFolder = DriveApp.getFoldersByName('Vietnamese Foods').next(); |
65 |
| - const urlsFolder = sourceFolder.getFoldersByName('Image Urls').next(); |
66 |
| - |
67 |
| - if (response === 'yes') { |
68 |
| - runOnAllSheets(downloadUrlsInSheet, [urlsFolder]); |
69 |
| - Browser.msgBox( |
70 |
| - 'Download thành công', |
71 |
| - 'Đã lưu urls của tất cả sheets vào Google Drive', |
72 |
| - Browser.Buttons.OK |
73 |
| - ); |
74 |
| - } else if (response === 'no') { |
75 |
| - const result = runOnActiveSheet(downloadUrlsInSheet, [urlsFolder]); |
76 |
| - Browser.msgBox( |
77 |
| - 'Download thành công', |
78 |
| - `Đã lưu ${result} urls vào Google Drive`, |
79 |
| - Browser.Buttons.OK |
80 |
| - ); |
81 |
| - } |
82 |
| -} |
83 |
| - |
84 |
| -function syncToDrive() { |
85 |
| - const response = myMsgBox('Đồng bộ vào Google Drive'); |
86 |
| - const sourceFolder = DriveApp.getFoldersByName('Vietnamese Foods').next(); |
87 |
| - const datasetFolder = sourceFolder.getFoldersByName('Dataset').next(); |
88 |
| - const urlsFolder = sourceFolder.getFoldersByName('Image Urls').next(); |
89 |
| - |
90 |
| - if (response === 'yes') { |
91 |
| - runOnAllSheets(syncToDriveInSheet, [datasetFolder, urlsFolder]); |
92 |
| - Browser.msgBox( |
93 |
| - 'Đồng bộ thành công', |
94 |
| - 'Đã đồng bộ hình ảnh kèm urls của tất cả sheets vào Google Drive', |
95 |
| - Browser.Buttons.OK |
96 |
| - ); |
97 |
| - } else if (response === 'no') { |
98 |
| - const result = runOnActiveSheet(syncToDriveInSheet, [ |
99 |
| - datasetFolder, |
100 |
| - urlsFolder, |
101 |
| - ]); |
102 |
| - Browser.msgBox( |
103 |
| - 'Đồng bộ thành công', |
104 |
| - `Đã đồng bộ ${result} hình ảnh kèm urls vào Google Drive`, |
105 |
| - Browser.Buttons.OK |
106 |
| - ); |
107 |
| - } |
108 |
| -} |
109 |
| - |
110 |
| -function setImageCellsSize() { |
111 |
| - const newSize = SpreadsheetApp.getUi() |
112 |
| - .prompt( |
113 |
| - 'Chọn kích thước cho ô chứa ảnh', |
114 |
| - 'Nhập kích thước mới theo định dạng (height,width) - Mặc định: 200,350', |
115 |
| - SpreadsheetApp.getUi().ButtonSet.OK |
116 |
| - ) |
117 |
| - .getResponseText() |
118 |
| - .split(','); |
119 |
| - |
120 |
| - const response = myMsgBox('Đặt kích thước ô chứa ảnh'); |
121 |
| - if (response === 'yes') runOnAllSheets(setImageCellsSizeInSheet, [newSize]); |
122 |
| - else if (response === 'no') runOnActiveSheet(activeSheet, [newSize]); |
123 |
| -} |
124 |
| - |
125 |
| -function moveImage(dest = 'Khác') { |
126 |
| - const spreadSheet = SpreadsheetApp.getActiveSpreadsheet(); |
127 |
| - const destSheet = spreadSheet.getSheetByName(dest); |
128 |
| - |
129 |
| - const [activeSheet, activeRow, activeCol] = getActiveAddress(); |
130 |
| - if ( |
131 |
| - activeSheet.getName() === destSheet.getName() || |
132 |
| - activeSheet.getName() === 'Thống kê' || |
133 |
| - activeRow - 1 === 0 || |
134 |
| - activeCol > 3 |
135 |
| - ) |
136 |
| - return; |
137 |
| - |
138 |
| - const destLastRow = getLastRowByCol(destSheet, 2) + 1; |
139 |
| - const destRange = destSheet.getRange(destLastRow, 2, 1, 3); |
140 |
| - const srcRange = activeSheet.getRange(activeRow, 2, 1, 3); |
141 |
| - |
142 |
| - srcRange.copyTo(destRange); |
143 |
| - activeSheet.deleteRow(activeRow); |
144 |
| -} |
| 1 | +function onOpen() { |
| 2 | + const ui = SpreadsheetApp.getUi(); |
| 3 | + const menu = ui.createMenu('TOOLS BỔ TRỢ'); |
| 4 | + |
| 5 | + menu.addItem('Mở tool gán nhãn', 'loadLabelingForm'); |
| 6 | + menu.addSeparator(); |
| 7 | + |
| 8 | + menu.addItem('Sắp xếp sheets theo tên', 'sortSheets'); |
| 9 | + menu.addItem('Xóa urls trùng trong sheets', 'removeDuplicates'); |
| 10 | + // menu.addItem('Download urls trong sheets', 'downloadUrls'); |
| 11 | + menu.addItem('Đồng bộ sheets vào Google Drive', 'syncToDrive'); |
| 12 | + menu.addSeparator(); |
| 13 | + |
| 14 | + menu.addItem('Đặt kích thước ô chứa ảnh', 'setImageCellsSize'); |
| 15 | + menu.addItem('Move ảnh đang chọn qua nhãn Khác', 'moveImage'); |
| 16 | + menu.addToUi(); |
| 17 | +} |
| 18 | + |
| 19 | +function loadLabelingForm() { |
| 20 | + const service = HtmlService.createTemplateFromFile('index'); |
| 21 | + const html = service.evaluate().setTitle('TOOL GÁN NHÃN'); |
| 22 | + const ui = SpreadsheetApp.getUi(); |
| 23 | + ui.showSidebar(html); |
| 24 | +} |
| 25 | + |
| 26 | +function sortSheets() { |
| 27 | + const spreadSheet = SpreadsheetApp.getActiveSpreadsheet(); |
| 28 | + const sheets = spreadSheet.getSheets(); |
| 29 | + const sheetNameArray = []; |
| 30 | + |
| 31 | + for (let i = 0; i < sheets.length; i++) |
| 32 | + sheetNameArray.push(sheets[i].getName()); |
| 33 | + sheetNameArray.sort(); |
| 34 | + |
| 35 | + for (let j = 0; j < sheets.length; j++) { |
| 36 | + spreadSheet.setActiveSheet( |
| 37 | + spreadSheet.getSheetByName(sheetNameArray[j]) |
| 38 | + ); |
| 39 | + spreadSheet.moveActiveSheet(j + 1); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +function removeDuplicates() { |
| 44 | + const response = myMsgBox('Xóa urls trùng trong sheet'); |
| 45 | + if (response === 'yes') { |
| 46 | + runOnAllSheets(removeDuplicatesInSheet, []); |
| 47 | + Browser.msgBox( |
| 48 | + 'Xóa urls trùng trong sheet', |
| 49 | + 'Đã xóa urls trùng của tất cả sheets', |
| 50 | + Browser.Buttons.OK |
| 51 | + ); |
| 52 | + } else if (response === 'no') { |
| 53 | + const result = runOnActiveSheet(removeDuplicatesInSheet, []); |
| 54 | + Browser.msgBox( |
| 55 | + 'Xóa urls trùng trong sheet', |
| 56 | + `Số ảnh còn lại hiện tại: ${result} ảnh`, |
| 57 | + Browser.Buttons.OK |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +function downloadUrls() { |
| 63 | + const response = myMsgBox('Download urls'); |
| 64 | + const sourceFolder = DriveApp.getFoldersByName('Vietnamese Foods').next(); |
| 65 | + const urlsFolder = sourceFolder.getFoldersByName('Image Urls').next(); |
| 66 | + |
| 67 | + if (response === 'yes') { |
| 68 | + runOnAllSheets(downloadUrlsInSheet, [urlsFolder]); |
| 69 | + Browser.msgBox( |
| 70 | + 'Download thành công', |
| 71 | + 'Đã lưu urls của tất cả sheets vào Google Drive', |
| 72 | + Browser.Buttons.OK |
| 73 | + ); |
| 74 | + } else if (response === 'no') { |
| 75 | + const result = runOnActiveSheet(downloadUrlsInSheet, [urlsFolder]); |
| 76 | + Browser.msgBox( |
| 77 | + 'Download thành công', |
| 78 | + `Đã lưu ${result} urls vào Google Drive`, |
| 79 | + Browser.Buttons.OK |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +function syncToDrive() { |
| 85 | + const response = myMsgBox('Đồng bộ vào Google Drive'); |
| 86 | + const sourceFolder = DriveApp.getFoldersByName('Vietnamese Foods').next(); |
| 87 | + const datasetFolder = sourceFolder.getFoldersByName('Dataset').next(); |
| 88 | + const urlsFolder = sourceFolder.getFoldersByName('Image Urls').next(); |
| 89 | + |
| 90 | + if (response === 'yes') { |
| 91 | + runOnAllSheets(syncToDriveInSheet, [datasetFolder, urlsFolder]); |
| 92 | + Browser.msgBox( |
| 93 | + 'Đồng bộ thành công', |
| 94 | + 'Đã đồng bộ hình ảnh kèm urls của tất cả sheets vào Google Drive', |
| 95 | + Browser.Buttons.OK |
| 96 | + ); |
| 97 | + } else if (response === 'no') { |
| 98 | + const result = runOnActiveSheet(syncToDriveInSheet, [ |
| 99 | + datasetFolder, |
| 100 | + urlsFolder, |
| 101 | + ]); |
| 102 | + Browser.msgBox( |
| 103 | + 'Đồng bộ thành công', |
| 104 | + `Đã đồng bộ ${result} hình ảnh kèm urls vào Google Drive`, |
| 105 | + Browser.Buttons.OK |
| 106 | + ); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +function setImageCellsSize() { |
| 111 | + const newSize = SpreadsheetApp.getUi() |
| 112 | + .prompt( |
| 113 | + 'Chọn kích thước cho ô chứa ảnh', |
| 114 | + 'Nhập kích thước mới theo định dạng (height,width) - Mặc định: 200,350', |
| 115 | + SpreadsheetApp.getUi().ButtonSet.OK |
| 116 | + ) |
| 117 | + .getResponseText() |
| 118 | + .split(','); |
| 119 | + |
| 120 | + const response = myMsgBox('Đặt kích thước ô chứa ảnh'); |
| 121 | + if (response === 'yes') runOnAllSheets(setImageCellsSizeInSheet, [newSize]); |
| 122 | + else if (response === 'no') runOnActiveSheet(activeSheet, [newSize]); |
| 123 | +} |
| 124 | + |
| 125 | +function moveImage(dest = 'Khác') { |
| 126 | + const spreadSheet = SpreadsheetApp.getActiveSpreadsheet(); |
| 127 | + const destSheet = spreadSheet.getSheetByName(dest); |
| 128 | + |
| 129 | + const [activeSheet, activeRow, activeCol] = getActiveAddress(); |
| 130 | + if ( |
| 131 | + activeSheet.getName() === destSheet.getName() || |
| 132 | + activeSheet.getName() === 'Thống kê' || |
| 133 | + activeRow - 1 === 0 || |
| 134 | + activeCol > 3 |
| 135 | + ) |
| 136 | + return; |
| 137 | + |
| 138 | + const destLastRow = getLastRowByCol(destSheet, 2) + 1; |
| 139 | + const destRange = destSheet.getRange(destLastRow, 2, 1, 3); |
| 140 | + const srcRange = activeSheet.getRange(activeRow, 2, 1, 3); |
| 141 | + |
| 142 | + srcRange.copyTo(destRange); |
| 143 | + activeSheet.deleteRow(activeRow); |
| 144 | +} |
0 commit comments