开发者

How do i parse an Excel file with embeded images into a php array

I have an excel spreadsheet with images which i need to upload to a db. How do i parse th开发者_StackOverflow中文版e spreadsheet into an array?


http://code.google.com/p/php-excel-reader/ should be able to handle most of what you need.


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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