axlsx
axlsx copied to clipboard
Getting full cell range of sheet
For a sheet, how can we get the full range of a sheet?
In other words, how do we get the left-top-most cell (presumably A1) and the right-bottom-most cell (e.g. G10).
Basically, I'd like to get a string back like "A1:G10"
I'd like to be able to easily add an autofilter to an entire sheet (which is tabular data).
Thanks,
I believe there is no nice way to get the right-bottom cell.
I've done this in a completely ugly way which is ....
def right_bottom_ref(cols,rows)
row_ref = rows.to_s
col_ref = 'A'
(cols-1).times{col_ref.next!}
return "A1:#{col_ref}#{row_ref}"
end
p.workbook.add_worksheet(:name => 'sample') do |sheet|
# add some rows
ref = right_bottom_ref sheet.cols.length, sheet.rows.length
sheet.add_table(ref, :name => 'sample', :style_info => { :name => "TableStyleMedium21" })
end
I'd like to make something like "Worksheet#right_bottom" if feasible.
What about the following, assuming sheet
is a Worksheet?
'A1:' + sheet.rows[-1].cells[-1].reference