Questions tagged [axlsx]

Ruby, JRuby and Rubinius Office Open XML (xlsx) generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.

Axlsx: Office Open XML Spreadsheet Generation

IRC: irc.freenode.net / #axlsx
Git: http://github.com/randym/axlsx
Twitter: https://twitter.com/#!/morgan_randy
Google Group: https://groups.google.com/forum/?fromgroups#!forum/axlsx

Author: Randy Morgan

Copyright: 2011 - 2017
License: MIT License

Latest Version: 3.0.0
Ruby Version: 2.2.7, 2.3.4, 2.4.1
JRuby Version: 1.9 modes
Rubinius Version: rubinius 3 * lower versions may run, this gem always tests against head.
Release Date: September 12th 2013

If you are working in rails, or with active record see: acts_as_xlsx

acts_as_xlsx is a simple ActiveRecord mixin that lets you generate a workbook with:

Posts.where(created_at > Time.now-30.days).to_xlsx

** and **

http://github.com/straydogstudio/axlsx_rails Axlsx_Rails provides an Axlsx renderer so you can move all your spreadsheet code from your controller into view files. Partials are supported so you can organize any code into reusable chunks (e.g. cover sheets, common styling, etc.) You can use it with acts_as_xlsx, placing the to_xlsx call in a view and add ':package => xlsx_package' to the parameter list. Now you can keep your controllers thin!

There are guides for using axlsx and acts_as_xlsx here: http://axlsx.blog.randym.net

If you are working with ActiveAdmin see: activeadmin-axlsx

It provides a plugin and dsl for generating downloadable reports.

The examples directory contains a number of more specific examples as well.

Synopsis

Axlsx is an Office Open XML Spreadsheet generator for the Ruby programming language. With Axlsx you can create excel worksheets with charts, images (with links), automated and fixed column widths, customized styles, functions, tables, conditional formatting, print options, comments, merged cells, auto filters, file and stream serialization as well as full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification.

sample

Feature List

  1. Author xlsx documents: Axlsx is made to let you easily and quickly generate professional xlsx based reports that can be validated before serialization.

  2. Generate 3D Pie, Line, Scatter and Bar Charts: With Axlsx chart generation and management is as easy as a few lines of code. You can build charts based off data in your worksheet or generate charts without any data in your sheet at all. Customize gridlines, label rotation and series colors as well.

  3. Custom Styles: With guaranteed document validity, you can style borders, alignment, fills, fonts, and number formats in a single line of code. Those styles can be applied to an entire row, or a single cell anywhere in your workbook.

  4. Automatic type support: Axlsx will automatically determine the type of data you are generating. In this release Float, Integer, String, Date, Time and Boolean types are automatically identified and serialized to your spreadsheet.

  5. Automatic and fixed column widths: Axlsx will automatically determine the appropriate width for your columns based on the content in the worksheet, or use any value you specify for the really funky stuff.

  6. Support for automatically formatted 1904 and 1900 epochs configurable in the workbook.

  7. Add jpg, gif and png images to worksheets with hyperlinks

  8. Reference cells in your worksheet with "A1" and "A1:D4" style references or from the workbook using "Sheet1!A3:B4" style references

  9. Cell level style overrides for default and customized style objects

  10. Support for formulas, merging, row and column outlining as well as cell level input data validation.

  11. Auto filtering tables with worksheet.auto_filter as well as support for Tables

  12. Export using shared strings or inline strings so we can inter-op with iWork Numbers (sans charts for now).

  13. Output to file or StringIO

  14. Support for page margins and print options

  15. Support for password and non password based sheet protection.

  16. First stage interoperability support for GoogleDocs, LibreOffice, and Numbers

  17. Support for defined names, which gives you repeated header rows for printing.

  18. Data labels for charts as well as series color customization.

  19. Support for sheet headers and footers

  20. Pivot Tables

  21. Page Breaks

Installing

To install Axlsx, use the following command:

$ gem install axlsx

Examples

The example listing is getting overly large to maintain here. If you are using Yard, you will be able to see the examples in line below.

Here's a teaser that kicks about 2% of what the gem can do.

Axlsx::Package.new do |p|
  p.workbook.add_worksheet(:name => "Pie Chart") do |sheet|
    sheet.add_row ["Simple Pie Chart"]
    %w(first second third).each { |label| sheet.add_row [label, rand(24)+1] }
    sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0,5], :end_at => [10, 20], :title => "example 3: Pie Chart") do |chart|
      chart.add_series :data => sheet["B2:B4"], :labels => sheet["A2:A4"],  :colors => ['FF0000', '00FF00', '0000FF']
    end
  end
  p.serialize('simple.xlsx')
end

Please see the examples examples for more.

There is much, much more you can do with this gem. If you get stuck, grab me on IRC or submit an issue to GitHub. Chances are that it has already been implemented. If it hasn't - let's take a look at adding it in.

Documentation

This gem is 100% documented with YARD, an exceptional documentation library. To see documentation for this, and all the gems installed on your system use:

gem install yard kramdown

yard server -g

Specs

This gem has 100% test coverage using test/unit. To execute tests for this gem, simply run rake in the gem directory.

272 questions
0
votes
1 answer

Create Excel file in Ruby on Rails with Axlsx

I try to create Excel files with the gem "axlsx". But i work for the first time with this gem and i try one Test. I make one link_to to an controller action. There is no Error, but i didnt find a complete excel file. Link_to : <%= link_to…
Drextor
  • 433
  • 1
  • 6
  • 24
0
votes
2 answers

Is there a way to convert xlsx to HTML using axlsx gem?

I'm creating an xlsx file in rails app and I would like to be able to convert it to an HTML file or string. Excel offers this by clicking "File > Save As Web Page." Is there a way to do this using axlsx gem?
Martin
  • 4,042
  • 2
  • 19
  • 29
0
votes
1 answer

Cannot send more than one table to an xlsx sheet using axlsx

I am using axlsx_rails to produce reports in an application and I am attempting to write my first (ever) report using this gem. The report is to allow the user to select a specific horse for the report and to output the horse and it's corresponding…
user3331154
  • 177
  • 1
  • 11
0
votes
0 answers

Image with axlsx gem

i am trying to add the images to excel. am able to send the different images when calling the method res_data. but after the execution i see the last image overwrites all the previous images captured. here is my code. please help .am using axlsx gem…
Jennifer
  • 45
  • 1
  • 9
0
votes
1 answer

Generate axlsx spreadsheets which are not easily formed by simple use of `add_row`

Background: I have previously been using the gem spreadsheet to generate .xls spreadsheets as part of a ruby project. However, this has caused various formatting and compatibility issues - the most recent being that old versions of excel only…
Tom Lord
  • 27,404
  • 4
  • 50
  • 77
0
votes
1 answer

Rails: Send a file generated by an axlsx view to a model

I am using the axlsx gem to generate excel spreadsheets. I am trying to send the generated spreadsheet to the model for zipping. This method zips the excel file with some other files. The method in my model looks like this: def zipper tempfile =…
agustaf
  • 683
  • 1
  • 6
  • 19
0
votes
1 answer

Autoload a gem only when needed in rails 3.2?

I'm trying to figure out how to load a specific gem only when needed. Here the scenario: I'm using the great axlsx gem to create Excel files. The feature in my app allowing this is called only when the user ask for a Excel file: # model require…
fro_oo
  • 1,610
  • 4
  • 24
  • 46
0
votes
1 answer

Merging cells based on repeated values in spreadsheet using axlsx in ruby on rails

I have been using axlsx gem in ruby for exporting data in spreadsheet file. I have more than 1000 of rows of data. Each row of data are the records from the database and has a unique id. I have already exported the records in a spreadsheet file…
0
votes
0 answers

Ruby Axlsx add new line to cell in whatever OS

the answer doesn't work for excel in mac osx, I have tried: sheet.add_row ["row1 \r\n\x0D\x0A row2"] still doesn't work
fudy
  • 1,540
  • 5
  • 25
  • 41
0
votes
1 answer

Error handling for gem 'axlsx_rails'

So I am using this gem axlsx_rails for exporting some data in excel file. But sometimes I get error like forbidden character as name or name exceed 31 character size. I don't understand how to handle these errors. All I want is to render index again…
asdfkjasdfjk
  • 3,784
  • 18
  • 64
  • 104
0
votes
1 answer

Separate Work Sheets based on year using axlsx gem

I have used axlsx gem for downloading data into excel. I have added worksheets with each sheet having 100 rows. In my data i have year column based on year i need to add sheets. How can i do that?
user2083041
  • 513
  • 1
  • 8
  • 32
0
votes
1 answer

Obtaining a reference to an already existing workbook for manipulation

How should I obtain a reference to an already existing .xlsx workbook when running my script? I'm using Ruby gem Axlsx and here is my code: require 'axlsx' p = Axlsx::Package.new wb_file = File.open("simple.xlsx", "a+") wb = p.workbook(wb_file) #…
Mindaugas Bernatavičius
  • 3,757
  • 4
  • 31
  • 58
0
votes
0 answers

axlsx_rails gem: Not rendering any non-numeric characters

So I'm working on setting up axlsx_rails in my rails app and am running into a consistent issue where the downloaded xlsx does not display any non-numeric characters. It also does not print any cells that contain a non-numeric character (i.e. "1p")…
mosquito242
  • 353
  • 5
  • 17
0
votes
2 answers

Incrementing Letters in ruby

I'm working with axlsx in rails and I want to be able to set up the columns according to the number of elements in a collection: In my controller: @task_categories = TaskCategories.all In my xlsx.axlsx view I would like to do something like: …
Joseph Freivald
  • 396
  • 2
  • 17
0
votes
1 answer

Using gem axlsx, how would I create multiple workbooks in one program?

Using basic axlsx code, I need to create a workbook, close it and create a new workbook within the same program. The workbooks will have generated names and a variable number will be created. At this point, I can create the sheets I need but,…
Richard_G
  • 4,700
  • 3
  • 42
  • 78