question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

References to other cells

See original GitHub issue

I am using Python 3.8.5 (Mac OS) and open the resulting xlsx files with LibreOffice 6.4.5.2 and Apple Numbers 10.1 (6913) (sorry, I have no MS Excel installed).

I am trying to add formulas that refer to other cells (both cross-sheet and within the same sheet), but they do not work. Here is some code that demonstrates the problem:

#!/usr/bin/env python3

# % locale
# LANG="ru_RU.UTF-8"
# LC_COLLATE="ru_RU.UTF-8"
# LC_CTYPE="ru_RU.UTF-8"
# LC_MESSAGES="ru_RU.UTF-8"
# LC_MONETARY="ru_RU.UTF-8"
# LC_NUMERIC="ru_RU.UTF-8"
# LC_TIME="ru_RU.UTF-8"
# LC_ALL=

# pip install XlsxWriter==1.2.9
import xlsxwriter

wb = xlsxwriter.Workbook('xlsx_bug.xlsx')
sheet1 = wb.add_worksheet("Sheet 1")
sheet2 = wb.add_worksheet("Sheet 2")

sheet2.write(0, 0, 'Cell 2')
sheet1.write_formula(0, 0, "='Sheet 2'.A1")
sheet1.write_formula(1, 0, "='Sheet 2'!A1")
wb.close()

If I higlight the A1 or A2 cell on Sheet 1 and press F4 (it changes a cell reference from absolute to relative), both formulas start to work.

The same could be done on the markup level by changing the following syntax:

<c r="A2"><f>'Sheet 2'!A1</f><v>0</v></c>

to this one:

<c r="A2"><f>'Sheet 2'!A1</f></c>

And this is how the cell looks like when saved by LibreOffice:

<c r="A2" s="0" t="str"><f aca="false">&apos;Sheet 2&apos;!A1</f><v>Cell 2</v></c>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jmcnamaracommented, Aug 3, 2020

Thanks for letting me know. I’ve updated the FAQ with this workaround as well: https://xlsxwriter.readthedocs.io/faq.html

1reaction
jmcnamaracommented, Jul 30, 2020

Or alternatively, remove the <v>0</> from the markup so the formulas are always recalculated?

That isn’t an option since it would break compatibility with Excel.

As a alternative you could specify a blank as the result of the calculation. That should force a recalculation in OpenOffice (based on my testing) without needing the “Recalculation on File Load setting”:

import xlsxwriter

wb = xlsxwriter.Workbook('xlsx_bug.xlsx')
sheet1 = wb.add_worksheet("Sheet 1")
sheet2 = wb.add_worksheet("Sheet 2")

sheet2.write(0, 0, 'Cell 2')
sheet1.write_formula(0, 0, "='Sheet 2'!A1", None, '')
sheet1.write_formula(1, 0, "='Sheet 2'!A1", None, '')

wb.close()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use cell references in a formula - Microsoft Support
Use cell references in a formula · Click the cell in which you want to enter the formula. · In the formula bar...
Read more >
Absolute, Relative, and Mixed Cell References in Excel
What are Absolute Cell References in Excel? ... Unlike relative cell references, absolute cell references don't change when you copy the formula to...
Read more >
Excel Formulas: Relative and Absolute Cell References
There are two types of cell references: relative and absolute. Relative and absolute references behave differently when copied and filled to other cells....
Read more >
Cell References in Excel | 3 Types Explained With an Example
A cell reference in Excel refers to other cells to a cell to use its values or properties. So in simple terms, if...
Read more >
Excel cell reference explained - Ablebits
A cell reference or cell address is a combination of a column letter and a row number that identifies a cell on a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found