您的位置:首页 > 其它

csv文件导出

2007-03-16 13:51 302 查看

void outCsv(string strsql, string filepath)




...{


MyCRM.DB db = new MyCRM.DB();


if (System.IO.File.Exists(filepath))




...{


System.IO.File.Delete(filepath);


}


System.IO.FileStream fsDestFile = System.IO.File.Open(filepath, System.IO.FileMode.OpenOrCreate);


System.IO.StreamWriter srDestFile = null;




DataTable dt = db.ececSelectSql(strsql);


string str = "";




foreach (DataRow dr in dt.Rows)




...{


string str1 = "";


for (int i = 0; i < dr.ItemArray.Length; i++)




...{


switch (dr[i].ToString())




...{


case "":


str1 += " ,";


break;


default:


str1 += dr[i].ToString().Trim() + ",";


break;


}




}


str1 = str1.Remove(str1.Length - 1, 1) + " ";


str += str1;


}


srDestFile = new System.IO.StreamWriter(fsDestFile, System.Text.Encoding.Default); //重要


srDestFile.WriteLine(str);


srDestFile.Flush();


srDestFile.Close();


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: