ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\Reader\Ods Class Reference
+ Inheritance diagram for PhpOffice\PhpSpreadsheet\Reader\Ods:
+ Collaboration diagram for PhpOffice\PhpSpreadsheet\Reader\Ods:

Public Member Functions

 __construct ()
 Create a new Ods Reader instance. More...
 
 canRead ($pFilename)
 Can the current IReader read the file? More...
 
 listWorksheetNames ($pFilename)
 Reads names of the worksheets from a file, without parsing the whole file to a PhpSpreadsheet object. More...
 
 listWorksheetInfo ($pFilename)
 Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns). More...
 
 load ($pFilename)
 Loads PhpSpreadsheet from file. More...
 
- Public Member Functions inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 __construct ()
 IReader constructor. More...
 
 getReadDataOnly ()
 Read data only? If this is true, then the Reader will only read data values for cells, it will not read any formatting information. More...
 
 setReadDataOnly ($pValue)
 Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. More...
 
 getReadEmptyCells ()
 Read empty cells? If this is true (the default), then the Reader will read data values for all cells, irrespective of value. More...
 
 setReadEmptyCells ($pValue)
 Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. More...
 
 getIncludeCharts ()
 Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook. More...
 
 setIncludeCharts ($pValue)
 Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook. More...
 
 getLoadSheetsOnly ()
 Get which sheets to load Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null indicating that all worksheets in the workbook should be loaded. More...
 
 setLoadSheetsOnly ($value)
 Set which sheets to load. More...
 
 setLoadAllSheets ()
 Set all sheets to load Tells the Reader to load all worksheets from the workbook. More...
 
 getReadFilter ()
 Read filter. More...
 
 setReadFilter (IReadFilter $pValue)
 Set read filter. More...
 
 getSecurityScanner ()
 
 __construct ()
 IReader constructor. More...
 
 canRead ($pFilename)
 Can the current IReader read the file? More...
 
 getReadDataOnly ()
 Read data only? If this is true, then the Reader will only read data values for cells, it will not read any formatting information. More...
 
 setReadDataOnly ($pValue)
 Set read data only Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. More...
 
 getReadEmptyCells ()
 Read empty cells? If this is true (the default), then the Reader will read data values for all cells, irrespective of value. More...
 
 setReadEmptyCells ($pValue)
 Set read empty cells Set to true (the default) to advise the Reader read data values for all cells, irrespective of value. More...
 
 getIncludeCharts ()
 Read charts in workbook? If this is true, then the Reader will include any charts that exist in the workbook. More...
 
 setIncludeCharts ($pValue)
 Set read charts in workbook Set to true, to advise the Reader to include any charts that exist in the workbook. More...
 
 getLoadSheetsOnly ()
 Get which sheets to load Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null indicating that all worksheets in the workbook should be loaded. More...
 
 setLoadSheetsOnly ($value)
 Set which sheets to load. More...
 
 setLoadAllSheets ()
 Set all sheets to load Tells the Reader to load all worksheets from the workbook. More...
 
 getReadFilter ()
 Read filter. More...
 
 setReadFilter (IReadFilter $pValue)
 Set read filter. More...
 
 load ($pFilename)
 Loads PhpSpreadsheet from file. More...
 

Private Member Functions

 processSettings (ZipArchive $zip, Spreadsheet $spreadsheet)
 
 setSelected (Spreadsheet $spreadsheet, string $wsname, string $setCol, string $setRow)
 
 parseRichText ($is)
 
 convertToExcelFormulaValue (string $openOfficeFormula)
 

Additional Inherited Members

- Protected Member Functions inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 openFile ($pFilename)
 Open file for reading. More...
 
- Protected Attributes inherited from PhpOffice\PhpSpreadsheet\Reader\BaseReader
 $readDataOnly = false
 
 $readEmptyCells = true
 
 $includeCharts = false
 
 $loadSheetsOnly
 
 $readFilter
 
 $fileHandle
 
 $securityScanner
 

Detailed Description

Definition at line 29 of file Ods.php.

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\Reader\Ods::__construct ( )

Create a new Ods Reader instance.

Reimplemented from PhpOffice\PhpSpreadsheet\Reader\BaseReader.

Definition at line 34 of file Ods.php.

35 {
36 parent::__construct();
37 $this->securityScanner = XmlScanner::getInstance($this);
38 }
static getInstance(Reader\IReader $reader)
Definition: XmlScanner.php:39

References PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner\getInstance().

+ Here is the call graph for this function:

Member Function Documentation

◆ canRead()

PhpOffice\PhpSpreadsheet\Reader\Ods::canRead (   $pFilename)

Can the current IReader read the file?

Parameters
string$pFilename
Returns
bool

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 47 of file Ods.php.

