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 943773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:29:16+00:00 2026-05-15T22:29:16+00:00

I am trying to read an Excel spreadsheet file with Ruby, but it is

  • 0

I am trying to read an Excel spreadsheet file with Ruby, but it is not reading the content of the file.

This is my script

book = Spreadsheet.open 'myexcel.xls';
sheet1 = book.worksheet 0
sheet1.each do |row|
  puts row.inspect ;
  puts row.format 2; 
  puts row[1]; 
  exit;
end

It is giving me the following:

[DEPRECATED] By requiring 'parseexcel', 'parseexcel/parseexcel' and/or
             'parseexcel/parser' you are loading a Compatibility layer which
             provides a drop-in replacement for the ParseExcel library. This
             code makes the reading of Spreadsheet documents less efficient and
             will be removed in Spreadsheet version 1.0.0

#<Spreadsheet::Excel::Row:0xffffffdbc3e0d2 @worksheet=#<Spreadsheet::Excel::Worksheet:0xb79b8fe0> @outline_level=0 @idx=0 @hidden=false @height= @default_format= @formats= []>
#<Spreadsheet::Format:0xb79bc8ac>
nil

I need to get the actual content of file. What am I doing wrong?

  • 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-05-15T22:29:16+00:00Added an answer on May 15, 2026 at 10:29 pm

    It looks like row, whose class is Spreadsheet::Excel::Row is effectively an Excel Range and that it either includes Enumerable or at least exposes some enumerable behaviours, #each, for example.

    So you might rewrite your script something like this:

    require 'spreadsheet'    
    book = Spreadsheet.open('myexcel.xls')
    sheet1 = book.worksheet('Sheet1') # can use an index or worksheet name
    sheet1.each do |row|
      break if row[0].nil? # if first cell empty
      puts row.join(',') # looks like it calls "to_s" on each cell's Value
    end
    

    Note that I’ve parenthesised arguments, which is generally advisable these days, and removed the semi-colons, which are not necessary unless you’re writing multiple statement on a line (which you should rarely – if ever – do).

    It’s probably a hangover from a larger script, but I’ll point out that in the code given the book and sheet1 variables aren’t really needed, and that Spreadsheet#open takes a block, so a more idiomatic Ruby version might be something like this:

    require 'spreadsheet'    
    Spreadsheet.open('MyTestSheet.xls') do |book|
      book.worksheet('Sheet1').each do |row|
        break if row[0].nil?
        puts row.join(',')
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read excel contents in android, but always get file not found
i am trying to read an excel file in ruby and then take the
I’m trying to read and parse a UTF-8 Excel file using the PHPExcelReader but
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
I am trying to read data from excel file in asp.net. I have added
i am trying to read an excel file using java. while compiling the program
I'm trying to read an Excel file (.xls, I think Excel 2003 compatible) via
I'm trying to read an excel file using an OleDb Reader, I couldn't debug
Possible Duplicate: Reading Datetime value From Excel sheet I'm trying to read in a
I'm trying to read excel file which is uploaded on itemadded event. I need

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.