Пример #1
0
 /**
  * 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');
 }
Пример #2
0
 /**
  * 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');
 }
Пример #3
0
 /**
  * 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');
 }
Пример #4
0
 /**
  * Test Magento_Convert_Excel->convert()
  * Magento_Convert_Excel($iterator, $callbackMethod)
  *
  * @return void
  */
 public function testConvertCallback()
 {
     $convert = new Magento_Convert_Excel(new ArrayIterator($this->_testData), array($this, 'callbackMethod'));
     $this->assertContains('_TRUE_', $convert->convert(), 'Failed asserting that callback method is called.');
 }