如何将列表写入.csv文件 [英] how to write list to .csv file
问题描述
我有一个2列表,我想将列表值附加到.CSV ...当我打开看起来与excel非常相似的.csv文件时。我的问题是没有将列表值绑定到不同的单元格。 .list值绑定到一个单元格本身。
如果我使用
file.Write(listitem)
$ p $它将附加到一个单元格
elsefile.WriteLine(listitem)它将垂直绑定列表项在.csv文件中
如何在.csvfile(看起来类似于excel)中水平写入每个list1项值,然后在换行符中追加下一个list2项目
foreach(列表中的字符串)
{
file.Write(string.Join( ,s));
}
file.WriteLine();
< / pre>
你能建议我实现这个目标吗?解决方案
将它们连接在一起。这将写入item1,然后是逗号,然后是项目2,然后是换行符。
file.WriteLine(listitem1& < span class =code-string> ,& listeitem2)
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 usefile.Write(listitem)it will append to one cell
elsefile.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?解决方案Concatenate them together. This will write item1 followed by a comma and then item 2 and then the newline character.
file.WriteLine(listitem1 & "," & listeitem2)
这篇关于如何将列表写入.csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!