Code Monkey home page Code Monkey logo

odf-report's Introduction

ODF-REPORT

Gem for generating .odt files by making strings, images, tables and sections replacements in a previously created .odt file.

INSTALL

In your Gemfile

gem 'odf-report'

USAGE

Step 1 -- the template

First of all, you need a .odt file to serve as a template. Templates are normal .odt files with [PLACEHOLDERS] for substitutions. There are four kinds of substitutions available:

  • fields
  • tables
  • images
  • sections

Fields

It's just an upcase sentence, surrounded by brackets. It will be replaced by the value you supply.

In the folowing example:

report = ODFReport::Report.new("Users/john/my_template.odt") do |r|
  r.add_field :user_name, @user.name
  r.add_field :address, "My new address"
end

All occurences of [USER_NAME] found in the file will be replaced by the value of @user.name whereas all [ADDRESS] 'es will contains My new address

Tables

To use table placeholders, you should create a Table in your document and give it a name. In OpenOffice, it's just a matter of right-clicking the table you just created, choose Table Properties... and type a name in the Name field.

If you inform header: true, the first row will be treated as a header and left untouched. The remaining rows will be used as the template for the table.

If you have more than one template row, they will be cycled. This is usefull for making zebra tables.

As with Field placeholders, just insert a [FIELD_NAME] in each cell and let the magic takes place.

Taking the folowing example:

report = ODFReport::Report.new("Users/john/my_template.odt") do |r|

  r.add_field "USER_NAME", @user.nome
  r.add_field "ADDRESS", @user.address

  r.add_table("TABLE_1", @list_of_items, :header=>true) do |t|
    t.add_column(:item_id, :id)
    t.add_column(:description) { |item| "==> #{item.description}" }
  end

end

and considering you have a table like this in your template

#ID Description
[ITEM_ID] [DESCRIPTION]

and a collection @list_of_items, it will create one row for each item in the collection, and the replacement will take place accordingly.

Any format applied to the fields in the template will be preserved.

Sections

Sometimes, you have to repeat a whole chunk of a document, in a structure a lot more complex than a table. You can make a Section in your template and use it in this situations. Creating a Section in OpenOffice is as easy as select menu Insert and then Section..., and then choose a name for it.

Sections are lot like Tables, in the sense that you can pass a collection and have that section repeated for each member of the collection. But, Sections can have anything inside it, even Tables and nested Sections, as long as you provide the appropriate data structure.

Let's see an example:

  @invoices = Invoice.find(:all)

  report = ODFReport::Report.new("reports/invoice.odt") do |r|

    r.add_field(:title, "INVOICES REPORT")
    r.add_field(:date, Date.today)

    r.add_section("SC_INVOICE", @invoices) do |s|

      s.add_field(:number) { |invoice| invoice.number.to_s.rjust(5, '0') }
      s.add_field(:name,    :customer_name)
      s.add_field(:address, :customer_address)

      s.add_table("TB_ITEMS", :items, header: true) do |t|
        t.add_column(:id)
        t.add_column(:product) {|item| item.product.name }
        t.add_column(:value, :product_value)
      end

      s.add_field(:total) do |invoice|
        if invoice.status == 'CLOSED'
          invoice.total
        else
          invoice.items.sum('product_value')}
        end
      end

      s.add_section("SUB_NOTES", :notes) do |s1|

        s1.add_field(:note_title) { |n| n.title }

        s1.add_table ...

      end

    end

  end

Note that when you add a Table to a Section, you don't pass the collection itself, but the attribute of the item of that section that will return the collection for that particular Table. Sounds complicated, huh? But once you get it, it's quite straightforward.

In the above example, s.add_table("TB_ITEMS", :items, header: true) do |t|, the :items thing refers to a invoice.items. Easy, right?

Images

You must put a mock image in your .odt template and give it a name. That name will be used to replace the mock image for the actual image. You can also assign any properties you want to the mock image and they will be kept once the image is replaced.

An image replace would look like this:

report = ODFReport::Report.new("my_template.odt") do |r|
  r.add_image :graphic1, "/path/to/the/image.jpg"

  r.add_table("TABLE_WITH_IMAGES", @items) do |t|
    t.add_column(:id)
    t.add_column(:product, :product_name)
    t.add_image('PRODUCT_IMAGE') { |item| item.image_path }
  end  
end

Step 2 -- generating the document

It's fairly simple to generate the document. You can use this inside a Rails application or in a standalone script.

Generating a document in a Rails application

In a controller, you can have a code like this:

def print

  @ticket = Ticket.find(params[:id])

  report = ODFReport::Report.new(Rails.root.join("/app/reports/ticket.odt")) do |r|

    r.add_field(:id,         @ticket.id.to_s)
    r.add_field(:created_by, @ticket.created_by)
    r.add_field(:created_at, @ticket.created_at.strftime("%d/%m/%Y - %H:%M"))
    r.add_field(:type,       @ticket.type.name)
    r.add_field(:status,     @ticket.status_text)
    r.add_field(:date,       Time.now.strftime("%d/%m/%Y - %H:%M"))
    r.add_field(:solution,   (@ticket.solution || ''))

    r.add_table("OPERATORS", @ticket.operators) do |t|
      t.add_column(:name) { |op| "#{op.name} (#{op.department.short_name})" }
    end

    r.add_table("FIELDS", @ticket.fields) do |t|
      t.add_column(:field_name, :name)
      t.add_column(:field_value) { |field| field.text_value || "Empty" }
    end

  end

  send_data report.generate,
		    type: 'application/vnd.oasis.opendocument.text',
            disposition: 'attachment',
            filename: 'report.odt'

end

Generating a document in a standalone script

It's very similar to a Rails app, but you can inform the path where the file will be saved.

report = ODFReport::Report.new("ticket.odt") do |r|
... populates the report ...
end

report.generate("./documents/new_ticket.odt")

Using a template stored in the database (or anywhere besides the file system)

You can provide an io: param, containing the actual file read into a String.

report = ODFReport::Report.new(io: @template.attachment.read) do |r|

REQUIREMENTS

rubyzip: manipulating the contents of the odt file, since it's actually a zip file. nokogiri: parsing and manipulating the document xml files. mime-types: identify images mime types

TROUBLESHOOTING

Placeholder not replaced

If your placeholder is not being replaced, the problem might come from OpenOffice/LibreOffice which, when a placeholder is edited, add some markup that prevents odf-report from identifying the placeholder.

The golden rule is: NEVER edit the placeholders. If you want to change one, delete it an write again, including the [] Example: if you have, say, [USER] in your template and you want to change to [USERNAME], you should not edit and type NAME. Delete the PLACEHOLDER [USER] and type [USERNAME].

Word found unreadable content
  • Symptom: You prepare your template file in eg. LibreOffice, and when you open the template in Word it says "Word found unreadable content"
  • Solution: Open your template in LibreOffice, save as .docx, quit LibreOffice. Open the .docx in LibreOffice, save as .odt.
  • Hypothesis: Word does not support all ODT features. Saving as .docx removes those features of the document.

odf-report's People

Contributors

denispeplin avatar diego-aslz avatar driehuis avatar finelineautomation avatar jaredbeck avatar joseicosta avatar kennym avatar lx00st avatar mauriciomenegaz avatar mgacc0 avatar monteirobrena avatar paulmassen avatar pierre-alain-b avatar sandrods avatar vtamara avatar y-yagi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odf-report's Issues

Multipage document from one-page template

Is it possible to create multipage document, where the pages are same, and only variable values are different, using odf-report?

The idea is to print about 300 documents every month, and it is easier to print it from one multi-page document, rather than open and print single-page documents one by one.

Saving XML without formatting

When Nokogiri saves XML it adds some formatting that is interpreted by OpenOffice as spaces. My fix is here:

def parse_document(txt)
doc = Nokogiri::XML(txt)
yield doc
txt.replace(doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML))
end

Conditional table with header possible?

Is it possible to hide a table whenever no elements in the collection are present?

Right now it still displays the header line with no subsequent rows if there are no records to display in the collection passed to add_table.

Field titles cannot be nested.

