.NET 创建并写CSV文件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了.NET 创建并写CSV文件相关的知识,希望对你有一定的参考价值。
/// <summary> /// 创建并写日志 /// </summary> /// <param name="SuccessA100"></param> /// <param name="Result"></param> public void WriteLog(List<string> SuccessA100,string Result,string A102) { if (SuccessA100 == null) { return; } string txtPath = AppDomain.CurrentDomain.BaseDirectory + "log\\" +A102 + "\\"+ Result +A102.Replace("-", "")+DateTime.Now.ToString("yyyyyMMdd") + ".csv"; if (!File.Exists(txtPath)) { if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "log\\" + A102 )) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "log\\" + A102); } FileStream fs1 = new FileStream(txtPath, FileMode.Create, FileAccess.Write);//创建写入文件 using (StreamWriter sw = new StreamWriter(fs1)) { sw.WriteLine("A001,"); foreach (string a100 in SuccessA100) { sw.WriteLine(a100+",");//开始写入值 } sw.Close(); fs1.Close(); } } else { FileStream fs = new FileStream(txtPath, FileMode.Append, FileAccess.Write); using (StreamWriter sw = new StreamWriter(fs)) { foreach (string a100 in SuccessA100) { sw.WriteLine(a100 + ",");//开始写入值 } sw.Close(); fs.Close(); } } Thread.Sleep(1000); }
以上是关于.NET 创建并写CSV文件的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Object c# .NET Core 在 blob 存储 Azure 上创建 csv 文件?