PHP export excel with image PHP export excel with image codeigniter codeigniter

PHP export excel with image


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;}


Use FCPATH instead of using base_url();