/** * 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; } $convert = new Magento_Convert_Excel(new ArrayIterator($data)); return $convert->convert('single_sheet'); }
/** * Retrieve grid data as MS Excel 2003 XML Document * * @return string */ public function getExcel() { $this->_isExport = true; $this->_prepareGrid(); $this->getCollection()->getSelect()->limit(); $this->getCollection()->setPageSize(0); $this->getCollection()->load(); $this->_afterLoadCollection(); $headers = array(); $data = array(); foreach ($this->getColumns() as $column) { if (!$column->getIsSystem()) { $headers[] = $column->getHeader(); } } $data[] = $headers; foreach ($this->getCollection() as $item) { $row = array(); foreach ($this->getColumns() as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($item); } } $data[] = $row; } if ($this->getCountTotals()) { $row = array(); foreach ($this->getColumns() as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($this->getTotals()); } } $data[] = $row; } $convert = new Magento_Convert_Excel(new ArrayIterator($data)); return $convert->convert('single_sheet'); }
/** * Write Data into File * * @param bool $callback * @return string */ protected function _writeFile($callback = false) { $adapter = new Magento_Filesystem_Adapter_Local(); $filesystem = new Magento_Filesystem($adapter); $name = md5(microtime()); $file = TESTS_TEMP_DIR . DIRECTORY_SEPARATOR . $name . '.xml'; $stream = $filesystem->createAndOpenStream($file, 'w+', TESTS_TEMP_DIR); $stream->lock(true); if (!$callback) { $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData)); } else { $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData), array($this, 'callbackMethod')); } $convert->write($stream); $stream->unlock(); $stream->close(); return $file; }
/** * Retrieve grid data as MS Excel 2003 XML Document * * @return string */ public function getExcel() { $collection = $this->_getPreparedCollection(); $headers = array(); $data = array(); foreach ($this->_getColumns() as $column) { if (!$column->getIsSystem()) { $headers[] = $column->getHeader(); } } $data[] = $headers; foreach ($collection as $item) { $row = array(); foreach ($this->_getColumns() as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($item); } } $data[] = $row; } if ($this->getCountTotals()) { $row = array(); foreach ($this->_getColumns() as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($this->_getTotals()); } } $data[] = $row; } $convert = new Magento_Convert_Excel(new ArrayIterator($data)); return $convert->convert('single_sheet'); }
/** * Write Data into File * * @param bool $callback * @return string */ protected function _writeFile($callback = false) { $ioFile = new Varien_Io_File(); $path = Magento_Test_Environment::getInstance()->getTmpDir(); $name = md5(microtime()); $file = $path . DIRECTORY_SEPARATOR . $name . '.xml'; $ioFile->open(array('path' => $path)); $ioFile->streamOpen($file, 'w+'); $ioFile->streamLock(true); if (!$callback) { $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData)); } else { $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData), array($this, 'callbackMethod')); } $convert->write($ioFile); $ioFile->streamUnlock(); $ioFile->streamClose(); return $file; }