pyoo
pyoo copied to clipboard
Inserting rows causes cell indexing errors
Inserting rows seems to break the indexing of later cell referencing.
This sample code captures the problem:
import pyoo
desktop = pyoo.Desktop(pipe="pyoo_pipe")
doc_st = desktop.create_spreadsheet()
sheet = doc_st.sheets[0]
n = 3
r = 1
t = "B%d" % (r + n + 1)
print("Setting '%s' at %d, %d" % (t, r, 1))
# Doing this causes the bug:
sheet[r, 1].value = t
# If we also do this work-round, it fixes the problem:
#sheet[(0, 0)].value = ""
print("Inserting %d rows at index %d" % (n, r))
sheet._target.Spreadsheet.Rows.insertByIndex(r, n)
r = 1
t = "A%d" % (r + 1)
print("Setting '%s' at %d, %d" % (t, r, 0))
sheet[r, 0].value = t
doc_st.save("./bug.ods")
doc_st.close()
The expected result is 'A2' in cell A2 and 'B5' in cell B5. What I actually see is 'A2' in cell A5 and 'B5' in cell B5.
A work-round is to set a dummy value in cell A1 after doing the row insertion. Uncomment the indicated line, the problem goes away, i.e. the actual result matches the expected result.