Hi,
I'm creating a custom module and I want to create an excel file from backend button using custom array of data.
I had done this in magento 1.x using this block of code from controller action.
$xmlObj = new Varien_Convert_Parser_Xml_Excel(); $xmlObj->setVar('single_sheet', $filename); $xmlObj->setData($data); $xmlObj->unparse(); $content=$xmlObj->getData(); // Force Download $this->_prepareDownloadResponse($filename,$content);
Now need to create this feature in Magento 2.0
I'm thankful for any suggestion/solution/hint
How to generate an Excel file (speadsheet) in Magento 2? https://mage2.pro/t/823
Thanks a lot,
I have used like this in my controller and it working fine now.
$fileName = $filename; $convert = new \Magento\Framework\Convert\Excel(new \ArrayIterator($data)); $content = $convert->convert('single_sheet'); return $this->_fileFactory->create($fileName, $content);
Thanks again.