user3472430
user3472430

Reputation: 11

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

Upvotes: 1

Views: 7043

Answers (3)

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

Upvotes: 1

blue
blue

Reputation: 1949

What you're looking for is PHPExcel.

Here are some examples.

Upvotes: 1

Ananth
Ananth

Reputation: 1550

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/

Upvotes: 1

Related Questions