Import delimited file with last column empty

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Import delimited file with last column empty

Jacques Le Roux
Administrator
Hi all,

I was trapped when importing a delimited file with its last column
empty. Actually its last column was not completly empty but only some
last lines (more than 2500 lines) contained something. This file was
builf with Open Office 2.0 from an Excel protected file. Yes, OO read
such files, but you cant modify cells in it...

After trying to use <<default-value=" ">> in the delimited file
definition, I found a quick and dirty solution in
org.ofbiz.datafile.Record.createDelimitedRecord. I added <<+ " ">> in
the line
  StringTokenizer st = new StringTokenizer(line, "" + delimiter, true);
wich became
  StringTokenizer st = new StringTokenizer(line + " ", "" + delimiter,
true);

Then it worked. Of course an empty field and a field filled with a blank
is not the same thing. But it was not a problem for me as I do a trim on
this field (String type)

Now, I wonder if somebody see a better solution that may fix this
existing problem correctly.
I thougt about playing with lengths (specially in the expression
  if (modelField.refField != null && modelField.refField.length() > 0) {
but before diving in, perhaps it's obvious for someone ?

Thanks

Jacques



Reply | Threaded
Open this post in threaded view
|

Re: Import delimited file with last column empty

BJ Freeman
Also you need to pad each cell with a " " so numbers that have starting
0 will be treated as a text cell and the zero will not be dropped.

Jacques Le Roux sent the following on 4/29/2007 7:38 AM:

> Hi all,
>
> I was trapped when importing a delimited file with its last column
> empty. Actually its last column was not completly empty but only some
> last lines (more than 2500 lines) contained something. This file was
> builf with Open Office 2.0 from an Excel protected file. Yes, OO read
> such files, but you cant modify cells in it...
>
> After trying to use <<default-value=" ">> in the delimited file
> definition, I found a quick and dirty solution in
> org.ofbiz.datafile.Record.createDelimitedRecord. I added <<+ " ">> in
> the line
>   StringTokenizer st = new StringTokenizer(line, "" + delimiter, true);
> wich became
>   StringTokenizer st = new StringTokenizer(line + " ", "" + delimiter,
> true);
>
> Then it worked. Of course an empty field and a field filled with a blank
> is not the same thing. But it was not a problem for me as I do a trim on
> this field (String type)
>
> Now, I wonder if somebody see a better solution that may fix this
> existing problem correctly.
> I thougt about playing with lengths (specially in the expression
>   if (modelField.refField != null && modelField.refField.length() > 0) {
> but before diving in, perhaps it's obvious for someone ?
>
> Thanks
>
> Jacques
>
>
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Import delimited file with last column empty

Jacques Le Roux
Administrator
Thanks BJ,

But there are no problems with empty cells but the last one in a line.
Or did I misunderstood you ?

Jacques

----- Message d'origine -----
De : "BJ Freeman" <[hidden email]>
À : <[hidden email]>
Envoyé : dimanche 29 avril 2007 19:54
Objet : Re: Import delimited file with last column empty


> Also you need to pad each cell with a " " so numbers that have
starting
> 0 will be treated as a text cell and the zero will not be dropped.
>
> Jacques Le Roux sent the following on 4/29/2007 7:38 AM:
> > Hi all,
> >
> > I was trapped when importing a delimited file with its last column
> > empty. Actually its last column was not completly empty but only
some
> > last lines (more than 2500 lines) contained something. This file was
> > builf with Open Office 2.0 from an Excel protected file. Yes, OO
read
> > such files, but you cant modify cells in it...
> >
> > After trying to use <<default-value=" ">> in the delimited file
> > definition, I found a quick and dirty solution in
> > org.ofbiz.datafile.Record.createDelimitedRecord. I added <<+ " ">>
in
> > the line
> >   StringTokenizer st = new StringTokenizer(line, "" + delimiter,
true);
> > wich became
> >   StringTokenizer st = new StringTokenizer(line + " ", "" +
delimiter,
> > true);
> >
> > Then it worked. Of course an empty field and a field filled with a
blank
> > is not the same thing. But it was not a problem for me as I do a
trim on
> > this field (String type)
> >
> > Now, I wonder if somebody see a better solution that may fix this
> > existing problem correctly.
> > I thougt about playing with lengths (specially in the expression
> >   if (modelField.refField != null && modelField.refField.length() >
0) {

> > but before diving in, perhaps it's obvious for someone ?
> >
> > Thanks
> >
> > Jacques
> >
> >
> >
> >
> >
> >