/** * Write Data into File * * @param bool $callback * @return string */ protected function _writeFile($callback = false) { $name = md5(microtime()); $file = TESTS_TEMP_DIR . '/' . $name . '.xml'; $stream = new \Magento\Framework\Filesystem\File\Write($file, new \Magento\Framework\Filesystem\Driver\File(), 'w+'); $stream->lock(); if (!$callback) { $convert = new \Magento\Framework\Convert\Excel(new \ArrayIterator($this->_testData)); $convert->setDataHeader($this->_testHeader); $convert->setDataFooter($this->_testFooter); } else { $convert = new \Magento\Framework\Convert\Excel(new \ArrayIterator($this->_testData), [$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() { $this->_isExport = true; $this->_prepareGrid(); $this->getCollection()->getSelect()->limit(); $this->getCollection()->setPageSize(0); $this->getCollection()->load(); $this->_afterLoadCollection(); $headers = []; $data = []; foreach ($this->getColumns() as $column) { if (!$column->getIsSystem()) { $headers[] = $column->getHeader(); } } $data[] = $headers; foreach ($this->getCollection() as $item) { $row = []; foreach ($this->getColumns() as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($item); } } $data[] = $row; } if ($this->getCountTotals()) { $row = []; foreach ($this->getColumns() as $column) { if (!$column->getIsSystem()) { $row[] = $column->getRowField($this->getTotals()); } } $data[] = $row; } $convert = new \Magento\Framework\Convert\Excel(new \ArrayIterator($data)); return $convert->convert('single_sheet'); }
/** * 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\Framework\Convert\Excel(new \ArrayIterator($data)); return $convert->convert('single_sheet'); }