48 {
49 File::assertFile($pFilename);
50
51 $mimeType = 'UNKNOWN';
52
53 // Load file
54
55 $zip = new ZipArchive();
56 if ($zip->open($pFilename) === true) {
57 // check if it is an OOXML archive
58 $stat = $zip->statName('mimetype');
59 if ($stat && ($stat['size'] <= 255)) {
60 $mimeType = $zip->getFromName($stat['name']);
61 } elseif ($zip->statName('META-INF/manifest.xml')) {
62 $xml = simplexml_load_string(
63 $this->securityScanner->scan($zip->getFromName('META-INF/manifest.xml')),
64 'SimpleXMLElement',
66 );
67 $namespacesContent = $xml->getNamespaces(true);
68 if (isset($namespacesContent['manifest'])) {
69 $manifest = $xml->children($namespacesContent['manifest']);
70 foreach ($manifest as $manifestDataSet) {
71 $manifestAttributes = $manifestDataSet->attributes($namespacesContent['manifest']);
72 if ($manifestAttributes->{'full-path'} == '/') {
73 $mimeType = (string) $manifestAttributes->{'media-type'};
74
75 break;
76 }
77 }
78 }
79 }
80
81 $zip->close();
82 }
83
84 return $mimeType === 'application/vnd.oasis.opendocument.spreadsheet';
85 }
static getLibXmlLoaderOptions()
Get default options for libxml loader.
Definition: Settings.php:116
static assertFile($filename)
Assert that given path is an existing file and is readable, otherwise throw exception.
Definition: File.php:143

References $xml, PhpOffice\PhpSpreadsheet\Shared\File\assertFile(), and PhpOffice\PhpSpreadsheet\Settings\getLibXmlLoaderOptions().

+ Here is the call graph for this function:

◆ convertToExcelFormulaValue()

PhpOffice\PhpSpreadsheet\Reader\Ods::convertToExcelFormulaValue ( string  $openOfficeFormula)
private

Definition at line 771 of file Ods.php.

771 : string
772 {
773 $temp = explode('"', $openOfficeFormula);
774 $tKey = false;
775 foreach ($temp as &$value) {
776 // Only replace in alternate array entries (i.e. non-quoted blocks)
777 if ($tKey = !$tKey) {
778 // Cell range reference in another sheet
779 $value = preg_replace('/\[\$?([^\.]+)\.([^\.]+):\.([^\.]+)\]/miu', '$1!$2:$3', $value);
780 // Cell reference in another sheet
781 $value = preg_replace('/\[\$?([^\.]+)\.([^\.]+)\]/miu', '$1!$2', $value ?? '');
782 // Cell range reference
783 $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/miu', '$1:$2', $value ?? '');
784 // Simple cell reference
785 $value = preg_replace('/\[\.([^\.]+)\]/miu', '$1', $value ?? '');
786 // Convert references to defined names/formulae
787 $value = str_replace('$$', '', $value ?? '');
788
789 $value = Calculation::translateSeparator(';', ',', $value, $inBraces);
790 }
791 }
792
793 // Then rebuild the formula string
794 $excelFormula = implode('"', $temp);
795
796 return $excelFormula;
797 }
static translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)

◆ listWorksheetInfo()

PhpOffice\PhpSpreadsheet\Reader\Ods::listWorksheetInfo (   $pFilename)

Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).

Parameters
string$pFilename
Returns
array

Definition at line 146 of file Ods.php.

147 {
148 File::assertFile($pFilename);
149
150 $worksheetInfo = [];
151
152 $zip = new ZipArchive();
153 if ($zip->open($pFilename) !== true) {
154 throw new ReaderException('Could not open ' . $pFilename . ' for reading! Error opening file.');
155 }
156
157 $xml = new XMLReader();
158 $xml->xml(
159 $this->securityScanner->scanFile('zip://' . realpath($pFilename) . '#content.xml'),
160 null,
162 );
163 $xml->setParserProperty(2, true);
164
165 // Step into the first level of content of the XML
166 $xml->read();
167 while ($xml->read()) {
168 // Quickly jump through to the office:body node
169 while ($xml->name !== 'office:body') {
170 if ($xml->isEmptyElement) {
171 $xml->read();
172 } else {
173 $xml->next();
174 }
175 }
176 // Now read each node until we find our first table:table node
177 while ($xml->read()) {
178 if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
179 $worksheetNames[] = $xml->getAttribute('table:name');
180
181 $tmpInfo = [
182 'worksheetName' => $xml->getAttribute('table:name'),
183 'lastColumnLetter' => 'A',
184 'lastColumnIndex' => 0,
185 'totalRows' => 0,
186 'totalColumns' => 0,
187 ];
188
189 // Loop through each child node of the table:table element reading
190 $currCells = 0;
191 do {
192 $xml->read();
193 if ($xml->name == 'table:table-row' && $xml->nodeType == XMLReader::ELEMENT) {
194 $rowspan = $xml->getAttribute('table:number-rows-repeated');
195 $rowspan = empty($rowspan) ? 1 : $rowspan;
196 $tmpInfo['totalRows'] += $rowspan;
197 $tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'], $currCells);
198 $currCells = 0;
199 // Step into the row
200 $xml->read();
201 do {
202 $doread = true;
203 if ($xml->name == 'table:table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
204 if (!$xml->isEmptyElement) {
205 ++$currCells;
206 $xml->next();
207 $doread = false;
208 }
209 } elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
210 $mergeSize = $xml->getAttribute('table:number-columns-repeated');
211 $currCells += (int) $mergeSize;
212 }
213 if ($doread) {
214 $xml->read();
215 }
216 } while ($xml->name != 'table:table-row');
217 }
218 } while ($xml->name != 'table:table');
219
220 $tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'], $currCells);
221 $tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1;
222 $tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex'] + 1);
223 $worksheetInfo[] = $tmpInfo;
224 }
225 }
226 }
227
228 return $worksheetInfo;
229 }
static stringFromColumnIndex($columnIndex)
String from column index.
Definition: Coordinate.php:313

References $xml.

◆ listWorksheetNames()

PhpOffice\PhpSpreadsheet\Reader\Ods::listWorksheetNames (   $pFilename)

Reads names of the worksheets from a file, without parsing the whole file to a PhpSpreadsheet object.

Parameters
string$pFilename
Returns
string[]

Definition at line 94 of file Ods.php.

95 {
96 File::assertFile($pFilename);
97
98 $zip = new ZipArchive();
99 if ($zip->open($pFilename) !== true) {
100 throw new ReaderException('Could not open ' . $pFilename . ' for reading! Error opening file.');
101 }
102
103 $worksheetNames = [];
104
105 $xml = new XMLReader();
106 $xml->xml(
107 $this->securityScanner->scanFile('zip://' . realpath($pFilename) . '#content.xml'),
108 null,
110 );
111 $xml->setParserProperty(2, true);
112
113 // Step into the first level of content of the XML
114 $xml->read();
115 while ($xml->read()) {
116 // Quickly jump through to the office:body node
117 while ($xml->name !== 'office:body') {
118 if ($xml->isEmptyElement) {
119 $xml->read();
120 } else {
121 $xml->next();
122 }
123 }
124 // Now read each node until we find our first table:table node
125 while ($xml->read()) {
126 if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
127 // Loop through each table:table node reading the table:name attribute for each worksheet name
128 do {
129 $worksheetNames[] = $xml->getAttribute('table:name');
130 $xml->next();
131 } while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT);
132 }
133 }
134 }
135
136 return $worksheetNames;
137 }

References $xml.

◆ load()

PhpOffice\PhpSpreadsheet\Reader\Ods::load (   $pFilename)

Loads PhpSpreadsheet from file.

Parameters
string$pFilename
Returns
Spreadsheet

Implements PhpOffice\PhpSpreadsheet\Reader\IReader.

Definition at line 238 of file Ods.php.

239 {
240 // Create new Spreadsheet
241 $spreadsheet = new Spreadsheet();
242
243 // Load into this instance
244 return $this->loadIntoExisting($pFilename, $spreadsheet);
245 }

◆ parseRichText()

PhpOffice\PhpSpreadsheet\Reader\Ods::parseRichText (   $is)
private
Parameters
string$is
Returns
RichText

Definition at line 763 of file Ods.php.

764 {
765 $value = new RichText();
766 $value->createText($is);
767
768 return $value;
769 }

◆ processSettings()

PhpOffice\PhpSpreadsheet\Reader\Ods::processSettings ( ZipArchive  $zip,
Spreadsheet  $spreadsheet 
)
private

Definition at line 654 of file Ods.php.

654 : void
655 {
656 $dom = new DOMDocument('1.01', 'UTF-8');
657 $dom->loadXML(
658 $this->securityScanner->scan($zip->getFromName('settings.xml')),
660 );
661 //$xlinkNs = $dom->lookupNamespaceUri('xlink');
662 $configNs = $dom->lookupNamespaceUri('config');
663 //$oooNs = $dom->lookupNamespaceUri('ooo');
664 $officeNs = $dom->lookupNamespaceUri('office');
665 $settings = $dom->getElementsByTagNameNS($officeNs, 'settings')
666 ->item(0);
667 $this->lookForActiveSheet($settings, $spreadsheet, $configNs);
668 $this->lookForSelectedCells($settings, $spreadsheet, $configNs);
669 }

◆ setSelected()

PhpOffice\PhpSpreadsheet\Reader\Ods::setSelected ( Spreadsheet  $spreadsheet,
string  $wsname,
string  $setCol,
string  $setRow 
)
private

Definition at line 712 of file Ods.php.

712 : void
713 {
714 if (is_numeric($setCol) && is_numeric($setRow)) {
715 try {
716 $spreadsheet->getSheetByName($wsname)->setSelectedCellByColumnAndRow($setCol + 1, $setRow + 1);
717 } catch (Throwable $e) {
718 // do nothing
719 }
720 }
721 }
getSheetByName($pName)
Get sheet by name.

References PhpOffice\PhpSpreadsheet\Spreadsheet\getSheetByName().

+ Here is the call graph for this function:

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