Free Ultra-Fast Ruby Writer and Reader for Excel XLSX
A Blazing-Fast Open Source Ruby Library allows Software Developers to Create, Read and Manipulate Excel XLSX Files. Apply Excel Cell, Row and Column Formatting, Merging & Splitting.
What is Fast_Excel?
Are you tired of watching your Ruby on Rails application grind to a halt when generating large Excel reports? Do Fast_Excel or the classic axlsx gem leave you waiting for minutes, consuming massive amounts of memory? If so, it's time to meet Fast_Excel, the lightning-fast solution to your data export problems. Before we get into the nitty-gritty, let's talk about what makes Fast_Excel so special. The secret behind its incredible performance lies in its architecture. Fast_Excel is a FFI (Foreign Function Interface) binding for the libxlsxwriter C library. This means you get the blazing-fast performance of a highly optimized C library with the elegance and simplicity of a Ruby interface.
Fast_Excel is an open source gem by Paxa, giving Ruby developers a way to create and manage.xlsx Excel files very efficiently and with low memory overhead. The library is very feature-rich and supports a wide array of Excel features like formatting, formulas, multiple sheets, and more.Because FastExcel uses libxlsxwriter (C library), operations are much faster than pure Ruby libraries. It is very memory Efficient and has a minimal memory footprint, preventing your server from running out of RAM during export generation. It offers a clean, intuitive, and Ruby-like interface that's easy to learn and use. So, the next time you need to generate an Excel file in your Ruby application, give Fast_Excel a try. You'll be amazed at how fast and efficient it is!
Getting Started with Fast_Excel
The recommend way to install Fast_Excel library is by using RubyGems. Please use the following command for smooth installation.
Install rubyX via RubyGems
$ gem install fast_excel
Writing a Simple Spreadsheet via Ruby API
The open source Fast_Excel library makes it easy for software programmers to create new Excel XLSX files very efficiently and with low memory overhead inside their own Ruby applications. The primary use case is generating a simple spreadsheet from an array of data. It supports adding new worksheets, renaming existing worksheets, inserting text and image and so on. Here is a simple example that shows how to create a simple XLSX spreadsheet inside Ruby Apps.
How to Create a Simple Spreadsheet via Ruby Library?
require 'fast_excel'
# Create a new workbook
workbook = FastExcel.open("constant_memory.xlsx", constant_memory: true)
# Add a worksheet
worksheet = workbook.add_worksheet("User Report")
# Add data rows. The write_row method accepts an array of values.
worksheet.write_row(0, ["ID", "Name", "Email"]) # Header row (row index 0)
users = User.limit(10000)
users.each_with_index do |user, index|
# Write each row, starting from row 1
worksheet.write_row(index + 1, [user.id, user.name, user.email])
end
# Don't forget to close the workbook to save the file!
workbook.close
Advanced Cell Formatting via Ruby
The Fast_Excel library makes has provided complete support for a rich set of formatting options to make your spreadsheets look professional and readable. You can define font size, font family, color (including RGB), styles like bold/italic, underline variants, strikeout, text wrapping, rotation, indent, borders (thin, double, etc.), alignment (horizontal, vertical), number formats, etc. Here is a very useful example that shows how software developers can apply different types of formatting to cells, rows and columns of Excel worksheets inside ruby apps.
How to Apply Advanced Formatting to Excel Worksheets via Ruby API?
require 'fast_excel'
workbook = Fast_Excel.open("formatted_report.xlsx")
# Create a bold format
bold = workbook.bold_format
# Create a custom number format
currency_format = workbook.number_format("$#,##0.00")
worksheet = workbook.add_worksheet("Sales Report")
# Set column widths and formats
worksheet.set_column(0, 0, 20)
worksheet.set_column(1, 1, 15, currency_format)
# Write a header row with bold formatting
worksheet.append_row(["Product", "Revenue"], bold)
# Write data rows
worksheet.append_row(["Product A", 15000])
worksheet.append_row(["Product B", 25000])
workbook.close
Column and Row Manipulation via Ruby API
The Fast_Excel library allows software developers to work with rows and columns of an Excel spreadsheets inside Ruby apps. It has provided full control over the dimensions of your columns and rows. You can set specific widths and heights, and Fast_Excel even supports auto-width for string values. The following example demonstrates how to work with rows and columns of an Excel spreadsheet using Ruby commands.
How to Set the Width and Height of Spreadsheet Row or Column via Ruby?
require 'fast_excel'
workbook = Fast_Excel.open("column_width.xlsx")
worksheet = workbook.add_worksheet
# Set the width of the first column to 30
worksheet.set_column(0, 0, 30)
# Set the height of the first row to 40
worksheet.set_row(0, 40)
worksheet.append_row(["This is a long string that needs more space"])
workbook.close
Better Speed and Performance
The open source Fast_Excel library has very high speed and significantly outperforms pure-Ruby gems, especially with large datasets. As FastExcel uses libxlsxwriter (C library), operations are much faster than pure Ruby libraries. Benchmarks show it outperforms others such as Axlsx by several times. Writing 1,000 rows – Fast_Excel is ~3–4× faster than Axlsx; for large data (20,000 rows), it’s still significantly faster.