Jump to content

How to generate the report in excel formet


anand.arjunan
 Share

Recommended Posts

Hi all The php out put file i want generate the excel format please tell me any idea
<?php if($_REQUEST[zip]==1){ $select = "SELECT order_id,od_date,contact_person,office_name,office_add,menu,zipcode FROM orders where order_date between '".$_REQUEST[acd]."' and '".$_REQUEST[end_acd]."' and type='Rep' order by zipcode"; $export = mysql_query($select); $fields = mysql_num_fields($export);}else{ $select = "SELECT order_id,od_date,contact_person,office_name,office_add,menu,zipcode FROM orders where order_date between '".$_REQUEST[acd]."' and '".$_REQUEST[end_acd]."' and type='Rep'"; $export = mysql_query($select); $fields = mysql_num_fields($export); }?><?php $header = 'Order No'. "\t";$header .= 'Order Date'. "\t";$header .= 'Contact Person'. "\t";$header .= 'Office Name'. "\t";$header .= 'Office Address'. "\t";$header .= 'Menu'. "\t";$header .= 'Zip code'. "\t"; /* for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t"; } */?> <?php while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); ?> <?php if ($data == "") { $data = "\n(0) Records Found!\n"; } ?><?php header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=Reporders.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; ?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...