XLS Export

<?php
set_time_limit(0);
require_once(“../includes/connection.php”);
adminSecure();

function xlsBOF() {
echo pack(“ssssss”, 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
// Excel end of file footer
function xlsEOF() {
echo pack(“ss”, 0x0A, 0x00);
return;
}
// Function to write a Number (double) into Row, Col
function xlsWriteNumber($Row, $Col, $Value) {
echo pack(“sssss”, 0x203, 14, $Row, $Col, 0x0);
echo pack(“d”, $Value);
return;
}
// Function to write a label (text) into Row, Col
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack(“ssssss”, 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}

////////////////////////////////////////////////////////////

header(“Pragma: public”);
header(“Expires: 0”);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Content-Type: application/force-download”);
header(“Content-Type: application/octet-stream”);
header(“Content-Type: application/download”);;
header(“Content-Disposition: attachment;filename=product.xls”);
header(“Content-Transfer-Encoding: binary “);

xlsBOF();

$data_array = array(
“product_name”,
“brand_id”,
“style_id”,
“frame_id”,
“gender_id”,
“size_id”,
“eyesize_id”,
“bridgesize_id”,
“templelength_id”,
“option_color”,
“option_price”,
“product_url”,
“image_url”,
);

$header_array = array(
“Name”,
“Brand”,
“Style”,
“Frame”,
“Gender”,
“Size”,
“Eyesize”,
“Bridgesize”,
“Templelength”,
“Color”,
“Price”,
“Product Url”,
“Image Url”
);

foreach($header_array as $key => $value){
xlsWriteLabel(0,$key,$value);
}

$k = 2;

$res1 = $obj->selectData(TABLE_PRODUCT.” as p”,””,”p.product_id > 0 and p.product_status=’Active’ order by p.product_added desc”,””);
while($data1 = mysql_fetch_array($res1)){

$res2 = $obj->selectData(TABLE_PRODUCT_OPTION.” as po”,””,”po.option_status=’Active’ and po.product_id='”.$data1[‘product_id’].”‘”,””);
while($data2 = mysql_fetch_array($res2)){

$option_image = $obj->selectData(TABLE_PRODUCT_OPTION_IMAGE.” as poi”,””,”poi.image_status=’Active’ and poi.option_id='”.$data2[‘option_id’].”‘ and poi.option_extra_image<>” limit 1″,1);

$image_url = FURL.PRODUCT_IMAGES.$option_image[‘option_extra_image’];
$product_url = FURL.”products_detail.php?p_id=”.$data2[‘product_id’].”&o_id=”.$data2[‘option_id’].””;

foreach($data_array as $key => $value){
if($value == “product_name”){
xlsWriteLabel($k,$key,$data1[$value]);
} else if($value == “brand_id”){
xlsWriteLabel($k,$key,$obj->getBrandName($data1[$value]));
} else if($value == “style_id”){
xlsWriteLabel($k,$key,$obj->getProductStyle($data1[$value]));
} else if($value == “frame_id”){
xlsWriteLabel($k,$key,$obj->getFrameName($data1[$value]));
} else if($value == “gender_id”){
xlsWriteLabel($k,$key,$obj->getGenderName($data1[$value]));
} else if($value == “size_id”){
xlsWriteLabel($k,$key,$obj->getProductSize($data1[$value]));
} else if($value == “eyesize_id”){
xlsWriteLabel($k,$key,$obj->getProductEyeSize($data1[$value]));
} else if($value == “bridgesize_id”){
xlsWriteLabel($k,$key,$obj->getProductBridgeSize($data1[$value]));
} else if($value == “templelength_id”){
xlsWriteLabel($k,$key,$obj->getProductTempleLength($data1[$value]));
} else if($value == “product_url”){
xlsWriteLabel($k,$key,$product_url);
} else if($value == “image_url”){
xlsWriteLabel($k,$key,$image_url);
} else {
xlsWriteLabel($k,$key,$data2[$value]);
}
}
$k++;
}
}

xlsEOF();
/////////////////////////////////////////////////////

?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s