简体   繁体   中英

How to Export data in Excel including images in php

i am exporting data from database (MySQL) in excel sheet. i also want to export images in Excel using PHP.if any demo link is available, please share it here

You have to use one of the followig library to do that.

URLS:

https://github.com/PHPOffice/PHPExcel

https://phpexcel.codeplex.com/

https://code.google.com/p/php-excel/

What you're looking for is PHPExcel .

Here are some examples .

This is how I solved mine. Hope this helps!

 public function export_items_to_excel(){ $items = $this->transaction->view_all_items(); $output = ''; $output .= "<table class='table' border='1'> <thead> <th style='background-color:#c7c7c7;'>NAME</th> <th style='background-color:#c7c7c7;'>DESCRIPTION</th> <th style='background-color:#c7c7c7;'>QUANTITY</th> <th style='background-color:#c7c7c7;'>WEIGHT (KG)</th> <th style='background-color:#c7c7c7;'>HS CODE</th> <th style='background-color:#c7c7c7;'>SERIAL NO.</th> <th style='background-color:#c7c7c7;'>UNIT VALUE</th> <th style='background-color:#c7c7c7;'>CURRENCY</th> <th style='width:220px !important;background-color:#c7c7c7;'>PICTURE</th> </thead> <tbody> "; foreach($items as $item){ $output .= " <tr> <td style='text-align:center;'>".$item->item_name."</td> <td style='text-align:center;'>".$item->item_description."</td> <td style='text-align:center;'>".$item->item_quantity."</td> <td style='text-align:center;'>".number_format($item->item_weight, 2)."</td> <td style='text-align:center;'>".$item->item_hs_code."</td> <td style='text-align:center;'>".$item->item_serial_number."</td> <td style='text-align:center;'>".number_format($item->item_unit_value, 2)."</td> <td style='text-align:center;'>".$item->item_currency."</td> <td style='text-align:center;width:220px !important;height:220px !important;'><img src='".base_url()."assets/uploads/".$item->item_picture."' style='width:200px !important;height:152px !important;'> </td> </tr> "; } $output .= "</tbody> </table> "; header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header("Content-Disposition: attachment; filename=items.xls"); header("Cache-Control: max-age=0"); echo $output; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM