function exportexcel($newdate1,$newdate2){
// Connect database.
mysql_connect("localhost","root","admin");
mysql_select_db("project_2");
// Get data records from table.
$result=mysql_query(
"select projects.project_id,companies.company_name,projects.project_name,projects.project_target_budget,projects.project_start_date,projects.project_end_date, projects.project_actual_end_date,users.user_username
from projects , users ,companies
where projects.project_owner = users.user_id and projects.project_company = companies.company_id and projects.project_status ='2' and projects.project_actual_end_date between '$newdate1' and '$newdate2' order by projects.project_actual_end_date");
// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
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");
$strfilename = header("Content-Disposition: attachment;filename=project.xls ");
header("Content-Transfer-Encoding: binary ");
xlsBOF();
/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/
// Make column labels. (at line 1)
xlsWriteLabel(0,0,"Project ID");
xlsWriteLabel(0,1,"Project Company");
xlsWriteLabel(0,2,"Project Name");
xlsWriteLabel(0,3,"Budget");
xlsWriteLabel(0,4,"Start Date");
xlsWriteLabel(0,5,"End Date");
xlsWriteLabel(0,6,"Acutual Date");
xlsWriteLabel(0,7,"Owner");
//xlsWriteLabel(0,8,"Value");
$xlsRow = 1;
// Put data records from mysql by while loop.
while($row=mysql_fetch_array($result)){
xlsWriteLabel($xlsRow,0,$row['project_id']);
xlsWriteLabel($xlsRow,1,$row['company_name']);
xlsWriteLabel($xlsRow,2,$row['project_name']);
xlsWriteNumber($xlsRow,3,$row['project_target_budget']);
xlsWriteLabel($xlsRow,4,$row['project_start_date']);
xlsWriteLabel($xlsRow,5,$row['project_end_date']);
xlsWriteLabel($xlsRow,6,$row['project_actual_end_date']);
xlsWriteLabel($xlsRow,7,$row['user_username']);
//xlsWriteLabel($xlsRow,8,$row['value']);
$xlsRow++;
}
xlsEOF();
exit();
}