Hi All,
I am trying to export my data to Excel in binery xls format
for this i am using below helper file.
<?php
/**
* This xls helper is based on the one at
* http://bakery.cakephp.org/articles/view/excel-xls-helper
*
* The difference compared with the original one is this helper
* actually creates an xml which is openable in Microsoft Excel.
*
* Written by Yuen Ying Kit @ ykyuen.wordpress.com
*
*/
class XlsHelper extends AppHelper {
/**
* set the header of the http response.
*
* @param unknown_type $filename
*/
function setHeader($filename) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Content-Type: application/force-download");
header("Content-Type: application/download");;
header("Content-Disposition: inline; filename=\"".$filename.".xls\"");
}
/**
* add the xml header for the .xls file.
*
*/
function addXmlHeader() {
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "\n";
return;
}
/**
* add the worksheet name for the .xls.
* it has to be added otherwise the xml format is incomplete.
*
* @param unknown_type $workSheetName
*/
function setWorkSheetName($workSheetName) {
echo "\n";
echo "\n";
return;
}
/**
* add the footer to the end of xml.
* it has to be added otherwise the xml format is incomplete.
*
*/
function addXmlFooter() {
echo "\t\n";
echo "\t\n";
echo "\n";
return;
}
/**
* move to the next row in the .xls.
* must be used with closeRow() in pair.
*
*/
function openRow() {
echo "\t";
return;
}
/**
* end the row in the .xls.
* must be used with openRow() in pair.
*
*/
function closeRow() {
echo "\t\n";
return;
}
/**
* Write the content of a cell in number format
*
* @param unknown_type $Value
*/
function writeNumber($Value) {
if (is_null($Value)) {
echo "\t ";
} else {
echo "\t".$Value;
}
return;
}
/**
* Write the content of a cell in string format
*
* @param unknown_type $Value
*/
function writeString($Value) {
echo "\t".$Value;
return;
}
}
?>
and in my view file i am using my xls helper file function and exporting it ti excel
<?php
$xls->setHeader('Model_'.date('Y_m_d'));
$xls->openRow();
$xls->writeString('Store Availability');
$xls->closeRow();
$xls->openRow();
$xls->closeRow();
$xls->openRow();
$xls->writeString($strDate);
$xls->writeString('-TO-');
$xls->writeString($endDate);
$xls->closeRow();
$xls->openRow();
$xls->closeRow();
$xls->openRow();
$xls->closeRow();
foreach($subCategories as $subCategories){
$subCategoryId = $subCategories['SubCategory']['sub_category_id'];
$xls->openRow();
$xls->writeString($subCategories['SubCategory']['sub_category']);
$xls->closeRow();
$xls->openRow();
$xls->closeRow();
$xls->openRow();
$xls->writeString('Store Type');
//$xls->writeLabel('Store Type');
$xls->writeString('Branch Code');
$xls->writeString('Branch Name');
$xls->writeString('Dates Booked');
$xls->writeString('Dates Available');
$xls->closeRow();
$availability = $availability1[$subCategoryId];
foreach($availability as $storeId => $store){
$xls->openRow();
$bookedDates = implode(',', $store['booked_dates']) ;
$availableDates = implode(',', $store['available_dates']) ;
$xls->writeString($store['st']['store_type']);
$xls->writeString($store['s']['branch_code']);
$xls->writeString($store['s']['store_name']);
$xls->writeString($bookedDates);
$xls->writeString($availableDates);
$xls->closeRow();
}
$xls->openRow();
$xls->closeRow();
}
$xls->addXmlFooter();
exit();
?>
and also i am attaching my resultent .xls file also please find it.
Problem:
1.How to give background color for cell.
2.How to give font color and font size of text.
3.How to split the cell.
Tell me it is able to get my reqirements using this helper file and how?
Thanks
rakesh
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Thursday, January 27, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment