I would like, in PHP, to open an existing XLS worksheet, insert data into columns, save and close the file.
Is there any function or API for this type of handling, which opens the file in BINARY_SAFE
and allows me this kind of manipulation?
I would like, in PHP, to open an existing XLS worksheet, insert data into columns, save and close the file.
Is there any function or API for this type of handling, which opens the file in BINARY_SAFE
and allows me this kind of manipulation?
With phpexcel you can load and manipulate the spreadsheet, for example a spreadsheet with two names and email columns, and the following lines:
1 - A B
2 - joão da silva [email protected]
3 - maria oliveira [email protected]
This code loads the clients.xls file, adds a new client, and saves the worksheet. This response was based on SOen
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');
include 'PHPExcel/IOFactory.php';
$fileType = 'Excel5';
$fileName = 'clientes.xls';
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objReader->load($fileName);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A4', 'jose');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B4', '[email protected]');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);
$objWriter->save($fileName);