diff options
| author | Randy Morgan <[email protected]> | 2012-07-14 19:51:59 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-07-14 19:51:59 +0900 |
| commit | 46c67de5cc3d8a1350fc3cf0773b2d56b019f960 (patch) | |
| tree | e381f6d9e3c994d6da4322a4ce64783d2a6fa255 | |
| parent | 85cb12036c6cb8c71851b6751709d945b7da4cf9 (diff) | |
| download | caxlsx-46c67de5cc3d8a1350fc3cf0773b2d56b019f960.tar.gz caxlsx-46c67de5cc3d8a1350fc3cf0773b2d56b019f960.zip | |
refactor dimension calculations because it is _NOT_ readable code
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 68ae2e03..54f42553 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -274,11 +274,10 @@ module Axlsx # but at least a few other document readers expect this for conversion # @return [String] the A1:B2 style reference for the first and last row column intersection in the workbook def dimension - dim_start = rows.first.cells.first == nil ? 'A1' : rows.first.cells.first.r - dim_end = rows.last.cells.last == nil ? 'AA200' : rows.last.cells.last.r - "#{dim_start}:#{dim_end}" + "#{dimension_reference(rows.first.cells.first, 'A1')}:#{dimension_reference(rows.last.cells.last, 'AA200')}" end + # # Indicates if gridlines should be shown in the sheet. # This is true by default. # @return [Boolean] @@ -707,11 +706,9 @@ module Axlsx str << '</dataValidations>' end - # assigns the owner workbook for this worksheet def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end - # TODO this needs cleanup! def update_column_info(cells, widths=[], style=[]) styles = self.workbook.styles @@ -743,5 +740,10 @@ module Axlsx font_scale = (sz/10.0).to_f ((text.count(Worksheet.thin_chars) * mdw + 5) / mdw * 256) / 256.0 * font_scale end + + def dimension_reference(cell, default) + return default unless cell.respond_to?(:r) + cell.r + end end end |
