Reputation: 4651
I have an excel spreadsheet with images which i need to upload to a db. How do i parse the spreadsheet into an array?
Upvotes: 0
Views: 1762
Reputation: 212452
I'd recommend PHPExcel for parsing Excel files (though I am biased, as one of the developers). You don't mention which version of Excel (xls or xlsx files), but PHPExcel can read either... and it can read the images.
Reading the Excel worksheet data into a PHP array can be as simple as:
$inputFileName = './sampleData/example1.xls';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray();
var_dump($sheetData);
EDIT
To extract images, use something like:
$objPHPExcel = PHPExcel_IOFactory::load("MyExcelFile.xls");
foreach ($objPHPExcel->getSheetByName("My Sheet")->getDrawingCollection() as $drawing) {
if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
ob_start();
call_user_func(
$drawing->getRenderingFunction(),
$drawing->getImageResource()
);
$imageContents = ob_get_contents();
ob_end_clean();
}
}
Upvotes: 1
Reputation: 360762
http://code.google.com/p/php-excel-reader/ should be able to handle most of what you need.
Upvotes: 1