Open Excel file in BINARY_SAFE

Asked

Viewed 616 times

1

I would like to open an existing XLS spreadsheet in PHP, insert data into columns, save and close the file.
Is there any function or API for this type of treatment, which opens the file in BINARY_SAFE and allow me that kind of manipulation?

  • There is the library phpexcel.

  • but phpexcel it creates the file and I just want to manipulate an existing one. or it manipulates too?

  • 1

    That’s the problem with not saying what you tried/researched: someone suggests something and you say "but this I already know/does not serve me because..."

1 answer

1


With phpexcel it is possible to load and manipulate the spreadsheet, taking as an example a sheet with two columns name and email, and the following lines:

1 -       A              B
2 - joão da silva   [email protected]
3 - maria oliveira  [email protected]

This code loads the.xls clients file, adds a new client and saves the spreadsheet. This response was based on the 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.