求教文件导出的方法2: 如果输入参数为datareader 对象,如何快速的导入到以下文件EXCEL文件xml文件text文件CSV文件求源码:注意:我要的是winform的程序的源代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 windform的我没找到阿。。你给我个地址参考下 比如csv:using System;using System.Collections.Generic;using System.IO;using System.Text;using System.Data;namespace Utility{public class CSVHelper{//导出为svc文件,strFileName为要导出的csv格式文件的路径和文件名:比如,"d:\test\test.csv"public void ExportToSvc(System.Data.DataTable dt, string strFileName){string strPath = strFileName;if (File.Exists(strPath)){File.Delete(strPath);}//先打印标头StringBuilder strColu = new StringBuilder();StringBuilder strValue = new StringBuilder();int i = 0;try{StreamWriter sw = new StreamWriter(new FileStream(strPath, FileMode.CreateNew), Encoding.GetEncoding("GB2312"));for (i = 0; i <= dt.Columns.Count - 1; i++){strColu.Append(dt.Columns[i].ColumnName);strColu.Append(",");}strColu.Remove(strColu.Length - 1, 1);//移出掉最后一个,字符sw.WriteLine(strColu);foreach (DataRow dr in dt.Rows){strValue.Remove(0, strValue.Length);//移出for (i = 0; i <= dt.Columns.Count - 1; i++){strValue.Append(dr[i].ToString());strValue.Append(",");}strValue.Remove(strValue.Length - 1, 1);//移出掉最后一个,字符sw.WriteLine(strValue);}sw.Close();}catch (Exception ex){throw ex;}System.Diagnostics.Process.Start(strPath);}}} 你的输入参数根本不是datareader对象,你的是datatable,这样的代码我也有很多。。 C#中上下左右键切换控件焦点 用C#POST百度贴吧发贴 c#操作Excel设置字体颜色 根据输入值判断是否符合给定类型 c#打印问题 *********************急,急,急呀,水晶报表设计时遇到一个好大的问题!!****************************** 关于强名称的问题 怎么让水晶报表支持多个Page?就是我有10个表格,怎么让一个report支持这么多表呢?一个page只支持一个表格啊. ComboBox下拉列表重绘思路 思归大哥,请您看一下该问题集!其中问题可另开帖加分!(俗了!!) 100分求教文件导出的方法: 请教:C#传递数组到JS函数里~~~
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Data;namespace Utility
{
public class CSVHelper
{
//导出为svc文件,strFileName为要导出的csv格式文件的路径和文件名:比如,"d:\test\test.csv"
public void ExportToSvc(System.Data.DataTable dt, string strFileName)
{
string strPath = strFileName;
if (File.Exists(strPath))
{
File.Delete(strPath);
}
//先打印标头
StringBuilder strColu = new StringBuilder();
StringBuilder strValue = new StringBuilder();
int i = 0;
try
{
StreamWriter sw = new StreamWriter(new FileStream(strPath, FileMode.CreateNew), Encoding.GetEncoding("GB2312"));for (i = 0; i <= dt.Columns.Count - 1; i++)
{
strColu.Append(dt.Columns[i].ColumnName);
strColu.Append(",");
}
strColu.Remove(strColu.Length - 1, 1);//移出掉最后一个,字符sw.WriteLine(strColu);foreach (DataRow dr in dt.Rows)
{
strValue.Remove(0, strValue.Length);//移出for (i = 0; i <= dt.Columns.Count - 1; i++)
{
strValue.Append(dr[i].ToString());
strValue.Append(",");
}
strValue.Remove(strValue.Length - 1, 1);//移出掉最后一个,字符
sw.WriteLine(strValue);
}sw.Close();
}
catch (Exception ex)
{
throw ex;
}
System.Diagnostics.Process.Start(strPath);
}
}
}