Location: PHPKode > projects > Opensheet > opensheet/functions/export.xls.php
<?php
#Add sessions
# Add overtime
if (isset($_GET['year'])  && isset($_GET['month']) ) {
$year = $_GET['year'];$month = $_GET['month'];

$last_day =  date( 't', mktime(01,01,01,$month,01,$year) );	

include ('base.functions.php');
include ('../classes/global.class.php');

$hours = new Stats;
#$hours->getPrjHoursPerMonthByUsers($year,$month);
$usersHours = $hours->getPrjHoursPerMonthByUsers($year,$month);
#echo "<pre>";
#print_r($usersHours);
require_once 'Spreadsheet/Excel/Writer.php';


$filename = 'timesheet.xls';
// Creating workbook
$workbook = new Spreadsheet_Excel_Writer();
// Setting workbook version 8
$workbook->setVersion(8);
// Sending headers to browser
$workbook->send('timesheet.xls');
// Adding worksheet
$worksheet =& $workbook->addWorksheet('company');
$format_right =& $workbook->addFormat();
$format_right->setAlign('right');
$format_center =& $workbook->addFormat();
$format_center->setAlign('center');
$format_left =& $workbook->addFormat();
$format_left->setAlign('left');
// Setting worksheet encoding to UTF-8
$worksheet->setInputEncoding('UTF-8');
$worksheet->setColumn(0,0,10);
$worksheet->setColumn(1,2,30);
$worksheet->setColumn(3,6,20);
// Data input

// Header of a tables

$worksheet->write(0, 0, 'дата',$format_center);
$worksheet->write(0, 1, 'сотрудник',$format_center);
$worksheet->write(0, 2, 'проект',$format_center);
$worksheet->write(0, 3, 'нормативное время',$format_center);
$worksheet->write(0, 4, 'сверхурочное время',$format_center);
$worksheet->write(0, 5, 'выходные',$format_center);

$users = new Users;
$projects = new Projects;



$s = 1;


foreach($usersHours as $uid=>$data){

	foreach ($data as $pid=>$value){
		foreach ($value as $proj_type=>$hours){

$worksheet->write($s, 0, $last_day.".".$month.".".$year,$format_left);
$worksheet->write($s, 1, $users->getRealName($uid),$format_left);
$worksheet->write($s, 2, $projects->getProjectName($pid),$format_left);
$worksheet->write($s, 3, $hours,$format_center);
$worksheet->write($s, 4, '0',$format_center);
$worksheet->write($s, 5, '0',$format_center);
$s++;

 	 }
 	}
}

// Sending the file
header("Content-Disposition: attachment; filename=timesheet.xls");
header("Content-Type: application/octet-stream");
header("Content-Length: размер файла");
$workbook->close();
}
?>
Return current item: Opensheet