Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Check to ensure this file is included in Joomla!
- defined('_JEXEC') or die();
- //
- // view.xls.php code and view.xlsx.php code.
- // See Also: http://pastebin.com/jptfwmxw (Joomla PhpExcel layout working example)
- // see also http://pastebin.com/TfKq8NZ4 (xlsx.php for joomla and PhpExcel)
- // see also http://pastebin.com/kM9wtd1c (xls.php for joomla and PhpExcel)
- // Import PHPExcel library
- jimport('phpexcel.library.PHPExcel');
- //Import needed Joomla classes
- jimport('joomla.application.component.view');
- jimport('joomla.utilities.date');
- jimport('joomla.filesystem.file');
- class Cn_reportsViewRetailpartnersalesbypartners extends JViewLegacy
- {
- /**
- * Class Constructor
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * To display the page
- * @param string $tpl template to use
- */
- public function display($tpl = null)
- {
- global $mainframe;
- // Get the user requesting this view
- $params = JComponentHelper::getParams('com_cn_reports');
- $user = JFactory::getUser();
- $utz = $user->getParam('timezone');
- $unow = JFactory::getDate('now', $utz);
- $model = $this->getModel();
- // Get the date properties from the current model state
- $startDate = $model->getTzStartDate(); // get the start date as JDate
- $endDate = $model->getTzEndDate(); // get the end date as JDate
- $rname = $model->getRetailPartnerName(); // et the retail partner name from the model
- // $ruserid =$model->getRetailPartnerId();
- // Get and set the document properties
- $document = JFactory::getDocument();
- $date = new JDate();
- $download_desc = JText::sprintf('COM_CN_REPORTS_VIEW_RETAILPARTNERSALESBYPARTNERS_XLS_DOWNLOAD_DESC', JText::_('COM_CN_REPORTS_VIEW_RETAILPARTNERSALESBYPARTNERS_XLS_COMMISSIONS_TITLE'), $user->name, $date->format('%Y-%m-%d'), $user->name);
- $document->setDescription($download_desc);
- $download_title = JText::sprintf('COM_CN_REPORTS_VIEW_RETAILPARTNERSALESBYPARTNERS_XLS_DOWNLOAD_TITLE',
- $rname, $startDate->format('Y-m-d'), $endDate->format('Y-m-d'));
- $document->setName($download_title);
- $document->setTitle($download_title);
- //Get the PHPExcel object to set some properties
- $objPhpExcel =& $document->getPhpExcelObj();
- $objPhpExcel->getProperties()->setCreator($user->name)->setLastModifiedBy($user->name);
- $objPhpExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C' . $download_desc);
- $objPhpExcel->getActiveSheet()->setTitle(JText::_('COM_CN_REPORTS_VIEW_RETAILPARTNERSALESBYPARTNERS_XLS_COMMISSIONS_TITLE'));
- //$myWorkSheet = new PHPExcel_Worksheet($objPhpExcel, JText::_('COM_CN_REPORTS_VIEW_RETAILPARTNERSALESBYPARTNERS_XLS_OVERRIDES_TITLE'));
- // Attach the “My Data” worksheet as the first worksheet in the PHPExcel object
- //$objPhpExcel->addSheet($myWorkSheet, 1);
- $objPhpExcel->setActiveSheetIndex(0);
- // Assign the data from the model to the view template - getData(false) in this model gets all rows
- // ignoring pagination otherwise getData would return only the current data page on the screen
- // $this->assignRef('rows', $this->getModel()->getData(false));
- $items = $model->getItems();
- $cn_reports_export_xls_show_grid = $params->get('cn_reports_export_xls_show_grid');
- $cn_reports_export_xls_logo = $params->get('cn_reports_export_xls_logo');
- $cn_reports_export_xls_title = $params->get('cn_reports_export_xls_title');
- $cn_reports_export_xls_header = $params->get('cn_reports_export_xls_header');
- $cn_reports_export_xls_footer = $params->get('cn_reports_export_xls_footer');
- $cn_reports_export_xls_rowColumnTitleBgColor = $params->get('cn_reports_export_xls_rowcolumntitlebgcolor');
- $cn_reports_export_xls_rowColumnTitleBgColor = str_ireplace('#', '', $cn_reports_export_xls_rowColumnTitleBgColor);
- $cn_reports_export_xls_rowcolumntitlefontcolor = $params->get('cn_reports_export_xls_rowcolumntitlefontcolor');
- $cn_reports_export_xls_rowcolumntitlefontcolor = str_ireplace('#', '', $cn_reports_export_xls_rowcolumntitlefontcolor);
- $cn_reports_export_xls_rowRptTitleFontcolor = $params->get('cn_reports_export_xls_rowrpttitlefontcolor');
- $cn_reports_export_xls_rowRptTitleFontcolor = str_ireplace('#', '', $cn_reports_export_xls_rowRptTitleFontcolor);
- $cn_reports_export_xls_rowColumnHeaderBgColor = $params->get('cn_reports_export_xls_rowcolumnheaderbgcolor');
- $cn_reports_export_xls_rowColumnHeaderBgColor = str_ireplace('#', '', $cn_reports_export_xls_rowColumnHeaderBgColor);
- $cn_reports_export_xls_rowColumnHeaderFontcolor = $params->get('cn_reports_export_xls_rowcolumnheaderfontcolor');
- $cn_reports_export_xls_rowColumnHeaderFontcolor = str_ireplace('#', '', $cn_reports_export_xls_rowColumnHeaderFontcolor);
- $cn_reports_export_xls_rowcolumnfooterfontcolor = $params->get('cn_reports_export_xls_rowcolumnfooterfontcolor');
- $cn_reports_export_xls_rowcolumnfooterfontcolor = str_ireplace('#', '', $cn_reports_export_xls_rowcolumnfooterfontcolor);
- $cn_reports_export_xls_rowcolumnfooterbgcolor = $params->get('cn_reports_export_xls_rowcolumnfooterbgcolor');
- $cn_reports_export_xls_rowcolumnfooterbgcolor = str_ireplace('#', '', $cn_reports_export_xls_rowcolumnfooterbgcolor);
- $cn_reports_export_xls_rowaltbgcolor = $params->get('cn_reports_export_xls_rowaltbgcolor');
- $cn_reports_export_xls_rowaltbgcolor = str_ireplace('#', '', $cn_reports_export_xls_rowaltbgcolor);
- $cn_reports_export_xls_rowaltfontcolor = $params->get('cn_reports_export_xls_rowaltfontcolor');
- $cn_reports_export_xls_rowaltfontcolor = str_ireplace('#', '', $cn_reports_export_xls_rowaltfontcolor);
- $this->assignRef('rows', $items);
- $this->assignRef('reportStart', $startDate);
- $this->assignRef('reportEnd', $endDate);
- $this->assignRef('partnerName', $rname);
- //Assign the PHPExcel object for use in the template
- $this->assignRef('phpexcel', $objPhpExcel);
- $this->assignRef('showGrid', $cn_reports_export_xls_show_grid);
- $this->assignRef('showLogo', $cn_reports_export_xls_logo);
- $this->assignRef('showTitle', $cn_reports_export_xls_title);
- $this->assignRef('showHeader', $cn_reports_export_xls_header);
- $this->assignRef('showFooter', $cn_reports_export_xls_footer);
- $this->assignRef('rowColumnTitleBgColor', $cn_reports_export_xls_rowColumnTitleBgColor);
- $this->assignRef('rowColumnTitleFontColor', $cn_reports_export_xls_rowcolumntitlefontcolor);
- $this->assignRef('rowRptTitleFontcolor', $cn_reports_export_xls_rowRptTitleFontcolor);
- $this->assignRef('rowColumnHeaderBgColor', $cn_reports_export_xls_rowColumnHeaderBgColor);
- $this->assignRef('rowColumnHeaderFontColor', $cn_reports_export_xls_rowColumnHeaderFontcolor);
- $this->assignRef('rowcolumnfooterfontcolor', $cn_reports_export_xls_rowcolumnfooterfontcolor);
- $this->assignRef('rowcolumnfooterbgcolor', $cn_reports_export_xls_rowcolumnfooterbgcolor);
- $this->assignRef('altRowaltBgColor', $cn_reports_export_xls_rowaltbgcolor);
- $this->assignRef('rowAltFontColor', $cn_reports_export_xls_rowaltfontcolor);
- // I use the 'excel' template in the <View Folder Name>/tmpl folder for a variety of document types to
- // provide consistency between those document types (xls, xlsx, cvs, pdf) generated by PHPExcel but you
- // could use 'xls' here if you preferred instead to create a specific XLS template.
- $jinput = JFactory::getApplication()->input;
- $layout = $jinput->get('layout', 'excel', 'CMD');
- if(is_null($tpl)) $tpl = $layout;
- //Display the results
- parent::display($tpl);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement