On 21 Feb 2023, at 13:00, Matthew Hegarty wrote:
I've read that prepending
quote to an excel field will force the formula to be written as a string.
I've read through existing issues and searched the forum. This issue has
come up before
Openpyxl has always followed Excel's practice of treating strings that start with =
as formulae. This is very convenient and probably suitable in 99.9% of the cases. It doesn't do any additional processing or validation of formulae, though it does at least now check that formulae are syntactically correct. And, as it doesn't evaluate formulae itself, it's immune from any such poisoning.
but AFAICT it was not implemented yet?
It's not openpyxl's job to do this and I'm not going to maintain any code that would. It's fairly straightforward to write a monkey patch that would work this; my suggestion would be to strip the =
from the start of a string and rebind cell.value = cell.value.replace("=", "") if cell.data_type is "f" and if cell.value.startswith("f")
.
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226