Module: Writexlsx::Worksheet::Selection
- Included in:
- Writexlsx::Worksheet
- Defined in:
- lib/write_xlsx/worksheet/selection.rb
Overview
Selection-related operations extracted from Worksheet to slim the main class.
Instance Method Summary collapse
-
#set_selection(*args) ⇒ Object
:call-seq: set_selection(cell_or_cell_range).
Instance Method Details
#set_selection(*args) ⇒ Object
:call-seq:
set_selection(cell_or_cell_range)
Set which cell or cells are selected in a worksheet.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/write_xlsx/worksheet/selection.rb', line 13 def set_selection(*args) return if args.empty? if (row_col_array = row_col_notation(args.first)) row_first, col_first, row_last, col_last = row_col_array else row_first, col_first, row_last, col_last = args end active_cell = xl_rowcol_to_cell(row_first, col_first) if row_last # Range selection. # Swap last row/col for first row/col as necessary row_first, row_last = row_last, row_first if row_first > row_last col_first, col_last = col_last, col_first if col_first > col_last sqref = xl_range(row_first, row_last, col_first, col_last) else # Single cell selection. sqref = active_cell end # Selection isn't set for cell A1. return if sqref == 'A1' @selections = [[nil, active_cell, sqref]] end |