导出到Excel的操作
1.导出到Excel
导出到Excel
1
2 DataTable dt = wad.GetToExcel(lblcode.Text);
3 StringWriter sw = new StringWriter();
4
5 sw.WriteLine("代号,货品编码,货品名称,单位,净需求量,采购量,供应商,下单日期,到货日期,采购员,报关,状态,采购订单号");
6 foreach (DataRow item in dt.Rows)
7 {
8 //string state = (OPSState)Convert.ToInt32(item["imgstate"]);
9 sw.WriteLine(item["code"] + "," + item["goodscode"] + "," +
10 item["goodsname"] + "," + item["unit"] + "," +
11 item["netdemand"] + "," + item["shoppingnum"] + "," +
12 item["tradername"] + "," + item["orderdate"] + "," +
13 item["arrivaldate"] + "," + item["buyername"] + "," +
14 item["ifcustoms"] + "," + (OPSState)Convert.ToInt32(item["imgstate"]) + "," +
15 item["ordercode"] );
16 }
17 Response.AddHeader("Content-Disposition", "attachment; filename=test.csv");
18 Response.ContentType = "application/ms-excel";
19 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
20 Response.Write(sw);
21 sw.Close();
22 Response.End();
1
2 DataTable dt = wad.GetToExcel(lblcode.Text);
3 StringWriter sw = new StringWriter();
4
5 sw.WriteLine("代号,货品编码,货品名称,单位,净需求量,采购量,供应商,下单日期,到货日期,采购员,报关,状态,采购订单号");
6 foreach (DataRow item in dt.Rows)
7 {
8 //string state = (OPSState)Convert.ToInt32(item["imgstate"]);
9 sw.WriteLine(item["code"] + "," + item["goodscode"] + "," +
10 item["goodsname"] + "," + item["unit"] + "," +
11 item["netdemand"] + "," + item["shoppingnum"] + "," +
12 item["tradername"] + "," + item["orderdate"] + "," +
13 item["arrivaldate"] + "," + item["buyername"] + "," +
14 item["ifcustoms"] + "," + (OPSState)Convert.ToInt32(item["imgstate"]) + "," +
15 item["ordercode"] );
16 }
17 Response.AddHeader("Content-Disposition", "attachment; filename=test.csv");
18 Response.ContentType = "application/ms-excel";
19 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
20 Response.Write(sw);
21 sw.Close();
22 Response.End();