Guest User

merge

a guest
Dec 7th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. const CONFIG = {
  2. // MASTER FILE (Source)
  3. sourceFileId: '1ZL8IRF_vxdkidAPGncncFod5FdAhlNJ4R8Jh5FUhe5Y',
  4. sourceSheet: 'Special and Rare Items',
  5.  
  6. // LOCAL SHEET (Destination)
  7. targetSheet: 'Copy of Special and Rare Items',
  8.  
  9. // Range
  10. range: 'A1:K40'
  11. };
  12.  
  13. function onOpen() {
  14. SpreadsheetApp.getUi()
  15. .createMenu('📥 Import Progress')
  16. .addItem('📥 Import Checkboxes from Master', 'importFromMaster')
  17. .addItem('ℹ️ Instructions', 'showInstructions')
  18. .addToUi();
  19. }
  20.  
  21. function importFromMaster() {
  22. const ui = SpreadsheetApp.getUi();
  23.  
  24. const response = ui.alert(
  25. '📥 Import Mode Selection',
  26. 'Choose import mode:\n\n' +
  27. '• YES = MERGE (keep your checks + add new ones)\n' +
  28. '• NO = OVERWRITE (replace everything with master)\n' +
  29. '• CANCEL = Cancel import\n\n' +
  30. 'Recommended: YES (MERGE)',
  31. ui.ButtonSet.YES_NO_CANCEL
  32. );
  33.  
  34. if (response === ui.Button.CANCEL) {
  35. return;
  36. }
  37.  
  38. const mergeMode = (response === ui.Button.YES);
  39.  
  40. try {
  41. // Source file (το master)
  42. const sourceFile = SpreadsheetApp.openById(CONFIG.sourceFileId);
  43. const sourceSheet = sourceFile.getSheetByName(CONFIG.sourceSheet);
  44.  
  45. if (!sourceSheet) {
  46. ui.alert('❌ Error: Source sheet "' + CONFIG.sourceSheet + '" not found!');
  47. return;
  48. }
  49.  
  50. // Target file (το δικό σου)
  51. const targetFile = SpreadsheetApp.getActiveSpreadsheet();
  52. const targetSheet = targetFile.getSheetByName(CONFIG.targetSheet);
  53.  
  54. if (!targetSheet) {
  55. ui.alert('❌ Error: Target sheet "' + CONFIG.targetSheet + '" not found!');
  56. return;
  57. }
  58.  
  59. const sourceData = sourceSheet.getRange(CONFIG.range).getValues();
  60.  
  61. const targetData = targetSheet.getRange(CONFIG.range).getValues();
  62.  
  63. const updates = [];
  64. let importedCount = 0;
  65. let checkedCount = 0;
  66. let mergedCount = 0;
  67.  
  68. for (let row = 0; row < sourceData.length; row++) {
  69. for (let col = 0; col < sourceData[row].length; col++) {
  70. const sourceValue = sourceData[row][col];
  71. const targetValue = targetData[row][col];
  72.  
  73. if (sourceValue === true || sourceValue === false) {
  74. let finalValue;
  75.  
  76. if (mergeMode) {
  77. // MERGE MODE
  78. finalValue = (sourceValue === true || targetValue === true);
  79.  
  80. if (finalValue === true && targetValue === true && sourceValue === false) {
  81. mergedCount++; // Κράτησε το δικό σου check
  82. }
  83. } else {
  84. // OVERWRITE MODE
  85. finalValue = sourceValue;
  86. }
  87.  
  88. updates.push({
  89. row: row + 1,
  90. col: col + 1,
  91. value: finalValue
  92. });
  93.  
  94. importedCount++;
  95. if (finalValue === true) {
  96. checkedCount++;
  97. }
  98. }
  99. }
  100. }
  101.  
  102. updates.forEach(update => {
  103. try {
  104. targetSheet.getRange(update.row, update.col).setValue(update.value);
  105. } catch (e) {
  106. Logger.log('Failed at ' + update.row + ',' + update.col + ': ' + e.message);
  107. }
  108. });
  109.  
  110. let message = 'Mode: ' + (mergeMode ? 'MERGE ✅' : 'OVERWRITE ⚠️') + '\n\n' +
  111. 'Total checkboxes: ' + importedCount + '\n' +
  112. 'Checked items: ' + checkedCount + '\n';
  113.  
  114. if (mergeMode && mergedCount > 0) {
  115. message += 'Your checks preserved: ' + mergedCount + ' ✅';
  116. }
  117.  
  118. ui.alert('✅ Import Successful!', message, ui.ButtonSet.OK);
  119.  
  120. } catch (error) {
  121. ui.alert('❌ Import Failed!\n\n' + error.message);
  122. Logger.log('Import error: ' + error.message);
  123. }
  124. }
  125.  
  126. function showInstructions() {
  127. const html = HtmlService.createHtmlOutput(`
  128. <style>
  129. body {
  130. font-family: Arial, sans-serif;
  131. padding: 20px;
  132. line-height: 1.6;
  133. }
  134. h2 { color: #1a73e8; }
  135. .step {
  136. background: #e8f0fe;
  137. padding: 15px;
  138. margin: 10px 0;
  139. border-radius: 4px;
  140. border-left: 4px solid #1a73e8;
  141. }
  142. .warning {
  143. background: #fef7e0;
  144. border-left: 4px solid #f9ab00;
  145. padding: 15px;
  146. margin: 10px 0;
  147. }
  148. .mode {
  149. background: #e8f5e9;
  150. border-left: 4px solid #4caf50;
  151. padding: 15px;
  152. margin: 10px 0;
  153. }
  154. </style>
  155.  
  156. <h2>📥 How to Import Your Progress</h2>
  157.  
  158. <div class="step">
  159. <strong>Step 1:</strong> Click: 📥 Import Progress → Import Checkboxes from Master
  160. </div>
  161.  
  162. <div class="step">
  163. <strong>Step 2:</strong> Choose mode:<br>
  164. • <strong>MERGE</strong> = Keep your checks + add new ones ✅<br>
  165. • <strong>OVERWRITE</strong> = Replace with master file
  166. </div>
  167.  
  168. <div class="step">
  169. <strong>Step 3:</strong> Wait for confirmation
  170. </div>
  171.  
  172. <div class="mode">
  173. <strong>🎯 MERGE Mode (Recommended):</strong><br>
  174. • Keeps all YOUR checked items<br>
  175. • Adds NEW checked items from master<br>
  176. • Never loses your progress!
  177. </div>
  178.  
  179. <div class="warning">
  180. <strong>⚠️ OVERWRITE Mode:</strong><br>
  181. • Replaces ALL checkboxes with master<br>
  182. • Your progress will be LOST<br>
  183. • Use only if you want a fresh start
  184. </div>
  185. `).setWidth(550).setHeight(500);
  186.  
  187. SpreadsheetApp.getUi().showModalDialog(html, 'ℹ️ Instructions');
  188. }
Advertisement
Add Comment
Please, Sign In to add comment