sandrods / odf-report Goto Github PK
View Code? Open in Web Editor NEWGenerates ODF files, given a template (.odt) and data, replacing tags
Home Page: http://sandrods.github.com/odf-report
License: MIT License
Generates ODF files, given a template (.odt) and data, replacing tags
Home Page: http://sandrods.github.com/odf-report
License: MIT License
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:
Any chance you could take a look into it?
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.
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.
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?
I have used simple fields placeholders sucessfully.
Can't make sections to work.
I'm on:
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!
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?
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
How start new page in document ?
I need to know how can I upload the generated report direct to s3.
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...
Hi, how to replace image inside table row?
Thanks..
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
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? :-)
Hi,
Please add the support for ".ods" format template.
Thanks,
Kiran.
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.
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!
Hi,
I'm getting issues trying to validate the ODTs produced by this gem.
Both of the sites below validate the template I'm using, but won't validate the resulting generated file.
I've attached a screenshot of a validated template:
and the failed validation of the file generated with odf-report:
http://opendocumentfellowship.com/validator
https://odf-validator.rhcloud.com/
Anyone else experiencing this issue?
Congratulations for the work, did some tests but I need the end result is in PDF.
What do you suggest to convert?
Is it possible to have some basic formatting features ? Like generating a topic, bold text and so on ?
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
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 }
.
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
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.
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:
Can u please help me with this issue.
Thanks a lot
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
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.
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?
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
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
The last version on rubygems is ancient (from 2011)...
Thanks,
Ward.
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
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.
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.
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?
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. :)
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?
Nothing gets substituted
It work fine without sections
Could you please help, it's quite urgen
TIA
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.
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.
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?
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
Hi Guys
Can we automatically generate PDF Files with this Gem?
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
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.rb
and 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
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?
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'
[...]
´´´
Replacing images failed on Windows due to an issue with zipping files (see: http://stackoverflow.com/questions/10564283/why-are-binary-files-corrupted-when-zipping-them).
To fix this: change the following line of code in images.rb
from
file.output_stream.write ::File.read(path)
to
file.output_stream.write ::File.binread(path)
This solved the issue for me. I havn't yet time double check on Linux whether everything is still correct there.
I get errors when using images with ODF REPORT. I used libreoffice, and the steps I follow are:
Then in my code I have ODF-REPORT:
And when I generate the document, I get an error reading the image.
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?
Please find failing test inside the pull request from me.
Issue details:
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.