Working with PHP and Excel

Working with PHP and Excel

Introductions –

PHP got libraries through which we can create or access the excel data. There are two possible ways of creating or accessing the excel data in PHP

1) PHP – Excel library provided by PEAR.
2) PHP using Excel COM component functions and libraries.

** In PHP – Excel libraries, Spreadsheet_Excel_Reader is the class through which we can read the data from excel file. Online documentation is available on following url … http://pear.php.net/package/Spreadsheet_Excel_Reader

Spreadsheet_Excel_Writer is the class to write the data in a excel file. Online documentation is available on following url … http://pear.php.net/package/Spreadsheet_Excel_Writer

** Using Excel – COM components we can create, read the data from excel file easily. Here is
The small code which uses COM components to read the excel data….

<?php

$exlObj = new COM(“Excel.Application”) or Die (“Did not connect”);
$exlObj->Workbooks->Open(“test.xls”);
$exlBook = $exlObj->ActiveWorkBook;
$exlSheets = $exlBook->Sheets;
$exlSheet = $exlBook->WorkSheets(1);
echo $exlSheets->Count;
echo $sheetName = $exlSheet->Name;
$cell = $exlSheet->Cells(1, 1);
echo $cell->Value;

?>

Using both libraries writing excel with all formatting is available. And comparatively PHP-Excel COM components function provides a lot of functionalities to work with excel sheet on the fly.

I have tried to modify the existing excel sheet but it is not happened with both PEAR excel library and Excel COM libraries. I think it is not possible to modify the excel on the fly with out disturbing any color combinations. If any one got the solution looking for their comments….

Thank you,
Santhosh Tirunahari

Similar Posts:

Leave a Reply

Your email address will not be published.