Class: XlsxWriter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeXlsxWriter

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

Returns the value of attribute header_footer.



34
35
36
# File 'lib/xlsx_writer.rb', line 34

def header_footer
  @header_footer
end

#imagesObject (readonly)

Returns the value of attribute images.



32
33
34
# File 'lib/xlsx_writer.rb', line 32

def images
  @images
end

#page_setupObject (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_stringsObject (readonly)

Returns the value of attribute shared_strings.



35
36
37
# File 'lib/xlsx_writer.rb', line 35

def shared_strings
  @shared_strings
end

#sheetsObject (readonly)

Returns the value of attribute sheets.



31
32
33
# File 'lib/xlsx_writer.rb', line 31

def sheets
  @sheets
end

#staging_dirObject (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

Raises:

  • (RuntimeError)


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

Raises:

  • (RuntimeError)


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

#cleanupObject



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

#generateObject



100
101
102
103
# File 'lib/xlsx_writer.rb', line 100

def generate
  path
  true
end

#generated?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/xlsx_writer.rb', line 105

def generated?
  @generated == true
end

#pathObject



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

Returns:

  • (Boolean)


54
55
56
# File 'lib/xlsx_writer.rb', line 54

def quiet_booleans?
  @quiet_booleans == true
end