73        parent::__construct();
 
   91        if (function_exists(
'gzread')) {
 
   93            $fh = fopen($pFilename, 
'rb');
 
   95                $data = fread($fh, 2);
 
  100        return $data === chr(0x1F) . chr(0x8B);
 
  103    private static function matchXml(XMLReader 
$xml, 
string $expectedLocalName): bool
 
  105        return $xml->namespaceURI === self::NAMESPACE_GNM
 
  106            && 
$xml->localName === $expectedLocalName
 
  107            && 
$xml->nodeType === XMLReader::ELEMENT;
 
  121        $xml = 
new XMLReader();
 
  123        $xml->setParserProperty(2, 
true);
 
  125        $worksheetNames = [];
 
  126        while (
$xml->read()) {
 
  127            if (self::matchXml(
$xml, 
'SheetName')) {
 
  129                $worksheetNames[] = (string) 
$xml->value;
 
  130            } elseif (self::matchXml(
$xml, 
'Sheets')) {
 
  136        return $worksheetNames;
 
  150        $xml = 
new XMLReader();
 
  152        $xml->setParserProperty(2, 
true);
 
  155        while (
$xml->read()) {
 
  156            if (self::matchXml(
$xml, 
'Sheet')) {
 
  158                    'worksheetName' => 
'',
 
  159                    'lastColumnLetter' => 
'A',
 
  160                    'lastColumnIndex' => 0,
 
  165                while (
$xml->read()) {
 
  166                    if (self::matchXml(
$xml, 
'Name')) {
 
  168                        $tmpInfo[
'worksheetName'] = (string) 
$xml->value;
 
  169                    } elseif (self::matchXml(
$xml, 
'MaxCol')) {
 
  171                        $tmpInfo[
'lastColumnIndex'] = (int) 
$xml->value;
 
  172                        $tmpInfo[
'totalColumns'] = (
int) 
$xml->value + 1;
 
  173                    } elseif (self::matchXml(
$xml, 
'MaxRow')) {
 
  175                        $tmpInfo[
'totalRows'] = (int) 
$xml->value + 1;
 
  181                $worksheetInfo[] = $tmpInfo;
 
  185        return $worksheetInfo;
 
  197        if ($file !== 
false) {
 
  198            while (!gzeof($file)) {
 
  199                $data .= gzread($file, 1024);
 
  214        if ((!$this->readDataOnly) && (isset($sheet->Objects))) {
 
  215            foreach ($sheet->Objects->children(self::NAMESPACE_GNM) as 
$key => 
$comment) {
 
  216                $commentAttributes = 
$comment->attributes();
 
  218                if ($commentAttributes->Text) {
 
  219                    $this->spreadsheet->getActiveSheet()->getComment((
string) $commentAttributes->ObjectBound)
 
  220                        ->setAuthor((
string) $commentAttributes->Author)
 
  221                        ->setText($this->
parseRichText((
string) $commentAttributes->Text));
 
  232        return ($value instanceof SimpleXMLElement) ? $value : 
new SimpleXMLElement(
'<?xml version="1.0" encoding="UTF-8"?><root></root>');
 
  242    public function load($pFilename)
 
  265        $gnmXML = 
$xml->children(self::NAMESPACE_GNM);
 
  266        (
new Properties($this->spreadsheet))->readProperties(
$xml, $gnmXML);
 
  269        foreach ($gnmXML->Sheets->Sheet as $sheet) {
 
  270            $worksheetName = (string) $sheet->Name;
 
  271            if ((isset($this->loadSheetsOnly)) && (!in_array($worksheetName, $this->loadSheetsOnly))) {
 
  275            $maxRow = $maxCol = 0;
 
  278            $this->spreadsheet->createSheet();
 
  279            $this->spreadsheet->setActiveSheetIndex($worksheetID);
 
  283            $this->spreadsheet->getActiveSheet()->setTitle($worksheetName, 
false, 
false);
 
  285            if (!$this->readDataOnly) {
 
  287                    ->printInformation($sheet)
 
  288                    ->sheetMargins($sheet);
 
  291            foreach ($sheet->Cells->Cell as $cell) {
 
  292                $cellAttributes = $cell->attributes();
 
  293                $row = (int) $cellAttributes->Row + 1;
 
  294                $column = (
int) $cellAttributes->Col;
 
  296                if (
$row > $maxRow) {
 
  299                if ($column > $maxCol) {
 
  312                $ValueType = $cellAttributes->ValueType;
 
  313                $ExprID = (string) $cellAttributes->ExprID;
 
  316                    if (((
string) $cell) > 
'') {
 
  317                        $this->expressions[$ExprID] = [
 
  318                            'column' => $cellAttributes->Col,
 
  319                            'row' => $cellAttributes->Row,
 
  320                            'formula' => (string) $cell,
 
  323                        $expression = $this->expressions[$ExprID];
 
  325                        $cell = $this->referenceHelper->updateFormulaReferences(
 
  326                            $expression[
'formula'],
 
  328                            $cellAttributes->Col - $expression[
'column'],
 
  329                            $cellAttributes->Row - $expression[
'row'],
 
  335                    $vtype = (string) $ValueType;
 
  336                    if (array_key_exists($vtype, self::$mappings[
'dataType'])) {
 
  337                        $type = self::$mappings[
'dataType'][$vtype];
 
  339                    if ($vtype === 
'20') {        
 
  340                        $cell = $cell == 
'TRUE';
 
  343                $this->spreadsheet->getActiveSheet()->getCell($column . 
$row)->setValueExplicit((
string) $cell, 
$type);
 
  346            if ($sheet->Styles !== 
null) {
 
  347                (
new Styles($this->spreadsheet, $this->readDataOnly))->read($sheet, $maxRow, $maxCol);
 
  368        if ($sheet !== 
null && isset($sheet->MergedRegions)) {
 
  369            foreach ($sheet->MergedRegions->Merge as $mergeCells) {
 
  370                if (strpos($mergeCells, 
':') !== 
false) {
 
  371                    $this->spreadsheet->getActiveSheet()->mergeCells($mergeCells);
 
  379        if ($sheet !== 
null && isset($sheet->Filters)) {
 
  380            foreach ($sheet->Filters->Filter as $autofilter) {
 
  381                if ($autofilter !== 
null) {
 
  384                        $this->spreadsheet->getActiveSheet()->setAutoFilter((
string) 
$attributes[
'Area']);
 
  394        if ($columnDimension !== 
null) {
 
  395            $columnDimension->setWidth($defaultWidth);
 
  402        if ($columnDimension !== 
null) {
 
  403            $columnDimension->setVisible(
false);
 
  407    private function processColumnLoop(
int $whichColumn, 
int $maxCol, SimpleXMLElement $columnOverride, 
float $defaultWidth): int
 
  410        $column = $columnAttributes[
'No'];
 
  411        $columnWidth = ((float) $columnAttributes[
'Unit']) / 5.4;
 
  412        $hidden = (isset($columnAttributes[
'Hidden'])) && ((
string) $columnAttributes[
'Hidden'] == 
'1');
 
  414        while ($whichColumn < $column) {
 
  418        while (($whichColumn < ($column + 
$columnCount)) && ($whichColumn <= $maxCol)) {
 
  431        if ((!$this->readDataOnly) && $sheet !== 
null && (isset($sheet->Cols))) {
 
  434            $columnAttributes = $sheet->Cols->attributes();
 
  435            if ($columnAttributes !== 
null) {
 
  436                $defaultWidth = $columnAttributes[
'DefaultSizePts'] / 5.4;
 
  439            foreach ($sheet->Cols->ColInfo as $columnOverride) {
 
  440                $whichColumn = $this->
processColumnLoop($whichColumn, $maxCol, $columnOverride, $defaultWidth);
 
  442            while ($whichColumn <= $maxCol) {
 
  449    private function setRowHeight(
int $whichRow, 
float $defaultHeight): void
 
  451        $rowDimension = $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow);
 
  452        if ($rowDimension !== 
null) {
 
  453            $rowDimension->setRowHeight($defaultHeight);
 
  459        $rowDimension = $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow);
 
  460        if ($rowDimension !== 
null) {
 
  461            $rowDimension->setVisible(
false);
 
  465    private function processRowLoop(
int $whichRow, 
int $maxRow, SimpleXMLElement $rowOverride, 
float $defaultHeight): int
 
  468        $row = $rowAttributes[
'No'];
 
  469        $rowHeight = (float) $rowAttributes[
'Unit'];
 
  470        $hidden = (isset($rowAttributes[
'Hidden'])) && ((
string) $rowAttributes[
'Hidden'] == 
'1');
 
  471        $rowCount = (int) ($rowAttributes[
'Count'] ?? 1);
 
  472        while ($whichRow < 
$row) {
 
  476        while (($whichRow < (
$row + $rowCount)) && ($whichRow < $maxRow)) {
 
  489        if ((!$this->readDataOnly) && $sheet !== 
null && (isset($sheet->Rows))) {
 
  492            $rowAttributes = $sheet->Rows->attributes();
 
  493            if ($rowAttributes !== 
null) {
 
  494                $defaultHeight = (float) $rowAttributes[
'DefaultSizePts'];
 
  498            foreach ($sheet->Rows->RowInfo as $rowOverride) {
 
  499                $whichRow = $this->
processRowLoop($whichRow, $maxRow, $rowOverride, $defaultHeight);
 
  514        if ($gnmXML !== 
null && isset($gnmXML->Names)) {
 
  515            foreach ($gnmXML->Names->Name as $definedName) {
 
  516                $name = (string) $definedName->name;
 
  517                $value = (
string) $definedName->value;
 
  518                if (stripos($value, 
'#REF!') !== 
false) {
 
  522                [$worksheetName] = Worksheet::extractSheetTitle($value, 
true);
 
  523                $worksheetName = trim($worksheetName, 
"'");
 
  524                $worksheet = $this->spreadsheet->getSheetByName($worksheetName);
 
  526                if ($worksheet !== 
null) {
 
  536        $value->createText($is);
 
An exception for terminatinating execution or to throw for unit testing.
Helper class to manipulate cell coordinates.
static stringFromColumnIndex($columnIndex)
String from column index.
static createInstance(string $name, ?Worksheet $worksheet=null, ?string $value=null, bool $localOnly=false, ?Worksheet $scope=null)
Create a new defined name, either a range or a formula.
getReadFilter()
Read filter.
listWorksheetInfo($pFilename)
Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns).
setColumnInvisible(int $whichColumn)
processColumnWidths(?SimpleXMLElement $sheet, int $maxCol)
__construct()
Create a new Gnumeric.
loadIntoExisting(string $pFilename, Spreadsheet $spreadsheet)
Loads from file into Spreadsheet instance.
setRowHeight(int $whichRow, float $defaultHeight)
setColumnWidth(int $whichColumn, float $defaultWidth)
processRowLoop(int $whichRow, int $maxRow, SimpleXMLElement $rowOverride, float $defaultHeight)
listWorksheetNames($pFilename)
Reads names of the worksheets from a file, without parsing the whole file to a Spreadsheet object.
processDefinedNames(?SimpleXMLElement $gnmXML)
setRowInvisible(int $whichRow)
static matchXml(XMLReader $xml, string $expectedLocalName)
load($pFilename)
Loads Spreadsheet from file.
processComments(SimpleXMLElement $sheet)
static gnumericMappings()
processColumnLoop(int $whichColumn, int $maxCol, SimpleXMLElement $columnOverride, float $defaultWidth)
canRead($pFilename)
Can the current IReader read the file?
parseRichText(string $is)
processRowHeights(?SimpleXMLElement $sheet, int $maxRow)
processMergedCells(?SimpleXMLElement $sheet)
processAutofilter(?SimpleXMLElement $sheet)
gzfileGetContents($filename)
static testSimpleXml($value)
static getInstance(Reader\IReader $reader)
static getInstance()
Get an instance of this class.
static getLibXmlLoaderOptions()
Get default options for libxml loader.
static assertFile($filename)
Assert that given path is an existing file and is readable, otherwise throw exception.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
if(array_key_exists('yes', $_REQUEST)) $attributes