Differenze tra le versioni di "Libreria PHPExcel"
(Creata pagina con "← ritorno a PHP Category:PHP Category:PHPExcel == Creazione file XLSX ==// xlsx <pre> $xls = new PHPExcel( ); ... $xlsWriter = new \PHPExcel_Wri...") |
(→Operazioni) |
||
| (5 versioni intermedie di uno stesso utente non sono mostrate) | |||
| Riga 1: | Riga 1: | ||
[[GENERALE#PHP|← ritorno a PHP]] [[Category:PHP]] [[Category:PHPExcel]] | [[GENERALE#PHP|← ritorno a PHP]] [[Category:PHP]] [[Category:PHPExcel]] | ||
| − | == Creazione file XLSX == | + | == Creazione file XLSX == |
<pre> | <pre> | ||
$xls = new PHPExcel( ); | $xls = new PHPExcel( ); | ||
| Riga 7: | Riga 7: | ||
$xlsWriter = new \PHPExcel_Writer_Excel2007( $xls ); | $xlsWriter = new \PHPExcel_Writer_Excel2007( $xls ); | ||
$xlsWriter->save( $filepath ); | $xlsWriter->save( $filepath ); | ||
| + | </pre> | ||
| + | |||
| + | == Formattazione == | ||
| + | * [[Formattazione cella PHPExcel]] | ||
| + | |||
| + | == Operazioni == | ||
| + | * [[Operazioni su più celle PHPExcel]] | ||
| + | * [[Unioni di più celle PHPExcel]] | ||
| + | |||
| + | == Fogli e dimensioni == | ||
| + | Dimensioni del primo foglio: | ||
| + | $foglio = $excel->getSheet( 0 ); | ||
| + | $highestRow = $foglio->getHighestRow(); | ||
| + | $highestColumn = $foglio->getHighestColumn(); | ||
| + | |||
| + | Numero di colonne: | ||
| + | $colNumber = \PHPExcel_Cell::columnIndexFromString( $sheet->getHighestColumn() ); | ||
| + | |||
| + | == Importazione e lettura di un file excel == | ||
| + | <pre> | ||
| + | // leggo il file | ||
| + | $excel = null; | ||
| + | try { | ||
| + | $inputFileType = \PHPExcel_IOFactory::identify( $filepath ); | ||
| + | $objReader = \PHPExcel_IOFactory::createReader( $inputFileType ); | ||
| + | $excel = $objReader->load( $filepath ); | ||
| + | } catch(Exception $e) { | ||
| + | echo 'Errore nel leggere il file come foglio di calcolo elettronico: '.$e->getMessage(); | ||
| + | return false; | ||
| + | } | ||
</pre> | </pre> | ||
Versione attuale delle 15:30, 16 feb 2024
Indice
Creazione file XLSX
$xls = new PHPExcel( ); ... $xlsWriter = new \PHPExcel_Writer_Excel2007( $xls ); $xlsWriter->save( $filepath );
Formattazione
Operazioni
Fogli e dimensioni
Dimensioni del primo foglio:
$foglio = $excel->getSheet( 0 ); $highestRow = $foglio->getHighestRow(); $highestColumn = $foglio->getHighestColumn();
Numero di colonne:
$colNumber = \PHPExcel_Cell::columnIndexFromString( $sheet->getHighestColumn() );
Importazione e lettura di un file excel
// leggo il file
$excel = null;
try {
$inputFileType = \PHPExcel_IOFactory::identify( $filepath );
$objReader = \PHPExcel_IOFactory::createReader( $inputFileType );
$excel = $objReader->load( $filepath );
} catch(Exception $e) {
echo 'Errore nel leggere il file come foglio di calcolo elettronico: '.$e->getMessage();
return false;
}