终于完成了自己的Dataset to CSV转换(所见即所得))
2006-04-05 11:08
477 查看
public void ProduceCSV(DataGrid dgListBill,DataSet dsBill)
{
int colCount = dgListBill.Columns.Count;
int valueRowCount = dsBill.Tables[0].Rows.Count;
string[] dtHeader = new String[colCount];
StringWriter sw=new StringWriter();
sw.WriteLine("=year(d4)");
string strColField,strLine;
strLine ="";
int k=0;//统计数据绑定的列数;
//填充表头
for (int i=0 ;i<colCount;i++)
{
string colType = dgListBill.Columns[i].GetType().ToString();
if (colType == "System.Web.UI.WebControls.BoundColumn")
{
BoundColumn Col = (BoundColumn)dgListBill.Columns[i];
if (Col.HeaderText !="操作" && Col.Visible && Col.DataField !=null)
{
dtHeader[k] = Col.DataField;
strLine += GetWriteableValue(Col.HeaderText)+" ";
k++;
}
}
}
sw.WriteLine(strLine);
// //填充内容
for(int i = 0;i<valueRowCount;i++)
{
strLine ="";
for(int j=0;j<k;j++)
{
strColField = dtHeader[j].ToString();
strLine += GetWriteableValue(dsBill.Tables[0].Rows[i][strColField])+" ";
}
sw.WriteLine(strLine);
}
ResponseAttach(sw,"输出结果.xls","application/m*-**cel","attachment","gb2312");
sw.Close();
}
public void ResponseAttach(StringWriter fileData,string strFileName,string ContentType,string OpMethod,string EncodingName)
{
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", OpMethod+";filename=" +Server.UrlEncode(strFileName));
Response.ContentEncoding = System.Text.Encoding.GetEncoding(EncodingName);
Response.Write(fileData.ToString());
//Response.Flush();
Response.End();
//Response.Clear();
}
{
int colCount = dgListBill.Columns.Count;
int valueRowCount = dsBill.Tables[0].Rows.Count;
string[] dtHeader = new String[colCount];
StringWriter sw=new StringWriter();
sw.WriteLine("=year(d4)");
string strColField,strLine;
strLine ="";
int k=0;//统计数据绑定的列数;
//填充表头
for (int i=0 ;i<colCount;i++)
{
string colType = dgListBill.Columns[i].GetType().ToString();
if (colType == "System.Web.UI.WebControls.BoundColumn")
{
BoundColumn Col = (BoundColumn)dgListBill.Columns[i];
if (Col.HeaderText !="操作" && Col.Visible && Col.DataField !=null)
{
dtHeader[k] = Col.DataField;
strLine += GetWriteableValue(Col.HeaderText)+" ";
k++;
}
}
}
sw.WriteLine(strLine);
// //填充内容
for(int i = 0;i<valueRowCount;i++)
{
strLine ="";
for(int j=0;j<k;j++)
{
strColField = dtHeader[j].ToString();
strLine += GetWriteableValue(dsBill.Tables[0].Rows[i][strColField])+" ";
}
sw.WriteLine(strLine);
}
ResponseAttach(sw,"输出结果.xls","application/m*-**cel","attachment","gb2312");
sw.Close();
}
public void ResponseAttach(StringWriter fileData,string strFileName,string ContentType,string OpMethod,string EncodingName)
{
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", OpMethod+";filename=" +Server.UrlEncode(strFileName));
Response.ContentEncoding = System.Text.Encoding.GetEncoding(EncodingName);
Response.Write(fileData.ToString());
//Response.Flush();
Response.End();
//Response.Clear();
}
相关文章推荐
- 将DataSet转换成CSV文件自己的用法
- 字符串匹配 wchar To char,摘抄别人的,自己改改,完成了自己的匹配。
- 自己制作的ORMap框架终于完成的差不多了。
- C# DataSet DataTable To/转换为 DBF 格式
- 公共代码帮助类:下载页面、导出Excel(不带表头)、导出Execl(带表头)、 导出CSV、实现对IList到DataSet的转换
- 读取csv文件转换成你自己想要格式的数据
- 写一个算法,完成String to Integer的转换(考虑所有情况)
- 自己研究课题的第一部分终于完成了
- Flowchart to Code终于完成!
- 终于完成了自己的论文
- 2016开始记录自己程序员生涯的所见所得
- C# LINQ系列:LINQ to DataSet的DataTable操作 及 DataTable与Linq相互转换
- 终于初步完成了小程序的制作,只通过自己所学的知识还是不够啊
- 自己写的JAVA多服务器通讯框架原型终于完成了!!!
- 周六周天加班,终于完成了将任何文件转换为二进制存储到数据库的工作
- How to transform our data into TFRecord(怎样将自己的图片数据转换成TF的格式)
- dataset=loadtxt('game/pima-indians-diabetes.csv') ValueError: could not convert string to float: b'6
- 通过findViewById()方法从layout中获取view并进行相应的转换时提示:"Cannot cast from View to AutoCompleteTextView"的解决办法!(转+自己错误)
- 今天终于自己在不看书的情况下完成了排序法的设计
- 一款将word转换为exe,并且限制访问的软件DRMsoft word to EXE