Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-28-2010, 11:48 AM
Member
 
Join Date: Jan 2010
Posts: 3
Rep Power: 0
papele is on a distinguished road
Default expoprt date to csv file
Hi all, I've a problem with a simple java code. I've to export String in csv file. I've done this right but I could not move the text into columns, only rows.
How can I move the text into columns?

This is my code:
Code:
import java.io.FileWriter;
import java.io.IOException;
 
public class GenerateCsv
{
   public static void main(String [] args)
   {
	   generateCsvFile("test.csv"); 
   }
 
   private static void generateCsvFile(String sFileName)
	{
		try
		{
		    
		    FileWriter writer = new FileWriter(sFileName);
		    
			writer.append("DisplayName");
			writer.append(',');
			writer.append("Age");
			writer.append('\n');
			
 
			writer.append("MKYONG");
			writer.append(',');
			writer.append("26");
			writer.append('\n');
			
			writer.append("YOUR NAME");
			writer.append(',');
			writer.append("29");
			writer.append('\n');
 
			//generate whatever data you want
 
			writer.flush();
			writer.close();
		}
		catch(IOException e)
		{
		 e.printStackTrace();
		} 
	}
}
For example,
Code:
 writer.append('\n');
down one line but I want to move in the next column right (of csv file), not down line.

Thank you all
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-28-2010, 12:06 PM
Member
 
Join Date: Jun 2008
Posts: 97
Rep Power: 0
dlorde is on a distinguished road
Default
In CSV files, the 'columns' are separated by commas (,) - hence the name Comma Separated Value (CSV).
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-28-2010, 12:36 PM
Member
 
Join Date: Jan 2010
Posts: 3
Rep Power: 0
papele is on a distinguished road
Default
Hi dlorde,
I know that In CSV files, the 'columns' are separated by commas (,) but, as you can see from my code, I use
Code:
 writer.append(',');
but it dosen't work correctly.

I don't understand if you meant this.

Could you write the instruction to move in the right column?

Thank you

Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-28-2010, 01:05 PM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
So, what output do you get?
Because that looks correct to me.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-28-2010, 01:41 PM
Member
 
Join Date: Jan 2010
Posts: 3
Rep Power: 0
papele is on a distinguished road
Default
This is my output on csv file now:


This is the output I want:



Thank you

Last edited by papele; 01-28-2010 at 01:52 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-28-2010, 03:06 PM
Senior Member
 
Join Date: Apr 2009
Posts: 944
Rep Power: 1
Tolls is on a distinguished road
Default
No it isn't.
That's your output as viewed through whatever spreadhseet program you're using.
What does the csv file look like in a text editor, because to me it looks like the csv is fine, but your spreadsheet program isn't.

In any case, the output you want is not what would normally be thought of as the layout for a csv as seen through a spreadsheet.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to print the creation date of a jar file lunarbof Advanced Java 9 08-22-2008 07:12 PM
How to change the date of modification of a file Java Tip java.io 0 04-05-2008 11:10 AM
How to find file created date..... roshithmca Advanced Java 1 02-18-2008 10:48 AM
File creating date/time bugger New To Java 1 11-11-2007 08:43 PM
Date format display in CSV file after exporting latha Advanced Java 0 08-03-2007 09:09 AM


All times are GMT +2. The time now is 02:46 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org