Class: XlsxWriter::Sheet
Constant Summary collapse
- AUTO =
false
Instance Attribute Summary collapse
-
#autofilters ⇒ Object
readonly
Returns the value of attribute autofilters.
-
#freeze_top_left ⇒ Object
Freeze the pane under this top left cell.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Attributes inherited from Xml
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_path ⇒ Object
-
#add_autofilter(range) ⇒ Object
specify range like “A1:C1”.
- #add_row(data) ⇒ Object
-
#initialize(document, name) ⇒ Sheet
constructor
A new instance of Sheet.
- #local_id ⇒ Object
- #ndx ⇒ Object
-
#path ⇒ Object
override Xml method to save memory.
- #relative_path ⇒ Object
-
#rid ⇒ Object
+1 because styles.xml occupies the first spot.
Methods inherited from Xml
#generate, #generated?, #render, #template_path
Constructor Details
#initialize(document, name) ⇒ Sheet
Returns a new instance of Sheet.
24 25 26 27 28 29 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 24 def initialize(document, name) @name = Sheet.excel_name name @rows = [] @autofilters = [] super document end |
Instance Attribute Details
#autofilters ⇒ Object (readonly)
Returns the value of attribute autofilters.
19 20 21 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 19 def autofilters @autofilters end |
#freeze_top_left ⇒ Object
Freeze the pane under this top left cell
22 23 24 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 22 def freeze_top_left @freeze_top_left end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 17 def name @name end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
18 19 20 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 18 def rows @rows end |
Class Method Details
.excel_name(value) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 6 def excel_name(value) str = value.to_s.dup str.gsub! '/', '' # remove forward slashes str.gsub! /\s+/, '' # compress "inner" whitespace str.strip! # trim whitespace from ends str.fast_xs end |
Instance Method Details
#absolute_path ⇒ Object
48 49 50 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 48 def absolute_path "/#{relative_path}" end |
#add_autofilter(range) ⇒ Object
specify range like “A1:C1”
53 54 55 56 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 53 def add_autofilter(range) raise ::RuntimeError, "Can't add autofilter, already generated!" if generated? autofilters << Autofilter.new(self, range) end |
#add_row(data) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 58 def add_row(data) raise ::RuntimeError, "Can't add row, already generated!" if generated? row = Row.new self, data rows << row row end |
#local_id ⇒ Object
35 36 37 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 35 def local_id ndx - 1 end |
#ndx ⇒ Object
31 32 33 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 31 def ndx document.sheets.index(self) + 1 end |
#path ⇒ Object
override Xml method to save memory
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 66 def path @path || @mutex.synchronize do @path ||= begin memo = ::File.join document.staging_dir, relative_path ::FileUtils.mkdir_p ::File.dirname(memo) ::File.open(memo, 'wb') do |f| to_file f end converted = UnixUtils.unix2dos memo ::FileUtils.mv converted, memo SheetRels.new(document, self).path @generated = true memo end end end |
#relative_path ⇒ Object
44 45 46 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 44 def relative_path "xl/worksheets/sheet#{ndx}.xml" end |
#rid ⇒ Object
+1 because styles.xml occupies the first spot
40 41 42 |
# File 'lib/xlsx_writer/generators/sheet.rb', line 40 def rid "rId#{ndx + 1}" end |