0

I'm using Roo and RubyXL to modify an Excel spreadsheet.

When I comment out the code that fills the color in the Excel sheet, then I do not get any error.

My full code:

require 'rubyXL'
require 'roo'

workbook = Roo::Spreadsheet.open(file_name)
workbook1 = RubyXL::Parser.parse(file_name)

workbook.default_sheet = 'Location Table Values'
worksheet1 = workbook1['Location Table Values']

for j in (workbook.first_row..workbook.last_row)
  print "\n"
  d = j

  for k in (workbook.first_column..workbook.last_column)
    if (k == workbook.first_column)
      choose("lookupSearch", :option => "Plan")
      fill_in "searchInput", :with => workbook.cell(j, k)
      find(:xpath, '//*[@id="searchicon"]').click
    elsif (k == workbook.last_column)
      puts " "
    else
      print k
      findXpath = page.find('td', text: workbook.cell(j,k), :match => :prefer_exact).path
      splitXpath = (findXpath.split("/"))
      count = splitXpath.count
      value = splitXpath.at(count - 1)

      if (value == "td[1]")
        finalElementXpath = findXpath.sub("td[1]", "td[2]")
      elsif (value == "td[2]")
        finalElementXpath= findXpath.sub("td[2]", "td[3]")
      end

      if (workbook.cell(j, k + 1)) == (find(:xpath, finalElementXpath).native.text)
        print "#{workbook.cell(j + 1, k)}-value exist \n"
        worksheet1.sheet_data[d][k].change_fill ('008000') # Green color
      else
        print "object #{workbook.cell(j, k + 1)}not exist #{workbook.cell(j, k)}"
        print workbook.cell(j, k + 1)
        worksheet1.sheet_data[d][k].change_fill ('ff0000')
      end
    end
  end
end

workbook1.write(file_name)

But I get Nil[] Nil class error.

RPD
  • 47
  • 8
  • `capybara` is not the right tool for this maybe look at `axlsx` gem or something meant for interacting with spreadsheets. `spreadsheet`, `roo`, etc. – engineersmnky Feb 10 '16 at 17:26
  • Basically i used capybara. But for accessing excel I used 'roo' and 'rubyXL' gem .Could you please help me on this issue – RPD Feb 10 '16 at 18:13
  • Your code is not syntactically valid. I you have more opening parentheses than closing ones. – Jordan Running Feb 10 '16 at 18:25
  • I've removed the references to Capybara, since you do not show any Capybara code or indicate that your problem has anything to do with Capybara, and added the [roo-gem] and [rubyxl] tags. – Jordan Running Feb 10 '16 at 18:27
  • I have edited my code and placed the whole code. Hope this would help. Please advice what should I change – RPD Feb 10 '16 at 18:46
  • I've edited your question to use a code block and I've edited your code to use proper indentation. Next time please take the time to properly format your code with consistent indentation. This makes one syntax error obvious: You have an extra `end` at the end. And you still have an extra opening parenthesis on the line that begins `if (workbook.cell(j, k + 1) == ...`. – Jordan Running Feb 10 '16 at 19:05
  • Sorry that end was for cucumber statement that i have it at the beginning of my code. I did not copy paste that line here. So I Will remove the last "end" – RPD Feb 10 '16 at 19:09

0 Answers0