GradientFill stops should not have position determined by `enumerate`

Issue #771 resolved
created an issue

The following gradientFill renders fine in Excel

      <gradientFill type="linear">
          <stop position="0"><color rgb="FFC6C6C6" /></stop>
          <stop position=".3"><color rgb="FFFFFFFF" /></stop>
          <stop position="1"><color rgb="FFFFC6C6" /></stop>

OpenPyxl currently only supports a list of gradient stops being colours, which are then enumerated to determine their position. This implies that at most two stops (the endpoints) are acceptable.

It should be possible to specify stops as (position, color).

Comments (8)

  1. CharlieC

    Thanks for the report. The specification isn't very clear on this and a discussion with the OOXML group didn't really help so the current implementation is based on best guess. It would need reworking to support non-linear positioning but I would be happy to accept a PR, based on the 2.5 branch, that does this as long as it comes with documentation on how to use it. At the moment I think the current approach of supplying a list of three colours works for most people.

  2. jnothman reporter

    If you could advise what x should be in stop = ValueSequence(expected_type=x, ...) to allow either a Color or a (float, Color) pair, that would be appreciated.

  3. CharlieC

    You should simply create a Stop class and use a Sequence. I created ValueSequence to make working with single value elements <b val=True />easier. That will no longer be possible here.

  4. CharlieC

    The code will be easy but the docs will be more of a challenge. You might also want to look at some kind of default behaviour (look at how colours) are handled so that it would still be possible to pass in a list of colours — though I'm no longer sure that this is the correct behaviour.

  5. CharlieC

    Just a note - Excel on MacOS has no GUI controls for working with GradientFills so I can't myself create any sample gradients for the docs or tests.

  6. Log in to comment