输入格式
输出格式
分隔符:
包含表头
转义特殊字符
JSON缩进:
📥 输入数据
📂 拖拽文件到此处
📤 转换结果
行数: 0 列数: 0
就绪
) .replace(/#/g, '\\#') .replace(/_/g, '\\_') .replace(/\{/g, '\\{') .replace(/\}/g, '\\}') .replace(/~/g, '\\textasciitilde{}') .replace(/\^/g, '\\textasciicircum{}'); } function generateHTML(data) { const lines = [ '', ' ', ' ' + data.headers.map(h => ``).join('') + '', ' ', ' ' ]; data.data.forEach(row => { lines.push(' ' + data.headers.map(h => ``).join('') + ''); }); lines.push(' ', '
${escapeHTML(h)}
${escapeHTML(row[h])}
'); return lines.join('\n'); } function escapeHTML(text) { if (typeof text !== 'string') text = String(text); const div = document.createElement('div'); div.textContent = text; return div.innerHTML; } // Utility functions function swapFormats() { const input = document.getElementById('inputFormat'); const output = document.getElementById('outputFormat'); const temp = input.value; input.value = output.value; output.value = temp; convert(); } function clearInput() { document.getElementById('inputData').value = ''; document.getElementById('outputData').value = ''; updateStats(); } function loadExample() { const example = `姓名,年龄,数学成绩,编程成绩 张三,20,85,78 李四,21,92,88 王五,19,78,92 赵六,22,88,85 钱七,20,95,90`; document.getElementById('inputData').value = example; document.getElementById('inputFormat').value = 'csv'; updateStats(); convert(); } function loadFile(event) { const file = event.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = e => { document.getElementById('inputData').value = e.target.result; // Auto-detect format const ext = file.name.split('.').pop().toLowerCase(); const formatMap = {csv: 'csv', tsv: 'tsv', json: 'json', md: 'markdown', tex: 'latex', html: 'html', txt: 'csv'}; if (formatMap[ext]) { document.getElementById('inputFormat').value = formatMap[ext]; } updateStats(); convert(); showToast(`已加载: ${file.name}`); }; reader.readAsText(file); } function copyOutput() { const text = document.getElementById('outputData').value; if (!text) { showToast('没有可复制的内容'); return; } if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(text) .then(() => showToast('已复制到剪贴板')) .catch(() => { // fallback const ta = document.getElementById('outputData'); ta.select(); document.execCommand('copy'); showToast('已复制到剪贴板'); }); } else { const ta = document.getElementById('outputData'); ta.select(); document.execCommand('copy'); showToast('已复制到剪贴板'); } } function downloadOutput() { const output = document.getElementById('outputData').value; if (!output) { showToast('没有可下载的内容'); return; } const format = document.getElementById('outputFormat').value; const extMap = {csv: 'csv', tsv: 'tsv', json: 'json', markdown: 'md', latex: 'tex', html: 'html'}; const ext = extMap[format] || 'txt'; const blob = new Blob([output], {type: 'text/plain'}); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `converted.${ext}`; a.click(); URL.revokeObjectURL(url); showToast('下载已开始'); } function updateStats() { const input = document.getElementById('inputData').value.trim(); if (!input) { document.getElementById('rowCount').textContent = '0'; document.getElementById('colCount').textContent = '0'; return; } const lines = input.split('\n').filter(l => l.trim()); const firstLine = lines[0] || ''; const colCount = firstLine.split(document.getElementById('delimiter').value).length; document.getElementById('rowCount').textContent = lines.length; document.getElementById('colCount').textContent = colCount; } function showStatus(text, isError = false) { const status = document.getElementById('statusText'); status.textContent = text; status.style.color = isError ? 'var(--rust)' : 'var(--ink3)'; } function showToast(message) { const toast = document.getElementById('toast'); toast.textContent = message; toast.classList.add('show'); setTimeout(() => toast.classList.remove('show'), 2000); } // Drag and drop const dropzone = document.getElementById('dropzone'); const inputTextarea = document.getElementById('inputData'); inputTextarea.addEventListener('dragover', e => { e.preventDefault(); dropzone.classList.add('active'); }); inputTextarea.addEventListener('dragleave', () => { dropzone.classList.remove('active'); }); inputTextarea.addEventListener('drop', e => { e.preventDefault(); dropzone.classList.remove('active'); const files = e.dataTransfer.files; if (files.length > 0) { const file = files[0]; const reader = new FileReader(); reader.onload = event => { document.getElementById('inputData').value = event.target.result; updateStats(); convert(); showToast(`已加载: ${file.name}`); }; reader.readAsText(file); } }); // Initialize loadExample(); ___I18N_PROTECTED_2___ ___I18N_PROTECTED_3___