Skip to content

[IMPROVEMENT] Excel: keep phpoffice/phpspreadsheet inside the Excel component - #12269

Merged
chfsx merged 3 commits into
ILIAS-eLearning:trunkfrom
srsolutionsag:improvement/12/excel-phpspreadsheet-wrapping
Oct 27, 2026
Merged

chfsx merged 3 commits into
ILIAS-eLearning:trunkfrom
srsolutionsag:improvement/12/excel-phpspreadsheet-wrapping

Conversation

@chfsx

@chfsx chfsx commented Oct 23, 2026

Copy link
Copy Markdown
Member

ilExcel wraps phpoffice/phpspreadsheet, but its API let two library details through: setCell() expected the DataType::TYPE_* constants of the library for explicit cell types, and its public methods threw the exceptions of the library. DataCollection therefore imported PhpOffice\PhpSpreadsheet\Cell\DataType, and Test, Exercise, Survey and DataCollection documented PhpOffice\PhpSpreadsheet\Exception in their @throws. This PR gives Excel its own types for both. Same approach as #12266 (guzzlehttp/psr7), #12267 (pimple/pimple) and #12268 (dflydev/fig-cookies).

Excel

  • New ILIAS\Excel\CellType (string enum: STRING, NUMERIC, BOOL, FORMULA). ilExcel::setCell() accepts CellType|string|null; strings keep working (e.g. for plugins) but are deprecated.
  • New ILIAS\Excel\ExcelException extends \RuntimeException. ilExcel translates the exceptions of the library into it, keeping the original one as previous (constructor, loadFromFile(), addSheet(), setActiveSheet(), sendToClient(), writeToFile(), writeToTmpFile(), addLink(), mergeCells()). The library exception is a \RuntimeException as well, so callers catching that keep working.
  • ExcelTestTBD is active again as ExcelTest (it was deactivated in 2024 because the library was missing) and gets tests for the exception translation and for CellType::STRING.

Components

  • DataCollection (text and text selection fields) passes CellType::STRING.
  • The @throws of DataCollection, Test, Exercise and Survey name \ILIAS\Excel\ExcelException; an unused import of DataType in Test is removed.

Testing

  • Build: [OK] All static artifacts are build!
  • PHPUnit, whole suite: green except RootFolderTest, which only fails locally because of untracked files in the root folder of my checkout.
  • Code rules gate on components/ILIAS: green. php-cs-fixer on the changed files: clean.
  • On a trunk installation, in the browser: data collection with a text field and the entry "007", "Export Excel" of the table: in the downloaded file the cell holds "007" as text, the leading zeros are kept.

@kergomard for Excel, @iszmais for DataCollection, @alex40724 for Exercise, @abrahammordev @juanma1331 for Survey, @dsstrassner for Test.

If there are no objections, I will merge this before Coding Completed.

@dsstrassner

Copy link
Copy Markdown
Contributor

Hi @thojou please Look into this for Test. Thanks

@iszmais iszmais left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes within the DataCollection!

LGMT 👍

@kergomard kergomard left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much @chfsx for this improvement!

I'm very happy with the CellType, I'm unhappy with the Exception.

  • Please remove all @throws with the Excel component. There is nobody really relying on it throwing anything specific right now and I would very much like it to stay this way. We usually do not use Exceptions for our command flow as I understand it and I do not want to start doing so here.
  • Please remove the specific Exception and simply throw an \ilException with the corresponding text.
  • Please remove the wrapper-function and try catch every place individually.

I know, this is ugly, but it is so on purpose. We might go any other way in the future and I do not want to cement any possible approach right now. If we now start throwing a specific Exception here this makes it look like it is by design. It isn't, it is by convenience/coincidence.

Thank you very much again and best,
@kergomard

@chfsx

chfsx commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Thanks a lot @kergomard, understood! Done in ce3fbb1:

  • removed all @throws regarding the Excel component (in ilExcel and in the consumers)
  • removed ILIAS\Excel\ExcelException, ilExcel now throws an \ilException with the message of the library
  • removed the wrapped() function, every call to the library has its own try/catch

@kergomard

Copy link
Copy Markdown
Contributor

Thank you so much @chfsx ! I will leave this open until wednesday OCT 28 for anybody to react and I will then merge to make sure it is in ILIAS 12.

@abrahammordev abrahammordev left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the change to Survey!

@chfsx
chfsx merged commit 5e10c64 into ILIAS-eLearning:trunk Oct 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants