Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to Excel #79

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public function getClickable()
return array();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
<update handle="adminhtml_adminhtml_customreport_viewtable"/>
</adminhtml_adminhtml_customreport_exportcsv>

<adminhtml_adminhtml_customreport_exportexcel>
<update handle="adminhtml_adminhtml_customreport_viewtable"/>
</adminhtml_adminhtml_customreport_exportexcel>

</layout>