Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Retrieve a file container array by grid data as MS Excel 2003 XML Document
  *
  * Return array with keys type and value
  *
  * @param string $sheetName
  * @return array
  */
 public function getExcelFile($sheetName = '')
 {
     $this->_isExport = true;
     $this->_prepareGrid();
     $convert = new \Magento\Framework\Convert\Excel($this->getCollection()->getIterator(), [$this, 'getRowRecord']);
     $name = md5(microtime());
     $file = $this->_path . '/' . $name . '.xml';
     $this->_directory->create($this->_path);
     $stream = $this->_directory->openFile($file, 'w+');
     $stream->lock();
     $convert->setDataHeader($this->_getExportHeaders());
     if ($this->getCountTotals()) {
         $convert->setDataFooter($this->_getExportTotals());
     }
     $convert->write($stream, $sheetName);
     $stream->unlock();
     $stream->close();
     return ['type' => 'filename', 'value' => $file, 'rm' => true];
 }