Skip to content

AutoColor for LibreOffice Dark Mode #4503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged

Conversation

oleibman
Copy link
Collaborator

@oleibman oleibman commented Jun 6, 2025

See discussion #4502. I am not sure of what needs to be involved here. This is especially so because Excel also offers AutoColor, but its dark mode looks significantly different than LibreOffice's.

So here's what I've come up with thus far.

  • Add boolean autoColor with setter and getter to Font.
  • If autoColor is true, ODS writer and XLSX Writer will record it in the xml, and will not write a font color. It is possible that both can co-exist; I'm just not sure how they are supposed to interact if that is the case.
  • It makes most sense to me if the spreadsheet's default font specifies autoColor, but PhpSpreadsheet will not insist on that.
  • Xlsx Reader will process autoColor. Like most other styles, Ods Reader is not yet set up to handle it.
  • LibreOffice Calc should follow the autoColor declarations when it reads either an Xlsx or Ods spreadsheet created by PhpSpreadsheet.

This is:

  • a bugfix
  • a new feature
  • refactoring
  • additional unit tests

Checklist:

  • Changes are covered by unit tests
    • Changes are covered by existing unit tests
    • New unit tests have been added
  • Code style is respected
  • Commit message explains why the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
  • CHANGELOG.md contains a short summary of the change and a link to the pull request if applicable
  • Documentation is updated as necessary

See discussion PHPOffice#4502. I am not sure of what needs to be involved here. This is especially so because Excel also offers AutoColor, but its dark mode looks significantly different than LibreOffice's.

So here's what I've come up with thus far.
- Add boolean autoColor with setter and getter to Font.
- If autoColor is true, ODS writer and XLSX Writer will record it in the xml, and will not write a font color. It is possible that both can co-exist; I'm just not sure how they are supposed to interact if that is the case.
- It makes most sense to me if the spreadsheet's default font specifies autoColor, but PhpSpreadsheet will not insist on that.
- Xlsx Reader will process autoColor. Like most other styles, Ods Reader is not yet set up to handle it.
- LibreOffice Calc should follow the autoColor declarations when it reads either an Xlsx or Ods spreadsheet created by PhpSpreadsheet.
@fwiep
Copy link

fwiep commented Jun 7, 2025

Yes! For me, this works exactly as expected.

The generated text has no preset color and is therefore rendered in perfect contrast to the cell's background. Be it dark on light or (as in my case) light on dark.

For my own reference, here's how I tested this PR manually:

  1. clone the PhpSpreadsheet Github repository (git clone "https://github.com/PHPOffice/PhpSpreadsheet.git")
  2. change into the directory (cd PhpSpreadsheet)
  3. install dependencies (composer install)
  4. download PR as patch file by appending .patch to its URL: https://github.com/PHPOffice/PhpSpreadsheet/pull/4503.patch
  5. apply the patch: patch -p 1 < /path/to/4503.patch
  6. add $spreadsheet->getActiveSheet()->getStyle('A')->getFont()->setAutoColor(true); to samples/Basic/01_Simple.php
  7. run sample: php -f samples/Basic/01_Simple.php

In the generated sample, column A has the font color indeed set to Automatic (or at least, is not preset to black).

Thanks! Kind regards,
FWieP

@oleibman oleibman added this pull request to the merge queue Jun 18, 2025
Merged via the queue into PHPOffice:master with commit 0dbe154 Jun 18, 2025
14 checks passed
@oleibman oleibman deleted the issue4502 branch June 18, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants