Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:53:50+00:00 2026-06-01T23:53:50+00:00

Is there any plugin in Ruby that converts CSV file onto Excel. I did

  • 0

Is there any plugin in Ruby that converts CSV file onto Excel. I did little Google but all I found was converting Excel file into CSV. I know few gems which I can tweak a little and use to convert Excel to CSV but I need to know if anyone has done that before.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:53:52+00:00Added an answer on June 1, 2026 at 11:53 pm

    According to this post, the spreadsheet gem is a possibility. It looks like this is a very popular gem. Check it out. Example:

    book = Spreadsheet::Workbook.new
    sheet1 = book.create_worksheet
    
    header_format = Spreadsheet::Format.new(
      :weight => :bold,
      :horizontal_align => :center,
      :bottom => true,
      :locked => true
    )
    
    sheet1.row(0).default_format = header_format
    
    FasterCSV.open(input_path, 'r') do |csv|
      csv.each_with_index do |row, i|
        sheet1.row(i).replace(row)
      end
    end
    
    book.write(output_path)
    

    According to this post, write_xlsx is a possibility.

    I’ve used the Apache POI library with JRuby to export xls files. Here’s a quick example.

    require 'java'
    require 'poi.jar'
    # require 'poi-ooxml.jar'
    require 'rubygems'
    require 'fastercsv'
    
    java_import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    
    wb = HSSFWorkbook.new # OR XSSFWorkbook, for xlsx
    sheet = wb.create_sheet('Sheet 1')
    
    FasterCSV.open(ARGV.first) do |csv|
      csv.each_with_index do |csv_row, line_no|
        row = sheet.createRow(line_no)
        csv_row.each_with_index do |csv_value, col_no|
          cell = row.createCell(col_no)
          cell.setCellValue(csv_value) unless csv_value.nil? # can't pass nil.
        end
      end
    end
    
    
    f = java.io.FileOutputStream.new("workbook.xls")
    wb.write(f)
    f.close
    

    Some useful methods for formatting POI spreadsheets are

    • sheet.createFreezePane(0,1,0,1)
    • wb.setRepeatingRowsAndColumns(0, -1, -1, 0, 1)
    • sheet.setColumnWidth(i, 100 *256)
    • sheet.autoSizeColumn(i), but beware, if you’re running in headless mode, you have to call java.lang.System.setProperty("java.awt.headless", "true")

    You can also use Win32ole on Windows, if you have Excel installed

    require 'win32ole'
    require 'rubygems'
    require 'fastercsv'
    
    xl = WIN32OLE.new('Excel.Application')
    xl.Visible = 0
    wb = xl.Workbooks.Add
    ws = wb.Worksheets(1)
    
    FasterCSV.open(ARGV.first) do |csv|
      csv.each_with_index do |csv_row, line_no|
        csv_row.each_with_index do |value, col|
          ws.Cells(line_no + 1, col + 1).Value = value
        end
      end
    end
    
    wb.SaveAs("workbook.xls", 56) # 56 = xlExcel8 aka Excel 97-2003. i.e. xls
    wb.SaveAs("workbook.xlsx", 51) # 51 = xlOpenXMLWorkbook
    wb.SaveAs("workbook.xlsb", 50) # 50 = xlExcel12
    
    wb.Close(2) #xlDoNotSaveChanges
    xl.Quit
    

    Some useful methods for formatting with Excel are

    • xl.Rows(1).Font.Bold = true
    • ws.Cells.EntireColumn.AutoFit

    Yet another option is to write directly to Microsoft’s XML Spreadsheet format, as Ryan Bates at Railscasts.com does at the end of his Exporting CSV and Excel episode.

    <?xml version="1.0"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:o="urn:schemas-microsoft-com:office:office"
      xmlns:x="urn:schemas-microsoft-com:office:excel"
      xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
      xmlns:html="http://www.w3.org/TR/REC-html40">
      <Worksheet ss:Name="Sheet1">
        <Table>
          <Row>
            <Cell><Data ss:Type="String">ID</Data></Cell>
            <Cell><Data ss:Type="String">Name</Data></Cell>
            <Cell><Data ss:Type="String">Release Date</Data></Cell>
            <Cell><Data ss:Type="String">Price</Data></Cell>
          </Row>
        <% @products.each do |product| %>
          <Row>
            <Cell><Data ss:Type="Number"><%= product.id %></Data></Cell>
            <Cell><Data ss:Type="String"><%= product.name %></Data></Cell>
            <Cell><Data ss:Type="String"><%= product.released_on %></Data></Cell>
            <Cell><Data ss:Type="Number"><%= product.price %></Data></Cell>
          </Row>
        <% end %>
        </Table>
      </Worksheet>
    </Workbook>
    

    This gem looks promising, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any ruby gem/ rails plugin available for parsing the resume and importing
Is there any plugin for jQuery that would take an argument for the max
Are there any plugin for eclipse that allows to show only one method from
Is there any plugin or extension for google chrome to reload the web page
I am pretty new to maven. Is there any plugin or packaging type suitable
Is there any jquery plugin for implementing iGoogle style dashboard? So basically drag n
Is there any jQuery plugin for progressive light glow effect like this ?
Preferably Eclipse Plugin Is there any Eclipse plugin which can help me in looking
Is there any Eclipse plugin which autobackup a project every so and so minutes
Is there any utility or plugin which provides cscope like functionality for C++. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.