spreadsheet icon indicating copy to clipboard operation
spreadsheet copied to clipboard

Formula referencing value in different sheet is broken

Open ausangshukla opened this issue 3 years ago • 8 comments

Formulas in the same sheet work well, but same formula for values in a different sheet break. Essentially sheet name within formulas is not copied in the created sheet.

Ruby 3.1.2 Ubuntu LibreOffice 7.3.2.2

ausangshukla avatar Aug 02 '22 08:08 ausangshukla

  1. hmm, can you share your test script please?
  2. Are you creating a new file or are you modifying an existing one?

zdavatz avatar Aug 02 '22 12:08 zdavatz

test.xls

class XlExporter
    DATA = [["Tim", 20], ["Dan", 30], ["Rich", 40]]
    def self.export
        open_book = Spreadsheet.open('test.xls')
        new_row_index = 0

        header = ["Name", "Age"]
        open_book.worksheet(0).row(new_row_index).concat(header)
        

        DATA.each do |d|
        new_row_index += 1
        open_book.worksheet(0).row(new_row_index).concat( [d[0], d[1]] )

        puts "Wrote row #{new_row_index}"                     
        end

        
        open_book.write('test_new.xls')
    end
end

ausangshukla avatar Aug 03 '22 02:08 ausangshukla

Note that the test.xls has 2 formulas, one on sheet 1 and the other on sheet2, which are exactly the same, ie sum of col B in sheet 1, but the generated XL shows only the sum on sheet 1, and an error on sheet 2.

Please lmk if you need more clarification.

ausangshukla avatar Aug 03 '22 02:08 ausangshukla

which software created the test.xls?

zdavatz avatar Aug 03 '22 12:08 zdavatz

LibreOffice on ubuntu I also tried with XL on windows, same result

ausangshukla avatar Aug 03 '22 12:08 ausangshukla

Try adding the formulas in LibreOffice, then save with LibreOffice, then modify the file with Ruby. Does that work?

zdavatz avatar Aug 03 '22 13:08 zdavatz

Not working using a newly created doc on LibreOffice on Ubuntu. In the result file, it is stripping out the row references from a different sheet, so the formula becomes invalid. So =SUM($Sheet1.B2:B11) becomes =SUM() and hence becomes invalid (See cell A1 in sheet2)

test.xls

I will try with a windows XL also and report it here

ausangshukla avatar Aug 04 '22 02:08 ausangshukla

I suppose you read the guide: https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md

zdavatz avatar Aug 04 '22 07:08 zdavatz