Ods reader: added/fixed PHPDoc and classes without namespace
This commit is contained in:
parent
4cf7beef31
commit
b50ca6e27c
|
@ -64,7 +64,10 @@ class Ods extends BaseReader implements IReader
|
||||||
$zipClass = \PhpOffice\PhpSpreadsheet\Settings::getZipClass();
|
$zipClass = \PhpOffice\PhpSpreadsheet\Settings::getZipClass();
|
||||||
|
|
||||||
$mimeType = 'UNKNOWN';
|
$mimeType = 'UNKNOWN';
|
||||||
|
|
||||||
// Load file
|
// Load file
|
||||||
|
|
||||||
|
/** @var \ZipArchive $zip */
|
||||||
$zip = new $zipClass();
|
$zip = new $zipClass();
|
||||||
if ($zip->open($pFilename) === true) {
|
if ($zip->open($pFilename) === true) {
|
||||||
// check if it is an OOXML archive
|
// check if it is an OOXML archive
|
||||||
|
@ -104,6 +107,7 @@ class Ods extends BaseReader implements IReader
|
||||||
* @param string $pFilename
|
* @param string $pFilename
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function listWorksheetNames($pFilename)
|
public function listWorksheetNames($pFilename)
|
||||||
{
|
{
|
||||||
|
@ -111,6 +115,7 @@ class Ods extends BaseReader implements IReader
|
||||||
|
|
||||||
$zipClass = \PhpOffice\PhpSpreadsheet\Settings::getZipClass();
|
$zipClass = \PhpOffice\PhpSpreadsheet\Settings::getZipClass();
|
||||||
|
|
||||||
|
/** @var \ZipArchive $zip */
|
||||||
$zip = new $zipClass();
|
$zip = new $zipClass();
|
||||||
if (!$zip->open($pFilename)) {
|
if (!$zip->open($pFilename)) {
|
||||||
throw new Exception('Could not open ' . $pFilename . ' for reading! Error opening file.');
|
throw new Exception('Could not open ' . $pFilename . ' for reading! Error opening file.');
|
||||||
|
@ -118,8 +123,8 @@ class Ods extends BaseReader implements IReader
|
||||||
|
|
||||||
$worksheetNames = [];
|
$worksheetNames = [];
|
||||||
|
|
||||||
$xml = new XMLReader();
|
$xml = new \XMLReader();
|
||||||
$res = $xml->xml(
|
$xml->xml(
|
||||||
$this->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'),
|
$this->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'),
|
||||||
null,
|
null,
|
||||||
\PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions()
|
\PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions()
|
||||||
|
@ -139,12 +144,12 @@ class Ods extends BaseReader implements IReader
|
||||||
}
|
}
|
||||||
// Now read each node until we find our first table:table node
|
// Now read each node until we find our first table:table node
|
||||||
while ($xml->read()) {
|
while ($xml->read()) {
|
||||||
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
|
if ($xml->name == 'table:table' && $xml->nodeType == \XMLReader::ELEMENT) {
|
||||||
// Loop through each table:table node reading the table:name attribute for each worksheet name
|
// Loop through each table:table node reading the table:name attribute for each worksheet name
|
||||||
do {
|
do {
|
||||||
$worksheetNames[] = $xml->getAttribute('table:name');
|
$worksheetNames[] = $xml->getAttribute('table:name');
|
||||||
$xml->next();
|
$xml->next();
|
||||||
} while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT);
|
} while ($xml->name == 'table:table' && $xml->nodeType == \XMLReader::ELEMENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,6 +163,7 @@ class Ods extends BaseReader implements IReader
|
||||||
* @param string $pFilename
|
* @param string $pFilename
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function listWorksheetInfo($pFilename)
|
public function listWorksheetInfo($pFilename)
|
||||||
{
|
{
|
||||||
|
@ -167,12 +173,13 @@ class Ods extends BaseReader implements IReader
|
||||||
|
|
||||||
$zipClass = \PhpOffice\PhpSpreadsheet\Settings::getZipClass();
|
$zipClass = \PhpOffice\PhpSpreadsheet\Settings::getZipClass();
|
||||||
|
|
||||||
|
/** @var \ZipArchive $zip */
|
||||||
$zip = new $zipClass();
|
$zip = new $zipClass();
|
||||||
if (!$zip->open($pFilename)) {
|
if (!$zip->open($pFilename)) {
|
||||||
throw new Exception('Could not open ' . $pFilename . ' for reading! Error opening file.');
|
throw new Exception('Could not open ' . $pFilename . ' for reading! Error opening file.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml = new XMLReader();
|
$xml = new \XMLReader();
|
||||||
$res = $xml->xml(
|
$res = $xml->xml(
|
||||||
$this->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'),
|
$this->securityScanFile('zip://' . realpath($pFilename) . '#content.xml'),
|
||||||
null,
|
null,
|
||||||
|
@ -193,7 +200,7 @@ class Ods extends BaseReader implements IReader
|
||||||
}
|
}
|
||||||
// Now read each node until we find our first table:table node
|
// Now read each node until we find our first table:table node
|
||||||
while ($xml->read()) {
|
while ($xml->read()) {
|
||||||
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
|
if ($xml->name == 'table:table' && $xml->nodeType == \XMLReader::ELEMENT) {
|
||||||
$worksheetNames[] = $xml->getAttribute('table:name');
|
$worksheetNames[] = $xml->getAttribute('table:name');
|
||||||
|
|
||||||
$tmpInfo = [
|
$tmpInfo = [
|
||||||
|
@ -208,7 +215,7 @@ class Ods extends BaseReader implements IReader
|
||||||
$currCells = 0;
|
$currCells = 0;
|
||||||
do {
|
do {
|
||||||
$xml->read();
|
$xml->read();
|
||||||
if ($xml->name == 'table:table-row' && $xml->nodeType == XMLReader::ELEMENT) {
|
if ($xml->name == 'table:table-row' && $xml->nodeType == \XMLReader::ELEMENT) {
|
||||||
$rowspan = $xml->getAttribute('table:number-rows-repeated');
|
$rowspan = $xml->getAttribute('table:number-rows-repeated');
|
||||||
$rowspan = empty($rowspan) ? 1 : $rowspan;
|
$rowspan = empty($rowspan) ? 1 : $rowspan;
|
||||||
$tmpInfo['totalRows'] += $rowspan;
|
$tmpInfo['totalRows'] += $rowspan;
|
||||||
|
@ -217,14 +224,14 @@ class Ods extends BaseReader implements IReader
|
||||||
// Step into the row
|
// Step into the row
|
||||||
$xml->read();
|
$xml->read();
|
||||||
do {
|
do {
|
||||||
if ($xml->name == 'table:table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
|
if ($xml->name == 'table:table-cell' && $xml->nodeType == \XMLReader::ELEMENT) {
|
||||||
if (!$xml->isEmptyElement) {
|
if (!$xml->isEmptyElement) {
|
||||||
++$currCells;
|
++$currCells;
|
||||||
$xml->next();
|
$xml->next();
|
||||||
} else {
|
} else {
|
||||||
$xml->read();
|
$xml->read();
|
||||||
}
|
}
|
||||||
} elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
|
} elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == \XMLReader::ELEMENT) {
|
||||||
$mergeSize = $xml->getAttribute('table:number-columns-repeated');
|
$mergeSize = $xml->getAttribute('table:number-columns-repeated');
|
||||||
$currCells += $mergeSize;
|
$currCells += $mergeSize;
|
||||||
$xml->read();
|
$xml->read();
|
||||||
|
|
Loading…
Reference in New Issue