Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const CONFIG = {
- // MASTER FILE (Source)
- sourceFileId: '1ZL8IRF_vxdkidAPGncncFod5FdAhlNJ4R8Jh5FUhe5Y',
- sourceSheet: 'Special and Rare Items',
- // LOCAL SHEET (Destination)
- targetSheet: 'Copy of Special and Rare Items',
- // Range
- range: 'A1:K40'
- };
- function onOpen() {
- SpreadsheetApp.getUi()
- .createMenu('📥 Import Progress')
- .addItem('📥 Import Checkboxes from Master', 'importFromMaster')
- .addItem('ℹ️ Instructions', 'showInstructions')
- .addToUi();
- }
- function importFromMaster() {
- const ui = SpreadsheetApp.getUi();
- const response = ui.alert(
- '📥 Import Mode Selection',
- 'Choose import mode:\n\n' +
- '• YES = MERGE (keep your checks + add new ones)\n' +
- '• NO = OVERWRITE (replace everything with master)\n' +
- '• CANCEL = Cancel import\n\n' +
- 'Recommended: YES (MERGE)',
- ui.ButtonSet.YES_NO_CANCEL
- );
- if (response === ui.Button.CANCEL) {
- return;
- }
- const mergeMode = (response === ui.Button.YES);
- try {
- // Source file (το master)
- const sourceFile = SpreadsheetApp.openById(CONFIG.sourceFileId);
- const sourceSheet = sourceFile.getSheetByName(CONFIG.sourceSheet);
- if (!sourceSheet) {
- ui.alert('❌ Error: Source sheet "' + CONFIG.sourceSheet + '" not found!');
- return;
- }
- // Target file (το δικό σου)
- const targetFile = SpreadsheetApp.getActiveSpreadsheet();
- const targetSheet = targetFile.getSheetByName(CONFIG.targetSheet);
- if (!targetSheet) {
- ui.alert('❌ Error: Target sheet "' + CONFIG.targetSheet + '" not found!');
- return;
- }
- const sourceData = sourceSheet.getRange(CONFIG.range).getValues();
- const targetData = targetSheet.getRange(CONFIG.range).getValues();
- const updates = [];
- let importedCount = 0;
- let checkedCount = 0;
- let mergedCount = 0;
- for (let row = 0; row < sourceData.length; row++) {
- for (let col = 0; col < sourceData[row].length; col++) {
- const sourceValue = sourceData[row][col];
- const targetValue = targetData[row][col];
- if (sourceValue === true || sourceValue === false) {
- let finalValue;
- if (mergeMode) {
- // MERGE MODE
- finalValue = (sourceValue === true || targetValue === true);
- if (finalValue === true && targetValue === true && sourceValue === false) {
- mergedCount++; // Κράτησε το δικό σου check
- }
- } else {
- // OVERWRITE MODE
- finalValue = sourceValue;
- }
- updates.push({
- row: row + 1,
- col: col + 1,
- value: finalValue
- });
- importedCount++;
- if (finalValue === true) {
- checkedCount++;
- }
- }
- }
- }
- updates.forEach(update => {
- try {
- targetSheet.getRange(update.row, update.col).setValue(update.value);
- } catch (e) {
- Logger.log('Failed at ' + update.row + ',' + update.col + ': ' + e.message);
- }
- });
- let message = 'Mode: ' + (mergeMode ? 'MERGE ✅' : 'OVERWRITE ⚠️') + '\n\n' +
- 'Total checkboxes: ' + importedCount + '\n' +
- 'Checked items: ' + checkedCount + '\n';
- if (mergeMode && mergedCount > 0) {
- message += 'Your checks preserved: ' + mergedCount + ' ✅';
- }
- ui.alert('✅ Import Successful!', message, ui.ButtonSet.OK);
- } catch (error) {
- ui.alert('❌ Import Failed!\n\n' + error.message);
- Logger.log('Import error: ' + error.message);
- }
- }
- function showInstructions() {
- const html = HtmlService.createHtmlOutput(`
- <style>
- body {
- font-family: Arial, sans-serif;
- padding: 20px;
- line-height: 1.6;
- }
- h2 { color: #1a73e8; }
- .step {
- background: #e8f0fe;
- padding: 15px;
- margin: 10px 0;
- border-radius: 4px;
- border-left: 4px solid #1a73e8;
- }
- .warning {
- background: #fef7e0;
- border-left: 4px solid #f9ab00;
- padding: 15px;
- margin: 10px 0;
- }
- .mode {
- background: #e8f5e9;
- border-left: 4px solid #4caf50;
- padding: 15px;
- margin: 10px 0;
- }
- </style>
- <h2>📥 How to Import Your Progress</h2>
- <div class="step">
- <strong>Step 1:</strong> Click: 📥 Import Progress → Import Checkboxes from Master
- </div>
- <div class="step">
- <strong>Step 2:</strong> Choose mode:<br>
- • <strong>MERGE</strong> = Keep your checks + add new ones ✅<br>
- • <strong>OVERWRITE</strong> = Replace with master file
- </div>
- <div class="step">
- <strong>Step 3:</strong> Wait for confirmation
- </div>
- <div class="mode">
- <strong>🎯 MERGE Mode (Recommended):</strong><br>
- • Keeps all YOUR checked items<br>
- • Adds NEW checked items from master<br>
- • Never loses your progress!
- </div>
- <div class="warning">
- <strong>⚠️ OVERWRITE Mode:</strong><br>
- • Replaces ALL checkboxes with master<br>
- • Your progress will be LOST<br>
- • Use only if you want a fresh start
- </div>
- `).setWidth(550).setHeight(500);
- SpreadsheetApp.getUi().showModalDialog(html, 'ℹ️ Instructions');
- }
Advertisement
Add Comment
Please, Sign In to add comment