reading excel file in php tutorial write
Reading an Excel file in PHP (4)
I'm trying to read an Excel file (Office 2003). There is an Excel file that needs to be uploaded and its contents parsed.
Via Google, I can only find answers to these related (and insufficient topics): generating Excel files, reading Excel XML files, reading Excel CSV files, or incomplete abandoned projects. I own Office 2003 so if I need any files from there, they are available. It's installed on my box but isn't and can't be installed on my shared host.
I use PHP-ExcelReader to read xls files, and works great.
It depends on how you want to use the data in the excel file. If you want to import it into mysql, you could simply save it as a CSV formatted file and then use fgetcsv to parse it.
I have used following code to read "xls and xlsx"
<?php include 'excel_reader.php'; // include the class $excel = new PhpExcelReader; // creates object instance of the class $excel->read('excel_file.xls'); // reads and stores the excel file data // Test to see the excel data stored in $sheets property echo '<pre>'; var_export($excel->sheets); echo '</pre>'; or echo '<pre>'; print_r($excel->sheets); echo '</pre>';
You have 2 choice as far as I know:
- Spreadsheet_Excel_Reader, which knows the Office 2003 binary format
- PHPExcel, which knows both Office 2003 as well as Excel 2007 (XML).
PHPExcel uses Spreadsheet_Excel_Reader for the Office 2003 format.
Update: I once had to read some Excel files but I used the Office 2003 XML format in order to read them and told the people that were using the application to save and upload only that type of Excel file.