Diferencia entre revisiones de «Usuario:ManuelRomero/PHP/excell»
De WikiEducator
< Usuario:ManuelRomero | PHP
(Página creada con «===Crear cabeceras con un fichero excell=== header(“Content-Type: application/vnd.ms-excel”); header(“Content-Disposition: attachment; filename=”$filename””);») |
(→Usando el recurso phpspreadseet) |
||
| (6 revisiones intermedias por el mismo usuario no mostrado) | |||
| Línea 3: | Línea 3: | ||
header(“Content-Disposition: attachment; filename=”$filename””); | header(“Content-Disposition: attachment; filename=”$filename””); | ||
| + | ===Usando el recurso phpspreadseet === | ||
| + | *https://github.com/PHPOffice/PhpSpreadsheet | ||
| + | *https://phpspreadsheet.readthedocs.io/en/develop/ | ||
| + | *https://phpoffice.github.io/PhpSpreadsheet/master/ | ||
| + | *https://stackoverflow.com/questions/tagged/phpspreadsheet | ||
| + | *https://gitter.im/PHPOffice/PhpSpreadsheet | ||
| + | https://www.htmlgoodies.com/beyond/exploring-phpspreadsheets-formatting-capabilities.html | ||
| + | ====Para leer un fichero xls==== | ||
| + | *Debemos cargar el fichero | ||
| + | <br /> | ||
| + | {{MRM_Actividad|Title=Acciones a realizar| | ||
| + | *Abro el fichero con '''''IOFactory::load(...)''''' | ||
| + | }} | ||
| + | <br /> | ||
| + | |||
| + | ;Clase <span style=color:red;font-size:1.5em>IOFactory </span> | ||
| + | ;método <span style=color:red;font-size:1.5em>load</span> | ||
| + | |||
| + | <source lang=php> | ||
| + | <?php | ||
| + | /**Quiero abrir un fichero ubuciado en ficheros/origen.xsl | ||
| + | Lo quiero abrir para leer de él | ||
| + | */ | ||
| + | //cargo la librería contando que tengo el autoload de vendor | ||
| + | use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
| + | $fichero = "./ficheros/origen.xls" | ||
| + | $sheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($fichero); | ||
| + | ... | ||
| + | ?> | ||
| + | </source> | ||
| + | ;Contar cuantas filas y columnas tiene | ||
| + | <source lang=php> | ||
| + | //Obtener cuantas filas y cuantas columnas tiene el fichero | ||
| + | $filas = $worksheet->getHighestRow(); // e.g. 10 | ||
| + | $columnas = $worksheet->getHighestColumn(); // e.g 'F' | ||
| + | </source> | ||
Última revisión de 14:24 18 nov 2018
Crear cabeceras con un fichero excell
header(“Content-Type: application/vnd.ms-excel”);
header(“Content-Disposition: attachment; filename=”$filename””);
Usando el recurso phpspreadseet
- https://github.com/PHPOffice/PhpSpreadsheet
- https://phpspreadsheet.readthedocs.io/en/develop/
- https://phpoffice.github.io/PhpSpreadsheet/master/
- https://stackoverflow.com/questions/tagged/phpspreadsheet
- https://gitter.im/PHPOffice/PhpSpreadsheet
https://www.htmlgoodies.com/beyond/exploring-phpspreadsheets-formatting-capabilities.html
Para leer un fichero xls
- Debemos cargar el fichero
- Clase IOFactory
- método load
<?php /**Quiero abrir un fichero ubuciado en ficheros/origen.xsl Lo quiero abrir para leer de él */ //cargo la librería contando que tengo el autoload de vendor use PhpOffice\PhpSpreadsheet\Spreadsheet; $fichero = "./ficheros/origen.xls" $sheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($fichero); ... ?>
- Contar cuantas filas y columnas tiene
//Obtener cuantas filas y cuantas columnas tiene el fichero $filas = $worksheet->getHighestRow(); // e.g. 10 $columnas = $worksheet->getHighestColumn(); // e.g 'F'