diff --git a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php index 2752d34..7a621a4 100755 --- a/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php +++ b/app/code/community/Clean/SqlReports/Block/Adminhtml/Customreport/View/Grid.php @@ -12,6 +12,7 @@ public function __construct() $this->setDefaultDir('ASC'); $this->setSaveParametersInSession(true); $this->addExportType('*/*/exportCsv', $this->__('CSV')); + $this->addExportType('*/*/exportExcel', $this->__('Excel')); } protected function _prepareLayout() diff --git a/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php b/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php index 27d11c1..a7f8111 100644 --- a/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php +++ b/app/code/community/Clean/SqlReports/Model/Report/GridConfig.php @@ -40,4 +40,4 @@ public function getClickable() return array(); } -} \ No newline at end of file +} diff --git a/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php b/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php index 7b40c39..afc4a71 100755 --- a/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php +++ b/app/code/community/Clean/SqlReports/controllers/Adminhtml/CustomreportController.php @@ -114,6 +114,31 @@ public function exportCsvAction() ); } + /** + * Export grid to Excel format + */ + public function exportExcelAction() + { + Mage::register('current_report', $this->_getReport()); + $this->loadLayout(); + + /** @var $grid Mage_Adminhtml_Block_Widget_Grid */ + $grid = $this->getLayout()->getBlock('report.view.grid'); + + if(!$grid instanceof Mage_Adminhtml_Block_Widget_Grid) { + $this->_forward('noroute'); + return; + } + + $fileName = strtolower(str_replace(' ', '_', $this->_getReport()->getTitle())) . '_' . time() . '.xls'; + $content = $grid->getExcel($fileName); + + $this->_prepareDownloadResponse( + $fileName, + $content + ); + } + /** * Get JSON action * @@ -156,7 +181,7 @@ protected function _getReport() protected function _isAllowed() { - $isView = in_array($this->getRequest()->getActionName(), array('index', 'view', 'viewtable', 'viewchart', 'getJson', 'exportCsv')); + $isView = in_array($this->getRequest()->getActionName(), array('index', 'view', 'viewtable', 'viewchart', 'getJson', 'exportCsv', 'exportExcel')); /** @var $helper Clean_SqlReport_Helper_Data */ $helper = Mage::helper('cleansql'); diff --git a/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml b/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml index 7d56787..e501576 100644 --- a/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml +++ b/app/design/adminhtml/default/default/layout/clean_sqlreports/cleansql.xml @@ -59,5 +59,9 @@ + + + +