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

  • Home
  • SEARCH
  • 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 8850427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:54:05+00:00 2026-06-14T12:54:05+00:00

I want to insert datas an existing Excel (.xls) file with Ruby under Linux.

  • 0

I want to insert datas an existing Excel (.xls) file with Ruby under Linux. This file has already data, it has some format properties and it contains macros.

I tried to insert data into the file with the spreadsheet gem but when I save modifications, the format and all the macros of the file are lost.

Here’s an example of a simple modification where I meet this problem :

book = Spreadsheet.open('myOriginalFile.xls')
sheet = book.worksheet 0
sheet.write('C12','hello')
book.write('myModifiedFile.xls')

I tried lots of things, did research on forums and the web but I didn’t find a solution…
Does anyone has an idea?

  • 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-14T12:54:06+00:00Added an answer on June 14, 2026 at 12:54 pm

    I found a solution :

    I use the POI library of Apache which is written in java with the rjb gem (Ruby Java Bridge, which allows to use java libraries with ruby). POI allows to keep macros and formulas of existing xls file and to modify it.

    For those who need, here’s how to set up rjb to use POI :

        # JVM loading
        apache_poi_path = File.dirname(__FILE__)+'/poi-3.8/poi-3.8-20120326.jar'
        Rjb::load("#{apache_poi_path}", ['-Xmx512M'])
    
        # Java classes import 
        @file_class = Rjb::import('java.io.FileOutputStream')
        @workbook_class = Rjb::import('org.apache.poi.hssf.usermodel.HSSFWorkbook')
        @poifs_class = Rjb::import('org.apache.poi.poifs.filesystem.POIFSFileSystem')
        Rjb::import('org.apache.poi.hssf.usermodel.HSSFCreationHelper')
        Rjb::import('org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator')
        @cell_reference_class = Rjb::import('org.apache.poi.hssf.util.CellReference')
        @cell_class = Rjb::import('org.apache.poi.hssf.usermodel.HSSFCell')
        # You can import all java classes that you need
    
        # Java classes utilisation :
        @file_input_class = Rjb::import('java.io.FileInputStream')
        @file_input = @file_input_class.new(model_file_path)
        @fs = @poifs_class.new(@file_input)
        @book = @workbook_class.new(@fs)
    
        @worksheet = @book.getSheet('worksheet')
        # ...
        # You can use your objects like in Java but with a ruby syntax
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data enclosed in HTML tags. I want to insert this data
I want to insert the data at some positions in the text file without
I want to insert the data at some positions in the text file without
I am using OLEDB to INSERT INTO an existing Excel worksheet. But I want
Possible Duplicate: insert contacts into database but does not want to duplicate already existing
I have a xml file which contains data I want to insert into a
I want to insert data into a table where I don't know the next
I want to insert data into the postgresql database of OpenERP, I am able
I want to insert data with special character in oracle tables. My code is
I'm new to Java. I want to create Java Array and insert data into

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.