sheets: deleting a row or column leaves formulas pointing at whatever slid into its place · Issue #658 · cloudflare/cloudflare-os · GitHub
Skip to content

sheets: deleting a row or column leaves formulas pointing at whatever slid into its place #658

Open

Description

@Cintu07

still there on main as of 5cae880

put 10, 20, 30 in a1:a3 and =a2 in b1. delete row 2. b1 still says =a2 and now shows 30, excel and google sheets both give #REF! here. nothing tells you the number changed which is the bad part

ranges do the same thing. 1, 2, 3, 100 in a1:a4 and =sum(a1:a3) somewhere, delete row 3 and the formula stays =sum(a1:a3) so it shows 103 instead of shrinking to a1:a2. columns have the exact same problem

cause is in adjustRef. deleteRows calls rewriteAllFormulas(at + count, -count, 0, 0) and adjustRef only shifts a ref when r >= rowAt, so a ref inside the deleted block is never touched and then rebuildSheetCells moves the next row into its spot. the return "#REF!" line in there looks like it was ment for exactly this but r cant go negative on that path so it never fires

two smaller things in the same function

  • every insert or delete drops the $ from every formula on the sheet becuase the ref gets rebuilt with rcToRef. =$a$12 turns into =a12 even if a1 didnt move, and thats what xlsx export writes out
  • in Sheet2!a1:a5 only the first end has the sheet name, so a5 gets shifted when sheet1 loses a row and it becomes Sheet2!a1:a4

repro

  1. new sheet, a1:a3 = 10, 20, 30, b1 = =a2
  2. select row 2, delete row(s)
  3. b1 shows 30

i have a fix here Cintu07@5805abc3 . adjustRef now moves each edge of the span a ref bounds, an edge on a deleted line moves in to the nearest surviving line, a span with nothing left becomes #REF!, a range naming another sheet is left alone and $ is kept. its 32+/17- in client.ts so its over the 30 line limit, happy to open a pr if you want it or split the $ part out

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions