Trasformare un foglio Excel in codice PHP permette di integrare dati tabellari in pagine web dinamiche. Il percorso standard: Excel → HTML → PHP. Non esiste conversione diretta "intelligente" (logica, formule → PHP), solo rappresentazione tabellare.
Conversione in 2 step
Step 1: Excel → HTML (tabella statica)
Opzione A: Excel nativo (nessun tool extra)
- Apri .xlsx in Excel → File → Salva con nome → Tipo: "Pagina Web (.htm; .html)".
- Scegli: "Foglio di lavoro selezionato" o "Cartella di lavoro intera".
- Opzioni: "Supporto completo per funzionalità" → Pubblica.
- Genera .htm + cartella _files (immagini, CSS, JS). Codice HTML verboso (tag
<table>con stili inline, XML namespaces Office).
Opzione B: Tool online (Tableizer, CSV to HTML, ConvertCSV)
- Incolla dati Excel (copia celle → incolla in tool) → genera HTML pulito
<table><tr><td>.... - Tableizer.journalistopia.com (semplice, CSS inline).
- ConvertCSV.com → CSV to HTML Table (opzioni classi CSS, ID, responsive).
Opzione C: Programmatico (Python/pandas, Node.js, PHP)
- Python:
pip install pandas openpyxl→df = pd.read_excel('file.xlsx'); print(df.to_html(classes='table table-striped', index=False)). - PHP:
composer require phpoffice/phpspreadsheet→ leggi .xlsx → itera righe → echo HTML.
Step 2: HTML → PHP (incorpora in script)
Metodo semplice: Include statico
<?php
// table.php
$htmlTable = '<table><tr><th>Nome</th><th>Valore</th></tr><tr><td>A</td><td>1</td></tr></table>';
?>
<!DOCTYPE html>
<html><head><title>Dati Excel</title></head><body>
<h1>Report</h1>
<?= $htmlTable ?>
</body></html>
Metodo dinamico: Genera HTML da array/dati
<?php
$data = [
['Nome' => 'Prodotto A', 'Prezzo' => 19.99, 'Stock' => 100],
['Nome' => 'Prodotto B', 'Prezzo' => 29.99, 'Stock' => 50],
];
?>
<table class="table">
<thead><tr><?php foreach($data[0] as $k => $v): ?><th><?=$k?></th><?php endforeach; ?></tr></thead>
<tbody>
<?php foreach($data as $row): ?>
<tr><?php foreach($row as $v): ?><td><?=$v?></td><?php endforeach; ?></tr>
<?php endforeach; ?>
</tbody>
</table>
Limiti fondamentali:
- Niente formule/logica: Excel `=SOMMA(A1:A10)` diventa testo statico "150" in HTML/PHP. Per logica, serve ricrearla in PHP/JS/SQL.
- Niente formattazione condizionale, grafici, pivot, macro VBA.
- Dati grandi: HTML/PHP in memoria per tabelle >10k righe → timeout/memory limit. Usa paginazione, DataTables.js, AJAX, CSV download.
Alternative moderne per "Excel sul web":
- Handsontable / HyperFormula (JS spreadsheet engine, supporta formule Excel-like).
- SheetJS (xlsx.js) leggi/scrivi .xlsx in browser/Node.
- Google Sheets API / Excel Online API (live sync, collaborazione).
- Power BI / Tableau / Metabase per dashboard da dati Excel.
Tool necessari
- Excel → HTML: Excel, o tool online, o script Python/PHP
- Editor PHP/HTML (VS Code, PhpStorm)
- Server PHP (XAMPP, Laragon, Docker, VPS)
Windows 2016
- Accedere a NAS Seagate da iPad: app, protocolli e configurazione
- Come nascondere l'immagine automatica nei post audio su Tumblr
- Come ripristinare i file di sistema System32 in Windows 7
- Fixare Windows Movie Maker che si chiude inaspettatamente
- Creare un opuscolo (brochure) in Word 2007 usando i modelli
- Creare un programma turni di gruppo in Microsoft Access
- Perché explorer.exe è sempre in esecuzione in Windows
- Convertire PDF in grafica vettoriale con Adobe Illustrator