Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Excel Class Reference

Public Member Functions

 __construct (\Iterator $iterator, $rowCallback=[])
 
 setDataHeader ($data)
 
 setDataFooter ($data)
 
 convert ($sheetName='')
 
 write (WriteInterface $stream, $sheetName='')
 

Protected Member Functions

 _getXmlHeader ($sheetName='')
 
 _getXmlFooter ()
 

Protected Attributes

 $_iterator = null
 
 $_rowCallback = []
 
 $_dataHeader = []
 
 $_dataFooter = []
 

Detailed Description

Convert the data to XML Excel

Definition at line 13 of file Excel.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Iterator  $iterator,
  $rowCallback = [] 
)

Class Constructor

Parameters
\Iterator$iterator
array$rowCallback

Definition at line 49 of file Excel.php.

50  {
51  $this->_iterator = $iterator;
52  $this->_rowCallback = $rowCallback;
53  }

Member Function Documentation

◆ _getXmlFooter()

_getXmlFooter ( )
protected

Retrieve Excel XML Document Footer XML Fragment Append data footer if it is available

Returns
string

Definition at line 105 of file Excel.php.

106  {
107  $xmlFooter = '';
108 
109  if ($this->_dataFooter) {
110  $xmlFooter = $this->_getXmlRow($this->_dataFooter, false);
111  }
112 
113  $xmlFooter .= '</Table></Worksheet></Workbook>';
114 
115  return $xmlFooter;
116  }

◆ _getXmlHeader()

_getXmlHeader (   $sheetName = '')
protected

Retrieve Excel XML Document Header XML Fragment Append data header if it is available

Parameters
string$sheetName
Returns
string

Definition at line 62 of file Excel.php.

63  {
64  if (empty($sheetName)) {
65  $sheetName = 'Sheet 1';
66  }
67 
68  $sheetName = htmlspecialchars($sheetName);
69 
70  $xmlHeader = '<' .
71  '?xml version="1.0"?' .
72  '><' .
73  '?mso-application progid="Excel.Sheet"?' .
74  '><Workbook' .
75  ' xmlns="urn:schemas-microsoft-com:office:spreadsheet"' .
76  ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
77  ' xmlns:x="urn:schemas-microsoft-com:office:excel"' .
78  ' xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"' .
79  ' xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"' .
80  ' xmlns:o="urn:schemas-microsoft-com:office:office"' .
81  ' xmlns:html="http://www.w3.org/TR/REC-html40"' .
82  ' xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet">' .
83  '<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">' .
84  '</OfficeDocumentSettings>' .
85  '<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">' .
86  '</ExcelWorkbook>' .
87  '<Worksheet ss:Name="' .
88  $sheetName .
89  '">' .
90  '<Table>';
91 
92  if ($this->_dataHeader) {
93  $xmlHeader .= $this->_getXmlRow($this->_dataHeader, false);
94  }
95 
96  return $xmlHeader;
97  }

◆ convert()

convert (   $sheetName = '')

Convert Data to Excel XML Document

Parameters
string$sheetName
Returns
string

Definition at line 192 of file Excel.php.

193  {
194  $xml = $this->_getXmlHeader($sheetName);
195 
196  foreach ($this->_iterator as $dataRow) {
197  $xml .= $this->_getXmlRow($dataRow, true);
198  }
199  $xml .= $this->_getXmlFooter();
200 
201  return $xml;
202  }
_getXmlHeader($sheetName='')
Definition: Excel.php:62

◆ setDataFooter()

setDataFooter (   $data)

Set Data Footer

Parameters
array$data
Returns
void

Definition at line 181 of file Excel.php.

182  {
183  $this->_dataFooter = $data;
184  }

◆ setDataHeader()

setDataHeader (   $data)

Set Data Header

Parameters
array$data
Returns
void

Definition at line 170 of file Excel.php.

171  {
172  $this->_dataHeader = $data;
173  }

◆ write()

write ( WriteInterface  $stream,
  $sheetName = '' 
)

Write Converted XML Data to Temporary File

Parameters
WriteInterface$stream
string$sheetName
Returns
void

Definition at line 211 of file Excel.php.

212  {
213  $stream->write($this->_getXmlHeader($sheetName));
214 
215  foreach ($this->_iterator as $dataRow) {
216  $stream->write($this->_getXmlRow($dataRow, true));
217  }
218  $stream->write($this->_getXmlFooter());
219  }
_getXmlHeader($sheetName='')
Definition: Excel.php:62

Field Documentation

◆ $_dataFooter

$_dataFooter = []
protected

Definition at line 41 of file Excel.php.

◆ $_dataHeader

$_dataHeader = []
protected

Definition at line 34 of file Excel.php.

◆ $_iterator

$_iterator = null
protected

Definition at line 20 of file Excel.php.

◆ $_rowCallback

$_rowCallback = []
protected

Definition at line 27 of file Excel.php.


The documentation for this class was generated from the following file: