Module: Workbook::Writers::HtmlWriter

Included in:
Book
Defined in:
lib/workbook/writers/html_writer.rb

Instance Method Summary collapse

Instance Method Details

#to_html(options = {}) ⇒ String

Generates an HTML table ()

Parameters:

  • options (Hash) (defaults to: {})

    A hash with options

Returns:

  • (String)

    A String containing the HTML code



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/workbook/writers/html_writer.rb', line 15

def to_html options={}
  builder = Nokogiri::XML::Builder.new do |doc|
    doc.html {
      doc.body {
        self.each{|sheet|
          doc.h1 {
            doc.text sheet.name
          }
          sheet.each{|table|
            doc.h2 {
              doc.text table.name
            }
            doc << table.to_html(options)
          }
        }
      }
    }
  end
  return builder.doc.to_xhtml
end

#write_to_html(filename = "#{title}.html", options = {}) ⇒ String

Write the current workbook to HTML format

Parameters:

  • filename (String) (defaults to: "#{title}.html")
  • options (Hash) (defaults to: {})

    see #to_xls

Returns:

  • (String)

    filename



42
43
44
45
# File 'lib/workbook/writers/html_writer.rb', line 42

def write_to_html filename="#{title}.html", options={}
  File.open(filename, 'w') {|f| f.write(to_html(options)) }
  return filename
end