Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a 2 list ,which i want to append the list values to .CSV ...when i open the .csv file which looks very similar to excel..My issue is am not binding list values to different cells ..list values are binding to one cell itself.

if i use
file.Write(listitem)
it will append to one cell

else
file.WriteLine(listitem)
it will bind list items vertically in .csv file

how can write each list1 item values horizontally in .csvfile(which looks similar to excel) then append next list2 items in newline


foreach (string s in list)
                    {
                        file.Write(string.Join(" ", s));

                    }
                    file.WriteLine();
</pre>


can you suggest me any idea to achieve this?
Posted
Updated 24-Jul-13 2:23am
v4

1 solution

Concatenate them together. This will write item1 followed by a comma and then item 2 and then the newline character.

C#
file.WriteLine(listitem1 & "," & listeitem2)
 
Share this answer
 
Comments
keerth516 24-Jul-13 8:19am    
you didnt get what i was trying to say, I have list1 contains 5items,want to write these 5items to different cells of .csv file instead it writing 5items to one cell itself. I want write each list items in one cell and then shift to adjacent cell and write second item. can u please suggest any other idea to achieve this.
ZurdoDev 24-Jul-13 8:22am    
Why won't this work? You said you wanted CSV.
keerth516 24-Jul-13 8:32am    
yes here when i create a .csv file ..it looks similar as excel sheet.
I could bind all the list items in one cell itself, not each item in different cell...can u pls suggest me any idea how can i write item1 to cell1 then item2 to adjacent cell.
ZurdoDev 24-Jul-13 8:41am    
What I suggested will put them into different cells. A CSV is a list of values separated by commas. When you open that in Excel, you tell it to use the comma as the delimiter and then it will put them into different cells. I don't see where you are stuck on this.
keerth516 24-Jul-13 8:56am    
sorry i was having some other issue which i could n't see it..yes your suggestion helped me..thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900