Class: Ekylibre::Export::OpenDocument::Spreadsheet

Inherits:
Object
  • Object
show all
Defined in:
lib/ekylibre/export/open_document/spreadsheet.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|zile| ... } ⇒ Spreadsheet

Returns a new instance of Spreadsheet.

Yields:

  • (zile)

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ekylibre/export/open_document/spreadsheet.rb', line 9

def initialize
  @header = ''
  zile.put_next_entry('META-INF/manifest.xml')
  zile.puts('<?xml version="1.0" encoding="UTF-8"?><manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"><manifest:file-entry manifest:media-type="' + Mime::ODS + '" manifest:full-path="/"/><manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/><manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/></manifest:manifest>')
  zile.put_next_entry('mimetype')
  zile.puts(Mime::ODS)
  zile.put_next_entry('styles.xml')
  zile.puts(File.open(File.join(__dir__, 'spreadsheet', 'styles.xml'), 'rb:UTF-8').read)
  zile.put_next_entry('content.xml')
  zile.puts('<?xml version="1.0" encoding="UTF-8"?><office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:field="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0" office:version="1.1"><office:scripts/>')
  zile.puts('<office:automatic-styles>' + # "<style:style style:name=\"co1\" style:family=\"table-column\"><style:table-column-properties fo:break-before=\"auto\" style:use-optimal-column-width=\"true\"/></style:style>"+
            "<style:style style:name=\"header\" style:family=\"table-cell\"><style:text-properties fo:font-size=\"#{font_size}pt\" style:font-size-asian=\"#{font_size}pt\" style:font-size-complex=\"#{font_size}pt\" fo:font-weight=\"bold\" style:font-weight-asian=\"bold\" style:font-weight-complex=\"bold\"/><style:table-cell-properties fo:border=\"0.002cm solid #000000\"/></style:style>"\
            "<style:style style:name=\"ce1\" style:family=\"table-cell\"><style:text-properties fo:font-size=\"#{font_size}pt\" style:font-size-asian=\"#{font_size}pt\" style:font-size-complex=\"#{font_size}pt\"/><style:table-cell-properties fo:border=\"0.002cm solid #000000\"/></style:style>" + #  fo:wrap-option=\"wrap\"
            "<style:style style:name=\"ce2\" style:family=\"table-cell\"><style:text-properties fo:font-size=\"#{font_size}pt\" style:font-size-asian=\"#{font_size}pt\" style:font-size-complex=\"#{font_size}pt\"/><style:table-cell-properties style:text-align-source=\"fix\" style:repeat-content=\"false\" fo:border=\"0.002cm solid #000000\"/><style:paragraph-properties fo:text-align=\"center\" fo:margin-left=\"0cm\"/></style:style>"\
            '<style:style style:name="ta1" style:family="table" style:master-page-name="Default"><style:table-properties table:display="true" style:writing-mode="lr-tb"/></style:style>'\
            "<style:style style:name=\"ro1\" style:family=\"table-row\"><style:table-row-properties style:row-height=\"#{height}cm\" fo:break-before=\"auto\" style:use-optimal-row-height=\"false\"/></style:style>"\
            "<style:style style:name=\"ro2\" style:family=\"table-row\"><style:table-row-properties style:row-height=\"#{height}cm\" fo:break-before=\"page\" style:use-optimal-row-height=\"false\"/></style:style>" + # "<number:date-style style:name=\"K4D\" number:automatic-order=\"true\"><number:text>"+::I18n.translate("date.formats.default").gsub(/\%./){|x| "</number:text>"+DATE_ELEMENTS[x[1..1]]+"<number:text>"} +"</number:text></number:date-style><style:style style:name=\"ce1\" style:family=\"table-cell\" style:data-style-name=\"K4D\"/>"+
            query.columns.collect do |column|
              "<style:style style:name=\"co#{column[:index]}\" style:family=\"table-column\"><style:table-column-properties fo:break-before=\"auto\" style:column-width=\"#{column[:size] * cmpc + fixed_margin}cm\"/></style:style>"
            end.join + '</office:automatic-styles>')

  # Tables
  zile.puts('<office:body><office:spreadsheet>')
  yield zile if block_given?
  zile.puts('</office:spreadsheet></office:body></office:document-content>')
end

Class Method Details

.generate(output, options = {}) {|document| ... } ⇒ Object

Yields:

  • (document)

44
45
46
47
48
# File 'lib/ekylibre/export/open_document/spreadsheet.rb', line 44

def self.generate(output, options = {}, &_block)
  document = new
  yield document
  document.generate(output, options)
end

Instance Method Details

#generate(output) ⇒ Object


38
39
40
41
42
# File 'lib/ekylibre/export/open_document/spreadsheet.rb', line 38

def generate(output)
  start = Time.zone.now
  Zip::OutputStream.open(output + '.ods') do |_zile|
  end
end

#header(&_block) ⇒ Object


36
# File 'lib/ekylibre/export/open_document/spreadsheet.rb', line 36

def header(&_block); end