Class: XlsxWriter
- Inherits:
-
Object
- Object
- XlsxWriter
- Defined in:
- lib/xlsx_writer.rb,
lib/xlsx_writer/row.rb,
lib/xlsx_writer/xml.rb,
lib/xlsx_writer/cell.rb,
lib/xlsx_writer/sheet.rb,
lib/xlsx_writer/version.rb,
lib/xlsx_writer/xml/app.rb,
lib/xlsx_writer/xml/rels.rb,
lib/xlsx_writer/xml/image.rb,
lib/xlsx_writer/autofilter.rb,
lib/xlsx_writer/page_setup.rb,
lib/xlsx_writer/xml/styles.rb,
lib/xlsx_writer/xml/workbook.rb,
lib/xlsx_writer/header_footer.rb,
lib/xlsx_writer/xml/doc_props.rb,
lib/xlsx_writer/shared_strings.rb,
lib/xlsx_writer/xml/sheet_rels.rb,
lib/xlsx_writer/xml/vml_drawing.rb,
lib/xlsx_writer/xml/content_types.rb,
lib/xlsx_writer/xml/workbook_rels.rb,
lib/xlsx_writer/xml/vml_drawing_rels.rb
Defined Under Namespace
Classes: App, Autofilter, Cell, ContentTypes, DocProps, HeaderFooter, Image, PageSetup, Rels, Row, SharedStrings, Sheet, SheetRels, Styles, VmlDrawing, VmlDrawingRels, Workbook, WorkbookRels, Xml
Constant Summary collapse
- Document =
backwards compatibility
XlsxWriter
- VERSION =
'0.4.4'
Instance Attribute Summary collapse
-
#header_footer ⇒ Object
readonly
Returns the value of attribute header_footer.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#page_setup ⇒ Object
readonly
Returns the value of attribute page_setup.
-
#shared_strings ⇒ Object
readonly
Returns the value of attribute shared_strings.
-
#sheets ⇒ Object
readonly
Returns the value of attribute sheets.
-
#staging_dir ⇒ Object
readonly
Returns the value of attribute staging_dir.
Instance Method Summary collapse
- #add_image(path, width, height) ⇒ Object
- #add_sheet(name) ⇒ Object
- #cleanup ⇒ Object
- #generate ⇒ Object
- #generated? ⇒ Boolean
-
#initialize ⇒ XlsxWriter
constructor
A new instance of XlsxWriter.
- #path ⇒ Object
-
#quiet_booleans! ⇒ Object
Instead of TRUE or FALSE, show TRUE and blank if false.
- #quiet_booleans? ⇒ Boolean
Constructor Details
#initialize ⇒ XlsxWriter
Returns a new instance of XlsxWriter.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xlsx_writer.rb', line 37 def initialize @mutex = Mutex.new staging_dir = UnixUtils.tmp_path 'xlsx_writer' FileUtils.mkdir_p staging_dir @staging_dir = staging_dir @sheets = [] @images = [] @page_setup = PageSetup.new @header_footer = HeaderFooter.new @shared_strings = SharedStrings.new self end |
Instance Attribute Details
#header_footer ⇒ Object (readonly)
Returns the value of attribute header_footer.
34 35 36 |
# File 'lib/xlsx_writer.rb', line 34 def @header_footer end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
32 33 34 |
# File 'lib/xlsx_writer.rb', line 32 def images @images end |
#page_setup ⇒ Object (readonly)
Returns the value of attribute page_setup.
33 34 35 |
# File 'lib/xlsx_writer.rb', line 33 def page_setup @page_setup end |
#shared_strings ⇒ Object (readonly)
Returns the value of attribute shared_strings.
35 36 37 |
# File 'lib/xlsx_writer.rb', line 35 def shared_strings @shared_strings end |
#sheets ⇒ Object (readonly)
Returns the value of attribute sheets.
31 32 33 |
# File 'lib/xlsx_writer.rb', line 31 def sheets @sheets end |
#staging_dir ⇒ Object (readonly)
Returns the value of attribute staging_dir.
30 31 32 |
# File 'lib/xlsx_writer.rb', line 30 def staging_dir @staging_dir end |
Instance Method Details
#add_image(path, width, height) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/xlsx_writer.rb', line 68 def add_image(path, width, height) raise RuntimeError, "Can't add image, already generated!" if generated? image = Image.new self, path, width, height images << image image end |
#add_sheet(name) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/xlsx_writer.rb', line 58 def add_sheet(name) raise RuntimeError, "Can't add sheet, already generated!" if generated? ndx = sheets.length + 1 sheet = Sheet.new self, name, ndx sheets << sheet sheet end |
#cleanup ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/xlsx_writer.rb', line 91 def cleanup @mutex.synchronize do FileUtils.rm_rf @staging_dir FileUtils.rm_f @path @path = nil @generated = false end end |
#generate ⇒ Object
100 101 102 103 |
# File 'lib/xlsx_writer.rb', line 100 def generate path true end |
#generated? ⇒ Boolean
105 106 107 |
# File 'lib/xlsx_writer.rb', line 105 def generated? @generated == true end |
#path ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/xlsx_writer.rb', line 75 def path @path || @mutex.synchronize do @path ||= begin sheets.each { |sheet| sheet.generate } images.each { |image| image.generate } shared_strings.generate Xml.auto.each { |part| part.new(self).generate } with_zip_extname = UnixUtils.zip staging_dir with_xlsx_extname = with_zip_extname.sub(/.zip$/, '.xlsx') FileUtils.mv with_zip_extname, with_xlsx_extname @generated = true with_xlsx_extname end end end |
#quiet_booleans! ⇒ Object
Instead of TRUE or FALSE, show TRUE and blank if false
50 51 52 |
# File 'lib/xlsx_writer.rb', line 50 def quiet_booleans! @quiet_booleans = true end |
#quiet_booleans? ⇒ Boolean
54 55 56 |
# File 'lib/xlsx_writer.rb', line 54 def quiet_booleans? @quiet_booleans == true end |