使用Ruby Spreadsheet更新特定单元格

时间:2014-09-25 16:28:18

标签: ruby

我正在使用gem“电子表格”我正在尝试将特定单元格(例如row(0).column(4))更新为新值。我能够通过使用insert方法获得一些东西但是将已经在单元格中的内容移动到正确的一个单元格。

我试过了:

book.worksheet(0).row(0).column(0).update "Payable"

但该列方法不存在。我可能错过了一些特定的东西,但是查看电子表格github页面上的文档,我显然只是遗漏了一些东西。

1 个答案:

答案 0 :(得分:3)

require 'spreadsheet'

book = Spreadsheet.open './spreadsheet.xls'
sheet = book.worksheet 0
sheet.rows[0][0] = 'hello'
             #^--- column
book.write './spreadsheet-output.xls'

请参阅此处修改现有文档:

https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md#modifying-an-existing-document

这对我也有用:

sheet = book.worksheet 0
sheet[1,0] = 'goodbye'
#row--^ ^--column

就像这样:

book.worksheet(0).row(2)[0] = 'mars'
                        #^----column
相关问题