1. Paste Data
Try an example:
Code copied to clipboard!
'); doc.close(); // Apply theme + fullwidth class on iframe body const themeTokens = themeClass.split(/\s+/).filter(Boolean); // themeTokens contains: excelx-etc__theme, theme-light/theme-dark/..., maybe table-full-width const themeName = themeTokens.find(t => t.startsWith("theme-")) || "theme-light"; doc.body.classList.add(themeName); if(elFullWidth.checked) doc.body.classList.add("table-full-width"); // Insert clone content doc.body.appendChild(clone); // Print after layout iframe.onload = () => {}; setTimeout(() => { iframe.contentWindow.focus(); iframe.contentWindow.print(); // Cleanup a bit later (some browsers need time) setTimeout(() => { iframe.remove(); }, 1000); }, 50); } // Events root.querySelectorAll(".excelx-etc__btn--example").forEach(b => { b.addEventListener("click", () => { const k = b.dataset.example; elInput.value = examples[k] || ""; if(parseInput()) render(); }); }); btnConvert.addEventListener("click", () => { if(parseInput()) render(); }); btnClear.addEventListener("click", () => { elInput.value = ""; elOutput.style.display = "none"; currentData = []; }); root.querySelectorAll(".excelx-etc__tab").forEach(t => { t.addEventListener("click", () => setFormat(t.dataset.format)); }); elThemeSel.addEventListener("change", () => { setTheme(); render(); }); elFullWidth.addEventListener("change", () => { setTheme(); render(); }); elHeader.addEventListener("change", () => { if(parseInput()) render(); }); elPretty.addEventListener("change", () => { if(parseInput()) render(); }); elAlign.addEventListener("change", () => { if(parseInput()) render(); }); btnCopy.addEventListener("click", async () => { const text = elCode.textContent || ""; try{ await navigator.clipboard.writeText(text); toast("Code copied to clipboard!"); }catch(e){ const ta = document.createElement("textarea"); ta.value = text; ta.style.position = "fixed"; ta.style.left = "-9999px"; document.body.appendChild(ta); ta.select(); document.execCommand("copy"); document.body.removeChild(ta); toast("Code copied!"); } }); // Export PDF (iframe method = no duplicates) btnPdf.addEventListener("click", exportPdfViaIframe); btnPng.addEventListener("click", async () => { try{ const html2canvas = await loadHtml2Canvas(); const target = root.querySelector("#excelx-etc-tablewrap"); const canvas = await html2canvas(target, { backgroundColor: null, scale: 2 }); const link = document.createElement("a"); link.download = "excel-table-export.png"; link.href = canvas.toDataURL("image/png"); link.click(); }catch(e){ toast("PNG export failed (blocked script or network)."); console.error(e); } }); // Auto convert while typing (debounced) let tmr = null; elInput.addEventListener("input", () => { window.clearTimeout(tmr); tmr = window.setTimeout(() => { if(parseInput()) render(); }, 250); }); // Init setTheme(); setFormat("md"); })();

Leave A Comment