File size: 17,386 Bytes
aa3adfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Spreadsheet</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .cell:focus {
            outline: 2px solid #3b82f6;
            z-index: 10;
        }
        .selected {
            background-color: #bfdbfe;
        }
        .col-header, .row-header {
            background-color: #f3f4f6;
            font-weight: 500;
            text-align: center;
            user-select: none;
        }
        .col-header {
            border-bottom: 1px solid #d1d5db;
        }
        .row-header {
            border-right: 1px solid #d1d5db;
        }
        .toolbar-button.active {
            background-color: #e5e7eb;
        }
    </style>
</head>
<body class="bg-gray-50">
    <div class="container mx-auto p-4 max-w-6xl">
        <div class="bg-white rounded-lg shadow-md overflow-hidden">
            <!-- Toolbar -->
            <div class="bg-gray-100 p-2 border-b border-gray-200 flex flex-wrap gap-2">
                <div class="flex items-center space-x-1">
                    <button id="bold-btn" class="toolbar-button p-2 rounded hover:bg-gray-200" title="Bold">
                        <i class="fas fa-bold"></i>
                    </button>
                    <button id="italic-btn" class="toolbar-button p-2 rounded hover:bg-gray-200" title="Italic">
                        <i class="fas fa-italic"></i>
                    </button>
                    <button id="underline-btn" class="toolbar-button p-2 rounded hover:bg-gray-200" title="Underline">
                        <i class="fas fa-underline"></i>
                    </button>
                </div>
                <div class="flex items-center space-x-1">
                    <button id="align-left-btn" class="toolbar-button p-2 rounded hover:bg-gray-200" title="Align Left">
                        <i class="fas fa-align-left"></i>
                    </button>
                    <button id="align-center-btn" class="toolbar-button p-2 rounded hover:bg-gray-200" title="Align Center">
                        <i class="fas fa-align-center"></i>
                    </button>
                    <button id="align-right-btn" class="toolbar-button p-2 rounded hover:bg-gray-200" title="Align Right">
                        <i class="fas fa-align-right"></i>
                    </button>
                </div>
                <div class="flex items-center space-x-1">
                    <select id="font-family" class="p-2 border rounded text-sm">
                        <option value="Arial">Arial</option>
                        <option value="Courier New">Courier New</option>
                        <option value="Georgia">Georgia</option>
                        <option value="Times New Roman">Times New Roman</option>
                        <option value="Verdana">Verdana</option>
                    </select>
                    <select id="font-size" class="p-2 border rounded text-sm">
                        <option value="10">10</option>
                        <option value="12" selected>12</option>
                        <option value="14">14</option>
                        <option value="16">16</option>
                        <option value="18">18</option>
                        <option value="20">20</option>
                    </select>
                </div>
                <div class="flex items-center space-x-1">
                    <input type="color" id="text-color" class="w-8 h-8" value="#000000" title="Text Color">
                    <input type="color" id="bg-color" class="w-8 h-8" value="#ffffff" title="Background Color">
                </div>
                <div class="flex items-center space-x-1 ml-auto">
                    <button id="clear-btn" class="p-2 bg-red-100 text-red-700 rounded hover:bg-red-200 text-sm">
                        Clear
                    </button>
                </div>
            </div>

            <!-- Spreadsheet -->
            <div class="overflow-auto max-h-[70vh]">
                <table id="spreadsheet" class="border-collapse w-full">
                    <thead>
                        <tr>
                            <th class="w-10 h-10 border col-header"></th>
                            <!-- Column headers (A, B, C, ...) -->
                            <script>
                                document.write(
                                    Array.from({ length: 26 }, (_, i) => 
                                        `<th class="w-24 h-10 border col-header">${String.fromCharCode(65 + i)}</th>`
                                    ).join('')
                                );
                            </script>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- Rows with row headers (1, 2, 3, ...) and cells -->
                        <script>
                            document.write(
                                Array.from({ length: 50 }, (_, row) => {
                                    return `
                                        <tr>
                                            <td class="w-10 h-8 border row-header">${row + 1}</td>
                                            ${Array.from({ length: 26 }, (_, col) => 
                                                `<td class="border">
                                                    <div 
                                                        id="cell-${String.fromCharCode(65 + col)}${row + 1}" 
                                                        class="cell w-full h-8 p-1 overflow-hidden whitespace-nowrap" 
                                                        contenteditable="true"
                                                        data-row="${row + 1}"
                                                        data-col="${String.fromCharCode(65 + col)}"
                                                    ></div>
                                                </td>`
                                            ).join('')}
                                        </tr>
                                    `;
                                }).join('')
                            );
                        </script>
                    </tbody>
                </table>
            </div>

            <!-- Status bar -->
            <div class="bg-gray-100 p-2 border-t border-gray-200 text-sm text-gray-600 flex justify-between">
                <div id="selected-cell">A1</div>
                <div id="cell-formula"></div>
                <div id="zoom-level">100%</div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const spreadsheet = document.getElementById('spreadsheet');
            const cells = document.querySelectorAll('.cell');
            const selectedCellDisplay = document.getElementById('selected-cell');
            const cellFormulaDisplay = document.getElementById('cell-formula');
            let activeCell = null;

            // Initialize cells with empty data
            cells.forEach(cell => {
                cell.dataset.value = '';
                cell.dataset.formula = '';
                cell.dataset.bold = 'false';
                cell.dataset.italic = 'false';
                cell.dataset.underline = 'false';
                cell.dataset.align = 'left';
                cell.dataset.fontFamily = 'Arial';
                cell.dataset.fontSize = '12';
                cell.dataset.textColor = '#000000';
                cell.dataset.bgColor = '#ffffff';
            });

            // Cell selection
            cells.forEach(cell => {
                cell.addEventListener('click', function() {
                    // Remove selection from all cells
                    cells.forEach(c => c.classList.remove('selected'));
                    
                    // Select current cell
                    this.classList.add('selected');
                    activeCell = this;
                    
                    // Update status bar
                    const col = this.dataset.col;
                    const row = this.dataset.row;
                    selectedCellDisplay.textContent = `${col}${row}`;
                    cellFormulaDisplay.textContent = this.dataset.formula ? `=${this.dataset.formula}` : '';
                    
                    // Update toolbar to reflect cell formatting
                    updateToolbar(this);
                });

                cell.addEventListener('input', function() {
                    this.dataset.value = this.textContent;
                });

                cell.addEventListener('keydown', function(e) {
                    if (e.key === 'Enter') {
                        e.preventDefault();
                        moveToAdjacentCell(this, 'down');
                    } else if (e.key === 'Tab') {
                        e.preventDefault();
                        moveToAdjacentCell(this, e.shiftKey ? 'left' : 'right');
                    }
                });
            });

            // Move to adjacent cell
            function moveToAdjacentCell(currentCell, direction) {
                const col = currentCell.dataset.col;
                const row = parseInt(currentCell.dataset.row);
                let nextCellId = '';
                
                if (direction === 'right') {
                    const nextCol = String.fromCharCode(col.charCodeAt(0) + 1);
                    if (nextCol <= 'Z') {
                        nextCellId = `cell-${nextCol}${row}`;
                    }
                } else if (direction === 'left') {
                    const prevCol = String.fromCharCode(col.charCodeAt(0) - 1);
                    if (prevCol >= 'A') {
                        nextCellId = `cell-${prevCol}${row}`;
                    }
                } else if (direction === 'up' && row > 1) {
                    nextCellId = `cell-${col}${row - 1}`;
                } else if (direction === 'down' && row < 50) {
                    nextCellId = `cell-${col}${row + 1}`;
                }
                
                if (nextCellId) {
                    const nextCell = document.getElementById(nextCellId);
                    nextCell.focus();
                    nextCell.click();
                }
            }

            // Update toolbar buttons based on cell formatting
            function updateToolbar(cell) {
                document.getElementById('bold-btn').classList.toggle('active', cell.dataset.bold === 'true');
                document.getElementById('italic-btn').classList.toggle('active', cell.dataset.italic === 'true');
                document.getElementById('underline-btn').classList.toggle('active', cell.dataset.underline === 'true');
                
                const alignButtons = ['align-left-btn', 'align-center-btn', 'align-right-btn'];
                alignButtons.forEach(btn => document.getElementById(btn).classList.remove('active'));
                document.getElementById(`align-${cell.dataset.align}-btn`).classList.add('active');
                
                document.getElementById('font-family').value = cell.dataset.fontFamily;
                document.getElementById('font-size').value = cell.dataset.fontSize;
                document.getElementById('text-color').value = cell.dataset.textColor;
                document.getElementById('bg-color').value = cell.dataset.bgColor;
            }

            // Apply formatting to active cell
            function applyFormatting(property, value) {
                if (activeCell) {
                    activeCell.dataset[property] = value;
                    updateCellStyle(activeCell);
                }
            }

            // Update cell style based on data attributes
            function updateCellStyle(cell) {
                cell.style.fontWeight = cell.dataset.bold === 'true' ? 'bold' : 'normal';
                cell.style.fontStyle = cell.dataset.italic === 'true' ? 'italic' : 'normal';
                cell.style.textDecoration = cell.dataset.underline === 'true' ? 'underline' : 'none';
                cell.style.textAlign = cell.dataset.align;
                cell.style.fontFamily = cell.dataset.fontFamily;
                cell.style.fontSize = `${cell.dataset.fontSize}px`;
                cell.style.color = cell.dataset.textColor;
                cell.style.backgroundColor = cell.dataset.bgColor;
            }

            // Toolbar event listeners
            document.getElementById('bold-btn').addEventListener('click', () => {
                if (activeCell) {
                    const newValue = activeCell.dataset.bold === 'true' ? 'false' : 'true';
                    applyFormatting('bold', newValue);
                    document.getElementById('bold-btn').classList.toggle('active');
                }
            });

            document.getElementById('italic-btn').addEventListener('click', () => {
                if (activeCell) {
                    const newValue = activeCell.dataset.italic === 'true' ? 'false' : 'true';
                    applyFormatting('italic', newValue);
                    document.getElementById('italic-btn').classList.toggle('active');
                }
            });

            document.getElementById('underline-btn').addEventListener('click', () => {
                if (activeCell) {
                    const newValue = activeCell.dataset.underline === 'true' ? 'false' : 'true';
                    applyFormatting('underline', newValue);
                    document.getElementById('underline-btn').classList.toggle('active');
                }
            });

            document.getElementById('align-left-btn').addEventListener('click', () => {
                applyFormatting('align', 'left');
                document.querySelectorAll('.align-btn').forEach(btn => btn.classList.remove('active'));
                document.getElementById('align-left-btn').classList.add('active');
            });

            document.getElementById('align-center-btn').addEventListener('click', () => {
                applyFormatting('align', 'center');
                document.querySelectorAll('.align-btn').forEach(btn => btn.classList.remove('active'));
                document.getElementById('align-center-btn').classList.add('active');
            });

            document.getElementById('align-right-btn').addEventListener('click', () => {
                applyFormatting('align', 'right');
                document.querySelectorAll('.align-btn').forEach(btn => btn.classList.remove('active'));
                document.getElementById('align-right-btn').classList.add('active');
            });

            document.getElementById('font-family').addEventListener('change', (e) => {
                applyFormatting('fontFamily', e.target.value);
            });

            document.getElementById('font-size').addEventListener('change', (e) => {
                applyFormatting('fontSize', e.target.value);
            });

            document.getElementById('text-color').addEventListener('input', (e) => {
                applyFormatting('textColor', e.target.value);
            });

            document.getElementById('bg-color').addEventListener('input', (e) => {
                applyFormatting('bgColor', e.target.value);
            });

            document.getElementById('clear-btn').addEventListener('click', () => {
                if (activeCell) {
                    activeCell.textContent = '';
                    activeCell.dataset.value = '';
                    activeCell.dataset.formula = '';
                    activeCell.dataset.bold = 'false';
                    activeCell.dataset.italic = 'false';
                    activeCell.dataset.underline = 'false';
                    activeCell.dataset.align = 'left';
                    activeCell.dataset.fontFamily = 'Arial';
                    activeCell.dataset.fontSize = '12';
                    activeCell.dataset.textColor = '#000000';
                    activeCell.dataset.bgColor = '#ffffff';
                    updateCellStyle(activeCell);
                    updateToolbar(activeCell);
                }
            });

            // Select first cell by default
            document.getElementById('cell-A1').click();
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=ipepe/simplespreadsheet" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>