如何从此csv方法中删除标头 [英] How to remove header from this csv method

查看:92
本文介绍了如何从此csv方法中删除标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面这个方法会为我创建一个csv文件但我不希望csv文件有一个标题作为文件的一部分。

请帮助看看我能做些什么来做从方法中删除。



谢谢



我尝试过:



public void CreateCSVFile(DataTable dt,string strFilePath)

{

try

{

sw = new StreamWriter(strFilePath,false);

int iColCount = dt.Columns.Count;

for(int i = 0; i< iColCount; i ++)

{

sw.Write(dt.Columns [i]);

if(i < iColCount - 1)

{

sw.Write(,);

}

}

sw.Write(sw.NewLine);

//现在写下所有行。

foreach(DataRow dt.Rows博士)

{

for(int i = 0;我< iColCount; i ++)

{

if(!Convert.IsDBNull(dr [i]))

{

sw .Write(dr [i] .ToString());

}

if(i< iColCount - 1)

{

sw.Write(,);

}

}

sw.Write(sw.NewLine);

}

}

catch(例外情况)

{

// Console.WriteLine(ex.ToString());

//Console.ReadKey();

}

终于

{

sw.Close();

}





}

this method below will create a csv file for me but i don't want the csv file to have a header as part of the file.
Kindly help look and see what i can do to remove from the method.

thanks

What I have tried:

public void CreateCSVFile(DataTable dt, string strFilePath)
{
try
{
sw = new StreamWriter(strFilePath, false);
int iColCount = dt.Columns.Count;
for (int i = 0; i < iColCount; i++)
{
sw.Write(dt.Columns[i]);
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
// Now write all the rows.
foreach (DataRow dr in dt.Rows)
{
for (int i = 0; i < iColCount; i++)
{
if (!Convert.IsDBNull(dr[i]))
{
sw.Write(dr[i].ToString());
}
if (i < iColCount - 1)
{
sw.Write(",");
}
}
sw.Write(sw.NewLine);
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.ToString());
//Console.ReadKey();
}
finally
{
sw.Close();
}


}

推荐答案

删除这些行



Remove these lines

for (int i = 0; i < iColCount; i++)
          {
              sw.Write(dt.Columns[i]);
              if (i < iColCount - 1)
              {
                  sw.Write(",");
              }
          }
          sw.Write(sw.NewLine);


这篇关于如何从此csv方法中删除标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