On Mar 3, 2009, at 11:55 PM, Salil G. wrote:
look like this…
my question is ,is it possible using rails?
Oh, sit back down James, let me take this reply.
I don’t know what version of Excel you are using, but I’ve got
Microsoft Office 2004 for Mac on my system and if I start with your
text in /tmp/notcsv.csv, open it in Excel, put =LEN(A1) in cell A2 and
'=LEN(A1) in cell A3 (and similarly for B2…C3), save it as ~/
Documents/fromExcel.csv as a “CSV (Comma-delimited)” type, then I get
$ head /tmp/notcsv.csv ~/Documents/fromExcel.csv
==> /tmp/notcsv.csv <==
“abc”, "sdfds “string"ddsfdsf”, “xyz”, “pqr”
==> /Users/rab/Documents/fromExcel.csv <==
abc," ““sdfds ““string”“ddsfdsf”””,” ““xyz””"," ““pqr””"
So you seem to be missing some quotes in your output. Note that the
first field had quotes in the original, but they are not required (no
leading spaces, no comma or quote in the value). The original file,
while technically invalid, is read by Excel and interpreted in a
reasonable way. The output is strictly conforming to the CSV spec
(although yours seems not to be).
As others have said, you’ll have to parse it yourself if you need to
accept a sloppy input format.
You also seem to have the impression that rails is somehow “more” than
ruby. It isn’t “more” than ruby, it just is written in ruby like any
other ruby program you might write to handle the data. Just decide
how each of the line types ought to be interpreted, write down the
rules that result, and turn them into code.
If you insist on asking questions here, then at least LISTEN to the
responses that you receive. Follow-up questions should include CODE
that demonstrates two things: that you have absorbed the previous
response and that you have made some additional progress which has led
you to a new problem. (Or you don’t understand the response and need a
particular aspect clarified.)
Rob B. http://agileconsultingllc.com