1

Below is my code where i try to find the text from the excel sheet and click that 'text' on the application. Once done I want to color that particular cell(where the text is located ) in green color.

 require 'rubyXL'
 require 'roo'
 workbook = Roo::Spreadsheet.open(file_name)
 workbook1 = RubyXL::Parser.parse(file_name) workbook.default_sheet='Left navigation'
 worksheet1 = workbook1['Left navigation']
 for j in (workbook.first_row..workbook.last_row)
   for k in (workbook.first_column..workbook.last_column)
     if(k==1)
        choose("lookupSearch", :option => "Plan")
        fill_in "searchInput", :with => workbook.cell(j,k)
        find(:xpath, '//*[@id="searchicon"]').click
     elsif(workbook.cell(j,k)=='.')
        puts "Completed"
     else
        find('a', text: workbook.cell(j,k), :match => :prefer_exact)
        worksheet1.sheet_data[j][k].change_fill ('008000')
     end
   end
 end

Error message is "undefined method `[]' for nil:NilClass (NoMethodError)"

Note : When I use worksheet1.sheet_data[j-1][k-1].change_fill ('008000') there is no error .But still green color is not there on the cell. Unable to trace . Please Advice

RPD
  • 47
  • 8
  • Which line is the error occurring on? (also, please indent your code so it's readable) – Thomas Walpole Apr 06 '16 at 20:26
  • @TomWalpole The error is in the line :16 – RPD Apr 07 '16 at 13:55
  • So Roo starts counting at 1 while RubyXL starts at 0 - so it should be `worksheet1[j-1][k-1].change_fill('008000')`. I assume you're saving the xslx before checking it for the new fill color? Also, is there a good reason why you're using both Roo and RubyXL to process the document, seems memory inefficient. – Thomas Walpole Apr 07 '16 at 17:58
  • @TomWalpole I use rubyXL to read/ write in XL and roo to access the worksheet in for loop. Yes I'm saving the excel sheet before i start executing.Also in roo i have direct methods like 'first column' and 'last column' – RPD Apr 08 '16 at 14:42
  • With rubyXL you just call #each on the worksheet/row respectively to iterate through the rows/cells -- there is no need for first_column/last_column. You may have fully valid reasons for needing to use both libraries and try and keep things synched (adjusting offsets, etc), but this code doesn't really show it. I wasn't asking if you are saving before executing this code, I mean are you saving after changing the fill color, and before you reopen the xslx to see if the color has changed, or are you checking the fill color some other way? – Thomas Walpole Apr 08 '16 at 16:58
  • @TomWalpole I save the changes . So once the script is executed, i open the excel sheet to check whether the cells color is green – RPD Apr 11 '16 at 14:09

0 Answers0