0

I currently have a .xlsx file with a workbook with multiple sheets with text and images.

I need to import this data into my MySQL database.

Does anyone know of any tutorials or just some code that can help me get all the sheet within the workbook and retrieve text and images, and insert them into the database.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jed
  • 929
  • 2
  • 19
  • 32
  • http://stackoverflow.com/questions/9695695/how-to-use-phpexcel-to-read-data-and-insert-into-database/9697745#9697745 – Mark Baker Feb 12 '13 at 07:23

2 Answers2

1

Check out PHPExcel. Here's how you would loop through the sheets. I'm not sure how you can get images though.

$reader = new PHPExcel_Reader_Excel2007();
$excel = $reader->load($filename);

foreach ($excel->getWorksheetIterator() as $worksheet){
    // Get the data from current worksheet
    // and store in DB as you like
}
luttkens
  • 1,272
  • 8
  • 16
0
$reader = new PHPExcel_Reader_Excel2007();
 $PHPExcel = $reader->load('test.xlsx');
 $worksheet = $PHPExcel->getActiveSheet();

 // extract images from worksheet and save files:  0.jpeg, 1.jpeg, 2.png, ...
 foreach ($worksheet->getDrawingCollection() as $i => $drawing) {
     $filename = $drawing->getPath();
     $imagesize = getimagesize($filename);

     switch ($imagesize[2]) {

     case 1:
         $image = imagecreatefromgif($filename);
         imagegif($image, "$i.gif");
         break;

     case 2:
         $image = imagecreatefromjpeg($filename);
         imagejpeg($image, "$i.jpeg");
         break;

     case 3:
         $image = imagecreatefrompng($filename);
         imagepng($image, "$i.png");
         break;

     default:
         continue 2;

     }
 }
Mark Baker
  • 209,507
  • 32
  • 346
  • 385