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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:14:20+00:00 2026-06-10T13:14:20+00:00

Okay so I’ve been messing around with Ruby quite a bit but am still

  • 0

Okay so I’ve been messing around with Ruby quite a bit but am still fairly new at it. I am running into a problem with my current program. What I want it to do is take a CSV file which contains a list of terms, I then take the csv file and create an array of those terms. Once I have those terms in an array I want to search an Excel workbook and find all occurances of that term…in all sheets. If a term is found it will be appended to a csv file with the sheet name and cell location it is found at. I think I have a fairly good start at it.

EDIT: I am no longer recieving any errors. It just simply recreates the given file. It does not seem to be dropping into the workbook and doing the compares? Any ideas?

EDIT 2: Used print statements it is something wrong with my if strings are equals condition.

EDIT 3: I isololated the issue to my compare. When I use the term variable it gets the term as ["theterm"] and then trys to compare it to a string which will always be false…

My code is below:

require 'roo'

$termsarray = Array.new

puts "Please enter filepath of file of terms (C:/path/to/file.csv)"
#termspath = gets.chomp.to_s
termspath = "C:/Ruby/termslist.csv"

CSV.foreach( "#{termspath}") do |row|   
  $termsarray << row
end
puts "Added terms to array successfully"

puts "Please enter filepath of file to cross-reference (C:/path/to/file.xlsx)"
#filepath = gets.chomp.to_s
filepath = "C:/Ruby/file_to_crossreference.xlsx"
puts "Please enter filepath for output file (C:/path/to/file.csv)"
output = gets.chomp.to_s

w1 = Excelx.new ( "#{filepath}" )
CSV.open( "#{output}", "w") do |csv|   
$termsarray.each do |term|
csv << term
  w1.sheets.each do |sheet|
    w1.default_sheet = sheet
    if w1.first_row && w1.first_column
      eval(w1.to_s).each do |index, value|
        if term.to_s.chomp.eql? value.to_s.chomp
          csv << [sheet, convert_index(index.to_s), value]
        end
      end
    end
  end
end
print "File Indexed Successfully!"
end
  • 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-10T13:14:22+00:00Added an answer on June 10, 2026 at 1:14 pm

    I fixed and found my problem. When creating the list of terms I was accidently creating an array of arrays. The code is below however it may not be the best, especially if the data is in multiple columns and such.

    CSV.foreach( "#{termspath}") do |row|  
      #Will only take first item in first column of each row
      string = row[0.to_i].to_s
      $termsarray << string
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I feel a bit foolish for having to ask this but I guess
Okay, so the answer to my question might not be the problem but here's
Okay, so I know that using eval() isn't great, but I haven't been able
Okay I got some good advice for Mobile Detection but still having an issue
Okay - I have a dilemma. So far my script converts page titles into
Okay, this is probably a very basic question; but, I'm just getting back in
Okay, so this is a long long shot but here it goes... When IE
Okay so the title may be a bit misleading. What I am trying to
Okay, I have setup up a handler for a div click but for some
Okay,I've been following this tutorial http://coenraets.org/blog/android-samples/androidtutorial/ Basically it gives me exactly what 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.