text: Hi all, I would like to import Area, Height and Width values from a csv file that has unique values for each cell into my datavyu opf file.
  Example CSV:
  Area,Height,Width,Document
  2679,75,48,499
  The Document column denotes the cell number that I would like the data to be imported to.
  Area, Height and Width are the values for the cell, in this case the datavyu cell number 499 has an area of 2679, height of 75 and width of 48.
  Current code looks something like this.
  for i in 1..frames
  time = i
  cell = cell_info.make_new_cell()
  cell.change_code("offset", time * (1000/30))
  cell.change_code("imgw", vwidth)
  cell.change_code("imgh", vheight)
  CSV.foreach('C:\\Users\\Main\\Desktop\\Untitled.csv', headers: true) do |row|
  #area, height, width, document = row
  x = 1
  document = "document"
  narea = row[1][x].to_i
  nheight = row[2][x].to_i
  nwidth = row[3][x].to_i
  if row[x][4].to_i == i
  #This is where the script checks the csv if area, height and width values exist for the cell being created, if so, it uses those values.
  cell.change_code("pixelarea", narea)
  cell.change_code("selectwidth", nwidth)
  cell.change_code("selectheight", nheight)
  x+=1
  else
  x+=1
  end
  end
  The ruby script runs successfully but does not populate the cells with the data in the csv. I think my error is either in my loop or in defining the csv array properly.
  Any help would be greatly appreciated.
  Thank You!
  asked
  03 Jan '17, 02:40
  patelav07
  11●1●1●3
  accept rate:
  0%
  edited
  03 Jan '17, 03:17
  Can you make sure the are, height, width, and document values are read properly for the rows of the csv file? E.g. put this line of code: puts [narea, nheight, nwidth].join(',') on the line before the if-statement.
  puts [narea, nheight, nwidth].join(',')
  I see that you commented out the line where you split the line into the area, width, height, etc. Did that not work?
  answered
  03 Jan '17, 14:54
  csv ×11
  ruby ×10
  import ×6
  question asked: 03 Jan '17, 02:40
  question was seen: 3,665 times
  last updated: 03 Jan '17, 14:54
  Simple Summary statistics from spreadsheet?
  General script for batch converting to CSV files
  Programming OpenSHAPA to SPSS
  Export as TSV script?
  Non-deterministic errors using Ruby API
  can you import an exported csv?
  Ruby script to create column with 30s cells within it
  Print script is looping.
  Running Raw Data Script on new format
  NoMethodError: undefined method
  First time here? Check out the FAQ!