使用C#将文本文件转换为excel文件 [英] converting text file to excel file using C#
本文介绍了使用C#将文本文件转换为excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
请告诉我如何使用c#将以下文本转换为excel这些是两行,在excel中我们必须放一些标题
OBREPORT,23.08.2013,02.06.58,PBS,8182301,80000001, 4802195,
OBREPORT,23.08.2013,02.06.58,PBS,8182301,80000001,4802195,>
提前致谢。
Hi All,
Please tell me how to convert the following text to excel using c# these are two rows and in excel we have to put some headers
"OBREPORT","23.08.2013","02.06.58","PBS","8182301","80000001","4802195",""
"OBREPORT","23.08.2013","02.06.58","PBS","8182301","80000001","4802195",""
Thanks in advance.
推荐答案
以下是一些写入Excel的示例。
http://csharp.net-informations.com/excel /csharp-excel-tutorial.htm [ ^ ]
http ://siddharthrout.wordpress.com/vb-net-and-excel/ [ ^ ]
Here are some examples to write into Excel.
http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm[^]
http://siddharthrout.wordpress.com/vb-net-and-excel/[^]
static void Main(string[] args)
{
string line;
using (StreamReader reader = new StreamReader(@"yourFilePath.txt"))
{
while ((line = reader.ReadLine()) != null)
{
using (StreamWriter writer = new StreamWriter(@"yourFilePath.csv", true))
{
writer.WriteLine(line.Replace(",",";"));
}
}
}
}
如果你想要写一些标题只是在所有这些之前写一行,并为每个新列添加一个;
And if you want to write some headers just write a line before all this and for every new column you add a ";"
访问这里....
http: //www.geekinterview.com/talk/19527-convert-the-text-file-excel-format.html [ ^ ]
visit here....
http://www.geekinterview.com/talk/19527-convert-the-text-file-excel-format.html[^]
这篇关于使用C#将文本文件转换为excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文