开发者

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

开发者 https://www.devze.com 2023-02-19 21:50 出处:网络
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

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

精彩评论

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

关注公众号