All Projects → sandrods → Odf Report

sandrods / Odf Report

Licence: mit
Generates ODF files, given a template (.odt) and data, replacing tags

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Odf Report

cccc
Source code counter and metrics tool for C++, C, and Java
Stars: ✭ 39 (-85.45%)
Mutual labels:  reports
pivot-vue
Integration example of WebDataRocks web reporting tool with the Vue framework
Stars: ✭ 17 (-93.66%)
Mutual labels:  reports
motor-admin
Deploy a no-code admin panel for any application in less than a minute. Search, create, update, and delete data entries, create custom actions, and build reports.
Stars: ✭ 1,145 (+327.24%)
Mutual labels:  reports
Reports.JS
Stimulsoft Reports.JS is a reporting tool for Node.js and JavaScript applications.
Stars: ✭ 33 (-87.69%)
Mutual labels:  reports
Samples-ASP.NET-MVC-CSharp
ASP.NET MVC C# samples for Stimulsoft Reports.Web reporting tool.
Stars: ✭ 31 (-88.43%)
Mutual labels:  reports
Logo
Logo Tiger Enterprise Özel Raporlar, Tablo ve View Açıklamaları
Stars: ✭ 73 (-72.76%)
Mutual labels:  reports
Samples-JS-PHP
JavaScript and PHP samples for Stimulsoft Reports.PHP reporting tool.
Stars: ✭ 17 (-93.66%)
Mutual labels:  reports
pivot-react
Integration example of WebDataRocks web reporting tool with React framework
Stars: ✭ 33 (-87.69%)
Mutual labels:  reports
Samples-NET.Core-MVC-CSharp
ASP.NET Core 2.0 MVC C# samples for Stimulsoft Reports.Web reporting tool.
Stars: ✭ 28 (-89.55%)
Mutual labels:  reports
Guitar
A Simple and Efficient Distributed Multidimensional BI Analysis Engine.
Stars: ✭ 86 (-67.91%)
Mutual labels:  reports
zen knit
Zen-Knit is a formal (PDF), informal (HTML) report generator for data analyst and data scientist who wants to use python. RMarkdown Alternative for Python
Stars: ✭ 27 (-89.93%)
Mutual labels:  reports
spring-javafx-material-design-admin
Aplicação desktop para Gerenciamento de estoque e vendas com Spring Boot, JavaFX e Material Design
Stars: ✭ 56 (-79.1%)
Mutual labels:  reports
SyliusReportPlugin
Report Plugin for Sylius. This plugin add a report interface to the Sylius administration. Some reports comes with this bundle but you can create your custom reports.
Stars: ✭ 25 (-90.67%)
Mutual labels:  reports
phpreports
A report system for PHP.
Stars: ✭ 40 (-85.07%)
Mutual labels:  reports
Ad-Hoc-Report-Builder-.net-mvc
Open Source Reporting tool for .NET6/.NET Core/.NET Framework that you can embed in your application and generate dashboards and ad hoc reports
Stars: ✭ 43 (-83.96%)
Mutual labels:  reports
redmine hourglass
New Redmine plugin to enhance the time tracking abilities, reports and REST-API.
Stars: ✭ 68 (-74.63%)
Mutual labels:  reports
jmeterReports
Jmeter autogenerater reports after test to Confluence, using grafana custom dushboards.
Stars: ✭ 23 (-91.42%)
Mutual labels:  reports
Cloud Reports
Scans your AWS cloud resources and generates reports. Check out free hosted version:
Stars: ✭ 255 (-4.85%)
Mutual labels:  reports
difido-reports
This project aims to provide a generic implementation for HTML test reports.
Stars: ✭ 38 (-85.82%)
Mutual labels:  reports
reports
UI for created and download reports in Laravel
Stars: ✭ 13 (-95.15%)
Mutual labels:  reports

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_itens, :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_itens, 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

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].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].