saving data in csv file

T

toomas

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
?
 
P

Piet71

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 ... //code passage snipped
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 :
//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
 
N

NathanIEI

//code passage snipped> but csv file look like :




//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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top