How can I check if a cell contains a formulae?

622 views
Skip to first unread message

Marco Manetti

unread,
May 26, 2014, 10:57:34 AM5/26/14
to python...@googlegroups.com
Hi!

I'm using xlrd and I need to check if a cell contains a formulae...
Do you know a solution or any advice?

Thank you so much!
Marco
Message has been deleted

Max Belkin

unread,
Jun 9, 2014, 7:41:30 AM6/9/14
to python...@googlegroups.com
Hi Marco!

I guess every formulae always starts with symbol '=' and has some more symbols after. I don't know is that right or not but the simpliest way is to read a cell value then check its first symbol and length.

Cheers,
Max

John Yeung

unread,
Jun 9, 2014, 2:01:00 PM6/9/14
to python-excel
On Mon, Jun 9, 2014 at 7:39 AM, Max Belkin
<bernardito.l...@gmail.com> wrote:
> I guess every formulae always starts with symbol '=' and has some more
> symbols after. I don't know is that right or not but the simpliest way is to
> read a cell value then check its first symbol and length.

No, it's not right. Have you even used xlrd at all? Have you read
any xlrd documentation at all?

There's no officially documented way to know if a cell contains a
formula when read by xlrd. I haven't looked at the source code
closely enough to know if there is an undocumented way (there have
been posts suggesting various stages of partial solution), but I doubt
it. When you read a cell with xlrd, it gives you the last saved
evaluated value of that cell.

If your workbook is .xlsx (not .xls), you can try using openpyxl
instead. It seems to be able to read cell formulas. When you open a
workbook, you can choose whether the "value" of a cell is its last
saved evaluated value or its formula text, but for whatever reason,
you can't have both. (Note that some cells may have "shared"
formulas; in this case, you can easily tell that the cell contains a
formula, but it is tricky to get the formula text.)

John Y.

He JinQiang

unread,
Aug 20, 2014, 4:15:26 AM8/20/14
to python...@googlegroups.com
When you read a cell with xlrd, it gives you the last saved 
evaluated value of that cell.


I have been using openpyxl and trying to paste data between worksheets( namely reading evaluated value), always failed and just copied the formula( "=-----").
Maybe I should try with xlrd now, thanks for reminding.
Reply all
Reply to author
Forward
0 new messages