public function getExcelFile($sheetName = '') { $this->_isExport = true; $this->_prepareGrid(); $this->_columns['referer']->setData('renderer', 'affiliateplusstatistic/report_renderer_referer'); $this->_columns['url_path']->setData('renderer', 'affiliateplusstatistic/report_renderer_path'); $parser = new Varien_Convert_Parser_Xml_Excel(); $io = new Varien_Io_File(); $path = Mage::getBaseDir('var') . DS . 'export' . DS; $name = md5(microtime()); $file = $path . DS . $name . '.xml'; $io->setAllowCreateFolders(true); $io->open(array('path' => $path)); $io->streamOpen($file, 'w+'); $io->streamLock(true); $io->streamWrite($parser->getHeaderXml($sheetName)); $io->streamWrite($parser->getRowXml($this->_getExportHeaders())); $this->_exportIterateCollection('_exportExcelItem', array($io, $parser)); if ($this->getCountTotals()) { $io->streamWrite($parser->getRowXml($this->_getExportTotals())); } $io->streamWrite($parser->getFooterXml()); $io->streamUnlock(); $io->streamClose(); return array('type' => 'filename', 'value' => $file, 'rm' => true); }
public function getExcel($data = array(), $filename = '') { $excelData = array(); if (array_key_exists('headers', $data)) { $excelData[] = $data['headers']; } if (array_key_exists('items', $data)) { foreach ($data['items'] as $item) { $excelData[] = $item; } } if (array_key_exists('totals', $data)) { $excelData[] = $data['totals']; } $xmlObj = new Varien_Convert_Parser_Xml_Excel(); $xmlObj->setVar('single_sheet', $filename); $xmlObj->setData($excelData); $xmlObj->unparse(); return $xmlObj->getData(); }
/** * Retrieve grid data as MS Excel 2003 XML Document * * @param string $filename the Workbook sheet name * @return string */ public function getExcel($filename = '') { $this->_isExport = true; $this->_prepareGrid(); $this->getCollection()->getSelect()->limit(); $this->getCollection()->setPageSize(0); $this->getCollection()->load(); $this->_afterLoadCollection(); $headers = array(); $data = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $headers[] = $column->getHeader(); } } $data[] = $headers; foreach ($this->getCollection() as $item) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($item); } } $data[] = $row; } if ($this->getCountTotals()) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($this->getTotals()); } } $data[] = $row; } $xmlObj = new Varien_Convert_Parser_Xml_Excel(); $xmlObj->setVar('single_sheet', $filename); $xmlObj->setData($data); $xmlObj->unparse(); return $xmlObj->getData(); }
/** * Retrieve grid as Excel Xml * * @return unknown */ public function getExcel($filename = '') { $this->_prepareGrid(); $data = array(); $row = array($this->__('Period')); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getHeader(); } } $data[] = $row; foreach ($this->getCollection()->getIntervals() as $_index => $_item) { $report = $this->getReport($_item['start'], $_item['end']); foreach ($report as $_subIndex => $_subItem) { $row = array($_index); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($_subItem); } } $data[] = $row; } if ($this->getCountTotals() && $this->getSubtotalVisibility()) { $row = array($_index); $j = 0; foreach ($this->_columns as $column) { $j++; if (!$column->getIsSystem()) { $row[] = $j == 1 ? $this->__('Subtotal') : $column->getRowField($this->getTotals()); } } $data[] = $row; } } if ($this->getCountTotals()) { $row = array($this->__('Total')); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($this->getGrandTotals()); } } $data[] = $row; } $xmlObj = new Varien_Convert_Parser_Xml_Excel(); $xmlObj->setVar('single_sheet', $filename); $xmlObj->setData($data); $xmlObj->unparse(); return $xmlObj->getData(); }
public function getExcel($filename = '') { $this->_prepareGrid(); $data = array(); foreach ($this->getColumns() as $column) { if (!$column->getIsSystem() && $column->getIndex() != 'stores') { $row[] = $column->getHeader(); } } $data[] = $row; if (count($this->getCustomVarData())) { foreach ($this->getCustomVarData() as $obj) { $row = array(); foreach ($this->getColumns() as $column) { if (!$column->getIsSystem() && $column->getIndex() != 'stores') { $row[] = $column->getRowField($obj); } } $data[] = $row; } } $xmlObj = new Varien_Convert_Parser_Xml_Excel(); $xmlObj->setVar('single_sheet', $filename); $xmlObj->setData($data); $xmlObj->unparse(); return $xmlObj->getData(); }
/** * Retrieve a file container array by grid data as MS Excel 2003 XML Document * * Return array with keys type and value * * @return string */ public function getExcelFile($sheetName = '') { $this->_isExport = true; $this->_prepareGrid(); $this->removeColumn('image'); $this->removeColumn('add_to_multiple_entries_list'); $parser = new Varien_Convert_Parser_Xml_Excel(); $io = new Varien_Io_File(); $path = Mage::getBaseDir('var') . DS . 'export' . DS; $name = md5(microtime()); $file = $path . DS . $name . '.xml'; $io->setAllowCreateFolders(true); $io->open(array('path' => $path)); $io->streamOpen($file, 'w+'); $io->streamLock(true); $io->streamWrite($parser->getHeaderXml($sheetName)); $io->streamWrite($parser->getRowXml($this->_getExportHeaders())); $this->_exportIterateCollection('_exportExcelItem', array($io, $parser)); if ($this->getCountTotals()) { $io->streamWrite($parser->getRowXml($this->_getExportTotals())); } $io->streamWrite($parser->getFooterXml()); $io->streamUnlock(); $io->streamClose(); return array('type' => 'filename', 'value' => $file, 'rm' => true); }
/** * Retrives Excel file content * @param string $filename * @return string */ public function getExcel($filename = '') { $this->_prepareGrid(); $data = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem() && $column->getIndex() != 'stores') { $row[] = $column->getHeader(); } } $data[] = $row; if (count($this->getCustomVarData())) { foreach ($this->getCustomVarData() as $obj) { $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem() && $column->getIndex() != 'stores') { $row[] = $column->getRowField($obj); } } $data[] = $row; } if ($this->getNeedTotal() && $this->getCountTotals() && count($this->getCustomVarData())) { $_isFirst = true; $row = array(); foreach ($this->_columns as $_column) { if ($_isFirst) { $row[] = $this->getTotalText(); } elseif ($_column->getType() == "action" || $_column->getDisableTotal()) { $row[] = ""; } else { $row[] = $_column->getRowField($this->getGrandTotals()); } $_isFirst = false; } $data[] = $row; } } $xmlObj = new Varien_Convert_Parser_Xml_Excel(); $xmlObj->setVar('single_sheet', $filename); $xmlObj->setData($data); $xmlObj->unparse(); return $xmlObj->getData(); }
protected function _exportExcelItem(Varien_Object $item, Varien_Io_File $adapter, $parser = null) { if (is_null($parser)) { $parser = new Varien_Convert_Parser_Xml_Excel(); } $row = array(); foreach ($this->_columns as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowFieldExport($item); } } $data = $parser->getRowXml($row); $adapter->streamWrite($data); }
public function expoXmlAction() { if (Mage::getModel('customer/session')->isLoggedIn()) { $orders = Mage::helper('marketplace')->getMarketOrders(); $filename = 'order.xml'; $data[0] = array($this->__("Order#"), $this->__("Bill to Name"), $this->__("Status"), $this->__("Total Sales"), $this->__("Amount Received"), $this->__("Amount Remain")); foreach ($orders as $order) { $data[] = array($order['increment_id'], $order['billname'], $order['status'], round($order['Total'], 2), round($order['Amount Received'], 2), round($order['Amount Remain'], 2)); } // Unparsing in Excel Format $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); } else { $this->_redirect('customer/account/login'); return; } }