I'm using the axlsx gem to create a XLSX file and have the following line in my code:
ws.add_row( "xyz" )
Is there a way to get the row index of the row I had just added? I might have to add a row later.
I use these two methods for doing it:
wb = xlsx_package.workbook
wb.add_worksheet(name: 'sheet 1') do |sheet|
sheet.add_row ['foo', 'bar']
my_first_row = sheet.add_row ['aladdin', 'rules']
my_second_row = sheet.add_row ['hello', 'world']
# Method 1
sheet.rows.index(my_first_row) # will return 1
sheet.rows.index(my_second_row) # will return 2
# Method 2
my_first_row.row_index # will return 1
my_second_row.row_index # will return 2
end
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With