Class: LXL::Range
- Inherits:
-
Range
- Object
- Range
- LXL::Range
- Defined in:
- lib/lxl.rb
Overview
Excel-style ranges.
Recognized formats
B3 | B3: | B3:D5 | Sheet1!B3:D5 | [Book1]Sheet1!B3:D5 | [file.xls]Sheet1!B3:D5
(the first two become B3:B3)
Collection
# Ruby Range
Range.new("B3", "D5").collect
# => ["B3", "B4", "B5", "B6", "B7", "B8", "B9",
"C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9",
"D0", "D1", "D2", "D3", "D4", "D5"]
# LXL Range
LXL::Range.new("B3", "D5").collect
# => ["B3", "B4", "B5", "C3", "C4", "C5", "D3", "D4", "D5"]
Constant Summary collapse
- EXCEL_RANGE =
/\A(\[([\w\.]+)\])?((\w+)!)?([A-Z]+[1-9]+)(:([A-Z]+[1-9]+)?)?/i
Instance Attribute Summary collapse
-
#book ⇒ Object
Workbook name.
-
#sheet ⇒ Object
Worksheet name.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
- #excel! ⇒ Object
- #excel? ⇒ Boolean
- #first_cell ⇒ Object
- #first_colnum ⇒ Object
- #first_column ⇒ Object
- #last_cell ⇒ Object
- #last_colnum ⇒ Object
- #last_column ⇒ Object
Instance Attribute Details
#book ⇒ Object
Workbook name.
387 388 389 |
# File 'lib/lxl.rb', line 387 def book @book end |
#sheet ⇒ Object
Worksheet name.
390 391 392 |
# File 'lib/lxl.rb', line 390 def sheet @sheet end |
Class Method Details
.new(first, last) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/lxl.rb', line 392 def self.new(first, last) excel = (first =~ EXCEL_RANGE && last =~ EXCEL_RANGE) if excel first =~ EXCEL_RANGE book,sheet,first = $2,$4,$5 obj = super(*[first.upcase,last.upcase].sort) obj.excel! obj.book = book obj.sheet = sheet obj else super end end |
Instance Method Details
#each ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/lxl.rb', line 439 def each if excel? (first_column..last_column).each do |column| (first_cell..last_cell).each do |cell| yield column+cell.to_s end end else super end end |
#excel! ⇒ Object
407 408 409 |
# File 'lib/lxl.rb', line 407 def excel! @excel = true end |
#excel? ⇒ Boolean
411 412 413 |
# File 'lib/lxl.rb', line 411 def excel? @excel ? true : false end |
#first_cell ⇒ Object
431 432 433 |
# File 'lib/lxl.rb', line 431 def first_cell first.to_s.gsub(/[^1-9]/,'').to_i end |
#first_colnum ⇒ Object
423 424 425 |
# File 'lib/lxl.rb', line 423 def first_colnum LXL.xlcolnum(first_column) end |
#first_column ⇒ Object
415 416 417 |
# File 'lib/lxl.rb', line 415 def first_column first.to_s.upcase.gsub(/[^A-Z]/,'') end |
#last_cell ⇒ Object
435 436 437 |
# File 'lib/lxl.rb', line 435 def last_cell last.to_s.gsub(/[^1-9]/,'').to_i end |
#last_colnum ⇒ Object
427 428 429 |
# File 'lib/lxl.rb', line 427 def last_colnum LXL.xlcolnum(last_column) end |
#last_column ⇒ Object
419 420 421 |
# File 'lib/lxl.rb', line 419 def last_column last.to_s.upcase.gsub(/[^A-Z]/,'') end |