bon ba c pa mal
This commit is contained in:
parent
e9e2d9949a
commit
8092f2e183
51
index.html
51
index.html
@ -413,7 +413,58 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jspdf@2.5.1/dist/jspdf.umd.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
async function exportPDF() {
|
||||
const gridEl = document.querySelector('.grid-container');
|
||||
|
||||
const canvas = await html2canvas(gridEl, {
|
||||
scale: 2,
|
||||
backgroundColor: '#ffffff'
|
||||
});
|
||||
|
||||
const imgData = canvas.toDataURL('image/png');
|
||||
const { jsPDF } = window.jspdf;
|
||||
|
||||
const pdf = new jsPDF({
|
||||
orientation: 'portrait',
|
||||
unit: 'px',
|
||||
format: [canvas.width, canvas.height]
|
||||
});
|
||||
|
||||
pdf.addImage(imgData, 'PNG', 0, 0);
|
||||
pdf.save('mots-fleches.pdf');
|
||||
}
|
||||
|
||||
function exportSpreadsheet(type) {
|
||||
const data = grid.map(row =>
|
||||
row.map(cell => {
|
||||
if (cell.type === 'letter') return cell.letter || '';
|
||||
return (cell.definitionH || '') + (cell.definitionV ? ' / ' + cell.definitionV : '');
|
||||
})
|
||||
);
|
||||
|
||||
const ws = XLSX.utils.aoa_to_sheet(data);
|
||||
const wb = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'Grille');
|
||||
|
||||
XLSX.writeFile(wb, `mots-fleches.${type}`, { bookType: type });
|
||||
}
|
||||
|
||||
function handleExport(value) {
|
||||
if (!value) return;
|
||||
|
||||
if (value === 'pdf') exportPDF();
|
||||
if (value === 'xlsx') exportSpreadsheet('xlsx');
|
||||
if (value === 'ods') exportSpreadsheet('ods');
|
||||
|
||||
document.getElementById('exportSelect').value = '';
|
||||
}
|
||||
|
||||
// État de l'application
|
||||
let grid = [];
|
||||
let activeCell = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user