Class: Workbook::Book
- Inherits:
-
Array
- Object
- Array
- Workbook::Book
- Includes:
- Readers::CsvReader, Readers::TxtReader, Readers::XlsReader, Writers::XlsWriter
- Defined in:
- lib/workbook/book.rb
Constant Summary
Constant Summary
Constants included from Readers::XlsReader
Readers::XlsReader::XLS_COLORS
Constants included from Writers::XlsWriter
Writers::XlsWriter::XLS_COLORS
Instance Attribute Summary (collapse)
-
- (Object) default_rewrite_header
Returns the value of attribute default_rewrite_header.
-
- (Workbook::Format) template
Returns the template describing how the document should be/is formatted.
-
- (String) title
The title of the workbook.
Class Method Summary (collapse)
-
+ (Workbook::Book) open(filename, ext = nil)
Create an instance from a file, using open.
Instance Method Summary (collapse)
- - (Object) create_or_open_sheet_at(index)
- - (Boolean) default_rewrite_header?
-
- (String) file_extension(filename)
The file extension.
- - (Boolean) has_contents?
- - (Workbook::Book) initialize(sheet = Workbook::Sheet.new([], self, options={})) constructor
-
- (Object) open(filename, ext = nil)
Loads an external file into an existing worbook.
-
- (Object) open_binary(filename, ext = nil)
Open the file in binary, read-only mode, do not read it, but pas it throug to the extension determined loaded.
-
- (Object) open_text(filename, ext = nil)
Open the file in non-binary, read-only mode, read it and parse it to UTF-8.
- - (Object) push(sheet = Workbook::Sheet.new)
-
- (Workbook::Sheet) sheet
The first sheet, and creates an empty one if one doesn't exists.
- - (Object) sort
Methods included from Readers::TxtReader
Methods included from Readers::CsvReader
Methods included from Readers::XlsReader
Methods included from Writers::XlsWriter
#format_to_xls_format, #html_color_to_xls_color, #init_spreadsheet_template, #strftime_to_ms_format, #to_xls, #write_to_xls, #xls_sheet, #xls_template
Constructor Details
- (Workbook::Book) initialize(sheet = Workbook::Sheet.new([], self, options={}))
20 21 22 23 24 25 26 |
# File 'lib/workbook/book.rb', line 20 def initialize sheet=Workbook::Sheet.new([], self, ={}) if sheet.is_a? Workbook::Sheet push sheet else push Workbook::Sheet.new(sheet, self, ) end end |
Instance Attribute Details
- (Object) default_rewrite_header
Returns the value of attribute default_rewrite_header
16 17 18 |
# File 'lib/workbook/book.rb', line 16 def default_rewrite_header @default_rewrite_header end |
- (Workbook::Format) template
Returns the template describing how the document should be/is formatted
29 30 31 |
# File 'lib/workbook/book.rb', line 29 def template @template ||= Workbook::Template.new end |
- (String) title
The title of the workbook
40 41 42 |
# File 'lib/workbook/book.rb', line 40 def title @title ? @title : "untitled document" end |
Class Method Details
+ (Workbook::Book) open(filename, ext = nil)
Create an instance from a file, using open.
99 100 101 102 103 |
# File 'lib/workbook/book.rb', line 99 def self.open filename, ext=nil wb = self.new wb.open filename, ext return wb end |
Instance Method Details
- (Object) create_or_open_sheet_at(index)
105 106 107 108 109 110 |
# File 'lib/workbook/book.rb', line 105 def create_or_open_sheet_at index s = self[index] s = self[index] = Workbook::Sheet.new if s == nil s.book = self s end |
- (Boolean) default_rewrite_header?
116 117 118 119 |
# File 'lib/workbook/book.rb', line 116 def default_rewrite_header? return true if default_rewrite_header.nil? default_rewrite_header end |
- (String) file_extension(filename)
The file extension
93 94 95 |
# File 'lib/workbook/book.rb', line 93 def file_extension(filename) File.extname(filename).gsub('.','') end |
- (Boolean) has_contents?
54 55 56 |
# File 'lib/workbook/book.rb', line 54 def has_contents? sheet.has_contents? end |
- (Object) open(filename, ext = nil)
Loads an external file into an existing worbook
61 62 63 64 65 66 67 68 |
# File 'lib/workbook/book.rb', line 61 def open filename, ext=nil ext = file_extension(filename) unless ext if ['txt','csv','xml'].include?(ext) open_text filename, ext else open_binary filename, ext end end |
- (Object) open_binary(filename, ext = nil)
Open the file in binary, read-only mode, do not read it, but pas it throug to the extension determined loaded
73 74 75 76 77 |
# File 'lib/workbook/book.rb', line 73 def open_binary filename, ext=nil ext = file_extension(filename) unless ext f = File.open(filename,'rb') send("load_#{ext}".to_sym,f) end |
- (Object) open_text(filename, ext = nil)
Open the file in non-binary, read-only mode, read it and parse it to UTF-8
82 83 84 85 86 87 88 89 |
# File 'lib/workbook/book.rb', line 82 def open_text filename, ext=nil ext = file_extension(filename) unless ext f = File.open(filename,'r') t = f.read detected_encoding = CharDet.detect(t)['encoding'] t = Iconv.conv("UTF-8//TRANSLIT//IGNORE",detected_encoding,t) send("load_#{ext}".to_sym,t) end |
- (Object) push(sheet = Workbook::Sheet.new)
44 45 46 |
# File 'lib/workbook/book.rb', line 44 def push sheet=Workbook::Sheet.new super(sheet) end |
- (Workbook::Sheet) sheet
The first sheet, and creates an empty one if one doesn't exists
49 50 51 52 |
# File 'lib/workbook/book.rb', line 49 def sheet push Workbook::Sheet.new unless first first end |
- (Object) sort
112 113 114 |
# File 'lib/workbook/book.rb', line 112 def sort raise Exception("Books can't be sorted") end |