public
void
ExportCSV(DataSet ds)
{
try
{
string data = "" ;
foreach (DataTable tb in ds.Tables)
{
foreach (DataColumn column in tb.Columns)
{
data += column.ColumnName + " , " ;
}
data += " \n " ;
foreach (DataRow row in tb.Rows)
{
foreach (DataColumn column in tb.Columns)
{
data += row[column].ToString() + " , " ;
}
data += " \n " ;
}
data += " \n " ;
}
Response.ContentEncoding = Encoding.GetEncoding( " gb2312 " );
string rename = HttpUtility.UrlEncode( " 通讯录 " , Encoding.GetEncoding( " utf-8 " ));
Response.ClearHeaders();
Response.AppendHeader( " Content-disposition " , string .Format( " attachment;filename={0}.csv " , rename));
Response.Write(data);
Response.End();
}
catch
{ }
}
{
try
{
string data = "" ;
foreach (DataTable tb in ds.Tables)
{
foreach (DataColumn column in tb.Columns)
{
data += column.ColumnName + " , " ;
}
data += " \n " ;
foreach (DataRow row in tb.Rows)
{
foreach (DataColumn column in tb.Columns)
{
data += row[column].ToString() + " , " ;
}
data += " \n " ;
}
data += " \n " ;
}
Response.ContentEncoding = Encoding.GetEncoding( " gb2312 " );
string rename = HttpUtility.UrlEncode( " 通讯录 " , Encoding.GetEncoding( " utf-8 " ));
Response.ClearHeaders();
Response.AppendHeader( " Content-disposition " , string .Format( " attachment;filename={0}.csv " , rename));
Response.Write(data);
Response.End();
}
catch
{ }
}
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2010/12/23/1914785.html,如需转载请自行联系原作者