Greetings!
I got some help on this a while back and have been tweaking on it
trying to get it do work right. What I want to do is take a csv file,
and whenever there is a blank cell update it with the info from the
cell directly above (and on down as long as there are blanks).
There are two problems with what I have so far:
- It does not retain the double quotes and I would like it to be able
to do that. - On a previous version it was working for just the last column. I
have tried to adjust it to make it work for any column (at least that I
list in the write(colNum) definition, but it is not working.
<>
require ‘CSV’
class BlankFiller
def initialize(last=’’)
@last = last
end
def fill(e)
if e.empty?
e = @last
else
@last = e
end
end
end
blank_filler = BlankFiller.new
out_csv = CSV.open(‘C:\temp\geoff\filldown\filldownNew.txt’, ‘w’)
class ColumnWrite < BlankFiller
def write(colNum)
CSV.foreach(“C:\temp\geoff\filldown\filldown.txt”) do |row|
row[colNum] = blank_filler.fill(row[colNum])
out_csv << row
end
write(0)
write(1)
write(2)
end
end
<>
Here is the csv file I’m working with for a test case:
“BegDoc”,“EndDoc”,“New”
“Doc1BegDoc”,“Doc1EndDoc”,“Test1”
“Doc2BegDoc”,"",""
“Doc2BegDoc”,"",""
“Doc3BegDoc”,“Doc3EndDoc”,“Test2”
“Doc4BegDoc”,"",""
“Doc5BegDoc”,“Doc5EndDoc”,“New”
Ideas?
Thanks!
Geoff