Sometimes it's really convenient to be able to open an excel spreadsheet up and grab the data - a common example is clients who can't use anything other than excel files (or refuse to use anything else like CSV).
If you're using PHP on Windows, you can use the inbuilt
COM library $excel = new COM("excel.application");$excel->Workbooks->Open("filename.xls");A solution I've found that works well on Linux machines, is
PHPExcelReader, and it seems to work very efficiently and easily with only a few lines of code.
$data = new Spreadsheet_Excel_Reader();$data->read("filename.xls");And you can access the data with a simple loop:
for($i=1; $i <= $data->sheets[0]['numRows']; $i++){
echo 'Row '. $i .', Column a:' $data->sheets[0]['cells'][$i][1] . '<br />';
echo 'Row '. $i .', Column b:' $data->sheets[0]['cells'][$i][2] . '<br />';
}
#1 Jeroen Mulder says:
What a coincidence! I actually need to write Excel spreadsheets with PHP somewhere this week. Thanks :-)