Class: SpreadsheetSpreadsheet
- Inherits:
-
AbstractSpreadsheet
- Object
- AbstractSpreadsheet
- SpreadsheetSpreadsheet
- Includes:
- WritableSpreadsheet
- Defined in:
- lib/tmis/engine/import/spreadsheet_roo.rb
Instance Attribute Summary collapse
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
Instance Method Summary collapse
-
#[](r, c) ⇒ Object
Contract Pos, Pos => Any.
-
#[]=(r, c, obj) ⇒ Object
Contract Pos, Pos, Any => Any.
-
#column(n) ⇒ Object
Contract Pos => Any.
- #format(r, c, fmt) ⇒ Object
-
#initialize(filepath) ⇒ SpreadsheetSpreadsheet
constructor
Contract String => Any.
-
#last_column ⇒ Object
Contract None => Pos.
-
#last_row ⇒ Object
Contract None => Pos.
- #merge(start_row, start_col, end_row, end_col) ⇒ Object
-
#row(n) ⇒ Object
Contract Pos => Any.
-
#save ⇒ Object
Contract None => Any.
-
#sheet(number) ⇒ Object
Contract Not => Any.
Constructor Details
#initialize(filepath) ⇒ SpreadsheetSpreadsheet
Contract String => Any
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 59 def initialize(filepath) @filepath = filepath.force_encoding("UTF-8") Spreadsheet.client_encoding = 'UTF-8' if File.file?(@filepath) @book = Spreadsheet.open(@filepath) else @book = Spreadsheet::Workbook.new(@filepath) @book.create_worksheet end @sheet = @book.worksheet(0) fmt = Spreadsheet::Format.new text_wrap: true fmt.horizontal_align = :center fmt.vertical_align = :middle fmt.font = Spreadsheet::Font.new('Times New Roman', :size => 12) @sheet.default_format = fmt @sheet end |
Instance Attribute Details
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
56 57 58 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 56 def filepath @filepath end |
Instance Method Details
#[](r, c) ⇒ Object
Contract Pos, Pos => Any
103 104 105 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 103 def [](r, c) @sheet[r - 1, c - 1] end |
#[]=(r, c, obj) ⇒ Object
Contract Pos, Pos, Any => Any
108 109 110 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 108 def []=(r, c, obj) @sheet[r - 1, c - 1] = obj end |
#column(n) ⇒ Object
Contract Pos => Any
98 99 100 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 98 def column(n) @sheet.column(n - 1) end |
#format(r, c, fmt) ⇒ Object
122 123 124 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 122 def format(r, c, fmt) @sheet.row(r - 1).set_format(c - 1, fmt) end |
#last_column ⇒ Object
Contract None => Pos
83 84 85 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 83 def last_column @sheet.column_count end |
#last_row ⇒ Object
Contract None => Pos
78 79 80 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 78 def last_row @sheet.last_row_index end |
#merge(start_row, start_col, end_row, end_col) ⇒ Object
118 119 120 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 118 def merge(start_row, start_col, end_row, end_col) @sheet.merge_cells(start_row - 1, start_col - 1, end_row - 1, end_col - 1) end |
#row(n) ⇒ Object
Contract Pos => Any
93 94 95 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 93 def row(n) @sheet.row(n - 1) end |
#save ⇒ Object
Contract None => Any
113 114 115 116 |
# File 'lib/tmis/engine/import/spreadsheet_roo.rb', line 113 def save @book.write("#{@filepath}_temp") FileUtils.mv("#{@filepath}_temp", @filepath) # Обход бага в библиотеке end |