I have problem with saving data in csv file. I would like save my data look
like this example :
excel preview :
A B C
1 10 11 12
2 13 14 15
As we see all values are in separate cell A1=10, B1=11, C1=12 ...
so I try :
PrintWriter wy = new PrintWriter(new FileWriter("test.csv"));
values[0][0]="10";
values[0][1]="11";
values[0][2]="12";
values[1][0]="13";
values[1][1]="14";
values[1][2]="15";
for (String[] row : values){
for (String col : row) {
wy.print(col + "\t");
}
}
but csv file look like :
A1=10 11 12
A2=13 14 15
but B1-B2 and C1-C2 is empty
the second steep is use Ostermiller library :
OutputStream out;
out = new FileOutputStream("temp.csv");
CSVPrinter csvp = new CSVPrinter(out);
String[][] values = new String[2][3];
csvp.changeDelimiter('\t');
values[0][0]="10";
values[0][1]="11";
values[0][2]="12";
values[1][0]="13";
values[1][1]="14";
values[1][2]="15";
csvp.println(values);
but the result is also this same, is anyone do how to resolve this problem
?
> I have problem with saving data in csv file. I would like save my data look
> like this example :
[quoted text clipped - 6 lines]
>
> As we see all values are in separate cell A1=10, B1=11, C1=12 ...
//code passage snipped
> but csv file look like :
>
[quoted text clipped - 4 lines]
>
> the second steep is use Ostermiller library :
//again, code passage snipped
> but the result is also this same, is anyone do how to resolve this problem
strongly off-topic for a java news group
Since two procedures give the same result, don´t you think that the
common thing in both scenarios (namely excel) might by responsible?
Are you going through the import wizard or is excel opening the file
directly? For the suffix "csv" I assume the latter. Are you sure that
"tabs" are really the default column delimiter of your excel
configuration?
Regards
Piet
NathanIEI - 08 May 2007 21:00 GMT
> On 8 Mai, 19:58, toomas <tomaszku...@gmail.com> wrote:> I have problem with saving data in csv file. I would like save my data look
> > like this example :
[quoted text clipped - 27 lines]
> Regards
> Piet
I think Piet is right. CSV stands for "Comma-Separated Values" and as
such, most spreadsheet applications probably won't pick up tabs as the
default delimiter. If you must use tabs, you could always import the
file into Excel using the 'Import External Data' option from within
the Excel application itself.
You can find samples of how a CSV file should be constructed here:
http://en.wikipedia.org/wiki/Comma-separated_values
A spec on CSV files can be found here:
http://tools.ietf.org/html/rfc4180