I am not able to use the same field name for tables nested within a document... like

r.add_field(:title, @page.title)
r.add_table("COMMENTS", @page.comments) do |comment|
r.add_column(:title) {|c| c.title}
end

The page title gets inserted everywhere, even inside the COMMENTS table. Is there a way to allow this nesting?

Thanks for a cool gem!
Don

feature request: insert unknown number of new images

So currently, it is possible to replace an existing image in a template with a new one.
However, it looks more like a hack.

Please create a proper implementation. Documatic used to have that functionality if i'm not wrong.
It should be possible to generate a list of new images from a database and include them in a loop for example.

Nokogiri SyntaxError - Duplicate Images Verification

I tried testing the latest version (0.5.1) but I stumbled upon this problem.

Nokogiri::XML::XPath::SyntaxError at /api/v1/menu/print
//draw:frame[@draw:name]

Traceback (innermost first)

nokogiri/XmlXpathContext.java: in evaluate
/JRuby-1715@backend/lib/ruby/gems/shared/gems/nokogiri-1.6.1-java/lib/nokogiri/xml/node.rb: in xpath
          ctx.evaluate(path, handler)...
org/jruby/RubyArray.java: in map
/JRuby-1715@backend/lib/ruby/gems/shared/gems/nokogiri-1.6.1-java/lib/nokogiri/xml/node.rb: in xpath
        sets = paths.map { |path|...
/JRuby-1715@backend/lib/ruby/gems/shared/gems/odf-report-0.5.1/lib/odf-report/images.rb: in avoid_duplicate_image_names
      nodes = content.xpath("//draw:frame[@draw:name]")...
/JRuby-1715@backend/lib/ruby/gems/shared/gems/odf-report-0.5.1/lib/odf-report/report.rb: in generate
          avoid_duplicate_image_names(doc)...
/JRuby-1715@backend/lib/ruby/gems/shared/gems/odf-report-0.5.1/lib/odf-report/report.rb: in parse_document
    yield doc...
/JRuby-1715@backend/lib/ruby/gems/shared/gems/odf-report-0.5.1/lib/odf-report/report.rb: in generate

The traceback is referring to these changes.

I'm using:
Torquebox 3.0.2
JRuby 1.7.15
ODF-Report 0.5.1 (mingw86)
nokogiri 1.6.1 (also tested 1.5.11 - same error).

The document I'm trying to generate has just 3 strings that need replacement. There are no images in the template.

   document = ODFReport::Report.new("document_in.odt") do |r|
          r.add_field :string1, 'Test 1'
          r.add_field :string2, 'Test 2'
          r.add_field :string3, 'Test 3'
        end
      document.generate("document_out.odt")

When I comment out the duplicate image verification in lib/odf-report/report.rb @ line 70 the library generates the documents from the templates without any issues.

Conditional Blocks

What about having conditional blocks to activate/deactivate a whole block of code in the ODF?

As there is no way to insert formatted text (or is there a way I didn't see?), that could be a more easy to implement way of having a chance to have part at that behaviour. (I also tried having sections inside a table to realize that, but it didn't work out).

Regards, hoeni

Can I add an image to a section

Thank you for supporting sections now. I might have missed it, but is it possible to add an image to a section? I see there is no add_image method for sections, as exists for the report. This would be a very important feature for me. Thank you.

Section doesn't work: Nokogiri::XML::XPath::SyntaxError

I have used simple fields placeholders sucessfully.
Can't make sections to work.

I'm on:

  • Fedora 19
  • libreoffice-writer.x86_64 1:4.1.1.2-3.fc19
  • jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_25-b15 [linux-amd64]

I have this code:
[fer@spock iSesmt]$ cat vai.rb

require 'odf-report'`
@estabs = ['a', 'b', 'c']
report = ODFReport::Report.new('/home/fer/RubymineProjects/iSesmt/reports/templates/teste.odt') { |r| 
    r.add_section("USERS", @estabs) { |s|
          s.add_field(:myuser, 'fernando') 
    }
}
report_file_name = report.generate

When I run it, I get this:
[fer@spock iSesmt]$ ruby vai.rb

Nokogiri::XML::XPath::SyntaxError: .//text:section[@text:name='USERS']
             evaluate at nokogiri/XmlXpathContext.java:123
                xpath at /home/fer/.rvm/gems/jruby-1.7.4/gems/nokogiri-1.5.10-java/lib/nokogiri/xml/node.rb:159
                  map at org/jruby/RubyArray.java:2417
                xpath at /home/fer/.rvm/gems/jruby-1.7.4/gems/nokogiri-1.5.10-java/lib/nokogiri/xml/node.rb:150
    find_section_node at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/section.rb:80
             replace! at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/section.rb:49
    replace_sections! at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/report.rb:93
                 each at org/jruby/RubyArray.java:1617
    replace_sections! at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/report.rb:92
             generate at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/report.rb:58
       parse_document at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/report.rb:77
             generate at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/report.rb:55
               update at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/file.rb:32
  update_content_file at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/file.rb:56
                 open at /home/fer/.rvm/gems/jruby-1.7.4/gems/rubyzip-0.9.9/lib/zip/zip_file.rb:90
  update_content_file at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/file.rb:44
               update at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/file.rb:30
                 each at org/jruby/RubyArray.java:1617
               update at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/file.rb:28
             generate at /home/fer/.rvm/gems/jruby-1.7.4/gems/odf-report-0.4.4/lib/odf-report/report.rb:53
               (root) at vai.rb:8
[fer@spock iSesmt]$ 

ODT File can be found here:
https://docs.google.com/file/d/0Bz9EAjPa_w23b18xN2tFUHgwR2s/edit?usp=sharing

Help!

Error image

I get errors when using images with ODF REPORT. I used libreoffice, and the steps I follow are:

  1. Insert any image into the template and put I put the "graphic" name.

Then in my code I have ODF-REPORT:

  1. r.add_image ("graphic", File.join (Dir.pwd, 'grafico.png'))

And when I generate the document, I get an error reading the image.

it removes whitespaces inside text

Please find failing test inside the pull request from me.
Issue details:

  1. Try to add text to a document with a lot of white-spaces
  2. Look through generated document
    Result:
    All "extra" white-spaces has been removed during generation
    Expected result:
    String with white-spaces appears inside generated document as it presented inside the code

Image placeholder - change image size on fly

Hi folks,

is it possible to change the image properties (image size) on the fly? I would like to have just 1 placeholder, 2 images with different size and programmatically decide which one to use in that placeholder.

Thanks,

Jiri

0.5.1 Introduced Error: String contains null byte

Thanks for such a cool gem! With version 0.5.1, I am getting an error "String contains null byte" when I use send_file to send the converted odt file to the user.

Reverting back to 0.4.3 the error goes away.

Thanks,
Don

Formatting

Is it possible to have some basic formatting features ? Like generating a topic, bold text and so on ?

invalid byte sequence in US-ASCII

In my controller I have:

def create_template
report = ODFReport::Report.new("public/data/invito.odt") do |r|
r.add_field(:prot_n, "prot_n")
end
report_file_name = report.generate
send_file(report_file_name)
end

I think it is ok but I have this error:

invalid byte sequence in US-ASCII

Update rubyzip to 1.1.0

I have a conflict between odf-report depending on rubyzip ~> 0.9.4 and other gems depending on rubyzip ~>1.0.0. (selenium-webdriver for example).

I've tried to update odf-report to use the latest rubyzip version but the resulting files are corrupted (OpenOffice). There are only three lines to change apparently:

josegm@a7805e0

Any chance you could take a look into it?

Upload to s3

I need to know how can I upload the generated report direct to s3.

table: columns instead of rows

I need to fill a table with a collection of items, but instead of adding a new row for each item, I'd need to add a column. So if the collection has 7 items I will end up with a 7 column table.

How would you approach this feature?

Variable columns count

What should i do if i want to create a table with variable number of columns? I can create a cycle with something like
t.add_column(:start)
key_dots.times do |dot|
t.add_column(:range)
end
t.add_column(:end)
and template table with 3 columns [START], [RANGE] and [END] but it's not gonna work. Is there any solution for this in odf-report or can you recommend any alternative? Thanks.

paragraph break

How can I add paragraph break? For example...

r.add_field :subject, "first \n second"

creates line break (as if I would press ctrl+enter in OpenOffice)

Is there any escape character to force parahraph break?

tnx 4 help

Extra space after [FIELD]

Every field in my template have a space between itself and the next character (even if the next character is a space). Why is this happening?

Support for .odp files

Image and field placeholders work in .odp, but table placeholder doesn't seem to work. The XMLs generate are different compared to .odt, but it's not obvious why it doesn't work. Any ideas?

Image replacement problem... currupt odt file generated

Hey Sandrods,

I had an issue where I just have an image in the ODT template file..and I gave name called 'flower' to that image. When I try to replace as you have show in the usage.

The problem is that my report that is generated now, is corrupted. The Open office can repair it easily, but I am never getting a proper report in the first time.

I see that you are replacing the image path in the content.xml, but there is another entry in the META-INF/menifest.xml, about the same image which is not replaced. Not sure though if that might be the reason for it.

Also, when I saw what was different in the repaired version of the ODT file, I found the following:

  1. The Pictures folder had only one image (the replacement), not both, the dummy and the replacement (which is what I get in the corrupted version)
  2. The path of the image in the content.xml file is also some new random, which is same as in the file name present in the Pictures folder.
  3. The thumbnail folder of the generated doc (corrupt one) has the png file which is of the image in the template, whee as the repaired doc shows a new thumbnail which is of the replaced image.

Can u please help me with this issue.

Thanks a lot

Changing image name

This isn't an issue with the code, but give how I couldn't figure it out in Word and an hour of googling didn't yield anything useful, I thought I would post here. I can't figure out how to change the name of an inserted image. I insert the image and Word automatically assigns it a name of "Picture 2", which I found out by looking at the content.xml document directly. I have tried everything I can think of to change the name, but whatever I do doesn't work. Can someone point me in the right direction?

Nested Tags do not work

This does not appear to be working... maybe nested tags with the same name are not possible?

report = ODFReport::Report.new("Users/john/my_template.odt") do |r|

  r.add_field :username, @user.name
  r.add_field :address, @user.address

  r.add_table("TABLE_1", @list_of_items, :header=>true) do |t|
    t.add_column(:username, :id)
    t.add_column(:description) { |item| "==> #{item.description}" }
  end

end

thanks!

Unable to manipulate .odt file downloaded from Google docs

I'm trying to download a Google doc in .odt format, manipulate it with odf-report, then update the Google doc with the modified content.

I'm able to create a .odt file locally (with OpenOffice), manipulate it with odf-report, then upload it to Google just fine. But if I use a .odt file downloaded from Google docs, odf-report doesn't make the changes. Any idea why?

I experienced some trouble with Google spreadsheets in a different context roo-rb/roo#166. Perhaps Google docs has some similar nuances?

Below is a gist that outlines my proof-of-concept implementation. It also has a sample .odt file that was downloaded from Google, and that does not work with odf-report.

https://gist.github.com/tikitikifoofoo/3cef692c7fa7f66a9ffa#file-00test-odt

odf-report (0.3.2)

hello sir,

...
i = -1
r.add_table('table_time_details', employees_records) do |t|
i += 1
t.add_column(:employees_date, employees_records[i][:date])
end
...

this does not work. can you help me?

Question/Request: Parse HTML in a table

Hi Sandro,

Nice gem that you have here, well done!

I'm writing this issue because I'm trying to add some HTML text to a cell of a table, but am not sure if there's a way to parse the HTML (simple stuff like p, strong, br, ul). I've looked at the Parser module and noticed that it is used in text.rb, but not sure if I can use that inside a table. Am I missing something?

Thank you!
Simão

Repeating the first table row (table header) fails

odf-report work great for me with tables, unless I try to activate repeating the first table row as table header if the table needs more than one page. The error message is:

can't dup NilClass

If I disable repeation of the first row, odf-report works fine.

Stack trace:

odf-report (0.4.4) lib/odf-report/table.rb:85:in `dup'
odf-report (0.4.4) lib/odf-report/table.rb:85:in `get_next_row'
odf-report (0.4.4) lib/odf-report/table.rb:56:in `replace!'
activerecord (3.2.8) lib/active_record/associations/collection_proxy.rb:89:in `each'
activerecord (3.2.8) lib/active_record/associations/collection_proxy.rb:89:in `send'
activerecord (3.2.8) lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
odf-report (0.4.4) lib/odf-report/table.rb:54:in `replace!'
odf-report (0.4.4) lib/odf-report/report.rb:87:in `replace_tables!'
odf-report (0.4.4) lib/odf-report/report.rb:86:in `each'
odf-report (0.4.4) lib/odf-report/report.rb:86:in `replace_tables!'
odf-report (0.4.4) lib/odf-report/report.rb:59:in `generate'
odf-report (0.4.4) lib/odf-report/report.rb:77:in `parse_document'
odf-report (0.4.4) lib/odf-report/report.rb:55:in `generate'
odf-report (0.4.4) lib/odf-report/file.rb:32:in `update'
odf-report (0.4.4) lib/odf-report/file.rb:56:in `update_content_file'
rubyzip (0.9.9) lib/zip/zip_file.rb:90:in `open'
odf-report (0.4.4) lib/odf-report/file.rb:44:in `update_content_file'
odf-report (0.4.4) lib/odf-report/file.rb:30:in `update'
odf-report (0.4.4) lib/odf-report/file.rb:28:in `each'
odf-report (0.4.4) lib/odf-report/file.rb:28:in `update'
odf-report (0.4.4) lib/odf-report/report.rb:53:in `generate'
[...]
´´´

Template variables in tables (which in turn are placed within sections) are not replaced

Hallo again,

after I've updated to your new version with nested sections support, report generating does not work anymore: all template variables in tables are not replaced with their resp. content. I don't know yet whether or not this has something to do with the fact that these tables are placed in sections.

Here's my code:

  def self.render_sections(r, section_reports)
    list_item_bullet = 1
    #is_first_section = true

    section_reports_to_render = section_reports.reject { |section_report| section_report.corrective_actions.empty? && !section_report.contains_visible_questions }
    @rendered_sections = section_reports_to_render

    r.add_section("sections", section_reports_to_render) do |s|
      #pdf.start_new_page unless is_first_section
      #is_first_section = false

      # Section title
      s.add_field(:section_title, :section_title)

      # Section classification (only if there are corrective actions)
      s.add_field(:question_classification) do |sr|
        if !sr.corrective_actions.empty?
          question_classifications = Report::SectionReport.filter_classifications(sr.question_classifications)
          question_classifications.keys.join(', ')
        end
      end

      # Corrective actions
      s.add_table(:corrective_actions, :corrective_actions, :skip_empty_rows => true) do |t|
        t.add_column(:corrective_action_string) do |ca|
          str = "#{list_item_bullet}. #{ca}"
          list_item_bullet += 1
          str
        end
      end

      # not important for now ### render_visible_questions(s)

    end
  end

Regards,
Mark

license tag missing

Hello, thanks for the code released -- what's the license it's distributed under? Guess something like Ruby's/GPL/BSD, but clear note is way better than a wild guess for personal use only. :)

Generate PDF

Hi Guys

Can we automatically generate PDF Files with this Gem?

Table fields not being populated

I have a report with two fields and a table that has four columns (each is a field).

The first two fields, before the table, are populating correctly. The table also has the correct number of lines for my collection, but the fields are not being populated. I have double checked the names and everything matches.

def print
@users = User.where('confirmed_at IS NOT NULL')
@timestamp = l Time.now, :format => :long

report = ODFReport::Report.new("#{Rails.root}/app/reports/users_list.odt") do |r|
  r.add_field(:timestamp, @timestamp) # works
  r.add_field(:main_title, "List of all users") # works

  r.add_table("DATA_TABLE", @users) do |t|  # correct number of table rows
    t.add_column(:id, :id)  # never fills placeholder [ID]
    t.add_column(:first_name, :first_name)  # never fills placeholder [FIRST_NAME]
    t.add_column(:last_name, :last_name)  # never fills placeholder [LAST_NAME]
    t.add_column(:email, :email)  # never fills placeholder [EMAIL]
  end
end

report_file_name = report.generate
send_file(report_file_name)

end

I've also tried t.add_colum(:id) and t.add_colum(:id) { |item| item.id }.

Validation

Hi Sandro,

it would be nice if the template could be validated.
use-case:

my user uploads the template, if [NAME] and [DATE] isn't found. then it wont save and sets an error flash

sometimes the template generates mistype the variables

Best regards
Marcel

Get avaible placeholder

First of all i want to say thanks for this great gem! I`m writing because i have problems to extend the gem! I tried to add a medthod that returns the avaible Placeholders but i had problems to achieve this, because i dont know exacly where i should put on.

When i for example call: ODFReport::Report.new("person.odt").placeholders

I would like that it returns ["name","telefon","street"]. Is this possible?

I looked at espacially at this method in report.rband thought in traversing through the documents nodes with Nokogiki! Would this be the right approach? Thanks!

 def parse_document(txt)
    doc = Nokogiri::XML(txt)
    yield doc
    txt.replace(doc.to_s)
 end

wrong number of arguments error

I tried to make a sample code to generate report this is the code
1 - report = ODFReport::Report.new("#{Rails.root}/app/reports/test.odt") do | r |
2 - end
3 - report.generate('/home/chris/Desktop/new_ticket.odt')

but when I run it this is the error
ArgumentError: wrong number of arguments (0 for 1) in line 3. Any tips?

Placeholder problem

Sometimes the placeholders stop working without a specific reason, not replacing the variables. The template was build with Writer v4.4.2.2

The strange thing is that if I create a template from scratch going through the same placeholder, it works...

add_field doesn't replace fields inside layout tables

In my odt file, I used some tables for laying out a multi-column header layout. Inside the table is some fields to be replaced. The table is just used for layout and not displaying a collection. The fields inside the table are not replaced by the replace_fields method. If I move the fields outside of the layout table, they are properly replaced.

Is this by design? If so, is there another way to get a multi-column layout for an ODF document besides using tables that will properly generate the replaced fields?

Let me know if you want the odt file and controller code.

Error on Heroku

Hi,

Congrats on the great gem you have. I'm using it locally and it works great, but now I've commited the project to heroku and I get an error:

NameError (uninitialized constant SamplesController::ODFReport):

Any idea on how to solve this?

Multiple pages?

Hi! I must say, I'm impressed already, although I haven't tried it out yet, it certainly seems like the perfect gem for my case.

Only one thought..

Having a template with a single page, could I have this gem manipulate it a few hundred times and concatenate the pages (still ending up with a single file)?

The use case is such; we are going to send mails (yeah, paper) to a few hundred addresses from a database. I'd like to end up with a big file that can be sent over the net to the person who will simply print it, put in envelope, and send. If I'd have to generate a file for every single recipient, it would take a lot of work opening the file, printing, closing, etc.

Could this be achieved without too much effort? :-)

Lack of built-in table index

There is no built-in index variable for odf-report table, so for adding numbered table, every time I have to write some ugly code like this:

        num = 1
        r.add_table("TARIFF", self.hookups.all, :header=>true) do |t|
          t.add_column(:monthly_payment, :monthly_payment)
          t.add_column(:speed_down, :speed_down)
          t.add_column(:num) do |n|
            num - 1
          end
          num += 1
        end

Is there another way to implement numbered tables?

Handle formula objects.

I know that it is not designed for this, but it could be useful to me as I use math formulas that I wanted to generate (to generate exams).

The issue is that formulas are stored within other files (object 1\content.xml) and we should change those also.

I've been working a little to see how hard is to implement it, and is not so easy as these two items raised.

  • ZipFile is not so well documented so it is not easy to know how to handle multiple files or files in folders on a zip.
  • (object 1\content.xml) schema is a little different so the image check for name duplication crashes on those files.

My first try is here: https://github.com/eloyesp/odf-report/tree/objects_contents

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.