Open Excel file in BINARY_SAFE

1

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?

    
asked by anonymous 03.04.2014 / 22:10

1 answer

1

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);
    
03.04.2014 / 23:15