What is the correct way to interact with a formula / error cell when reading?

33 views
Skip to first unread message

Xavier Morel

unread,
Jul 9, 2021, 3:58:37 AM7/9/21
to openpyxl-users
Cells have a `data_type` attribute which contains a typecode, however the symbolic names (constants) for those typecodes are apparently private as they got moved around a while back with a note that they're "only used internally": https://foss.heptapod.net/openpyxl/openpyxl/-/commit/d46a102dabcde1410d7f16f16f445a40b8ec6d15 so relying on them seems... iffy.

These also seem to be mentioned pretty much nowhere outside of the extracted APIDoc, and they're not exactly  brimming with docstrings.

Thus what is the correct way to know if a cell is a formula, or an error when opening in data_only mode? Using the typecodes anyway? Using the constants and handling the move if necessary? Other?

Thanks.

Charlie Clark

unread,
Jul 9, 2021, 7:43:46 AM7/9/21
to 'Xavier Morel' via openpyxl-users

On 9 Jul 2021, at 9:58, 'Xavier Morel' via openpyxl-users wrote:

Cells have a data_type attribute which contains a typecode, however the
symbolic names (constants) for those typecodes are apparently private as
they got moved around a while back with a note that they're "only used
internally":

https://foss.heptapod.net/openpyxl/openpyxl/-/commit/d46a102dabcde1410d7f16f16f445a40b8ec6d15

so relying on them seems... iffy.

Openpyxl itself relies generally on Python types, the data type values are used only when going to and from XML and you can overwrite them if you like: some times this is necessary.

These also seem to be mentioned pretty much nowhere outside of the
extracted APIDoc, and they're not exactly brimming with docstrings.

That's because I'm not a huge fan of docstrings: they're difficult to test and keep up to date: unit tests are much more useful.

Thus what is the correct way to know if a cell is a formula, or an error
when opening in data_only mode? Using the typecodes anyway? Using the
constants and handling the move if necessary? Other?

In data-only mode there will never be any formulae, cells marked as errors will contain the relevant error code.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Waldlehne 23
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226

Xavier Morel

unread,
Jul 9, 2021, 10:14:36 AM7/9/21
to openpyxl-users

Cells have a data_type attribute which contains a typecode, however the
symbolic names (constants) for those typecodes are apparently private as
they got moved around a while back with a note that they're "only used
internally":

https://foss.heptapod.net/openpyxl/openpyxl/-/commit/d46a102dabcde1410d7f16f16f445a40b8ec6d15

so relying on them seems... iffy.

Openpyxl itself relies generally on Python types, the data type values are used only when going to and from XML and you can overwrite them if you like: some times this is necessary.

Yup, I'd seen that and it's pretty nice.

These also seem to be mentioned pretty much nowhere outside of the
extracted APIDoc, and they're not exactly brimming with docstrings.

That's because I'm not a huge fan of docstrings: they're difficult to test and keep up to date: unit tests are much more useful.

Thus what is the correct way to know if a cell is a formula, or an error
when opening in data_only mode? Using the typecodes anyway? Using the
constants and handling the move if necessary? Other?

In data-only mode there will never be any formulae, cells marked as errors will contain the relevant error code.

Right, I guess I'm not clear enough: I was wondering what the proper way to check for the cell's type is when the "python type" carries no information (formula & error, possibly others) e.g. check the typecode directly (the string values), or check against the constants and handle the part where they moved around between versions, or something else. I didn't see any predicates similar to `is_date` so that seems out.
Reply all
Reply to author
Forward
0 new messages