Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

saving data in csv file

Thread view: 
toomas - 08 May 2007 18:58 GMT
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
?
Piet71 - 08 May 2007 20:17 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.