ASP.NET 导出Excel文档

 1 System.IO.TextWriter writer = new System.IO.StreamWriter(Server.MapPath("/provprice.xls"), false, System.Text.Encoding.GetEncoding("utf-8"));

 2             writer.Write("<table cellspacing=\"3\" style=\"font-family:宋体\" cellpadding=\"5\" rules=\"all\" border=\"1\">");

 3             writer.WriteLine("<tr style=\"font-weight:bold\"><td>");

 4             writer.Write("供货商");

 5             writer.Write("</td><td>");

 6             writer.Write("商品");

 7             writer.Write("</td><td>");

 8             writer.Write("库存");

 9             writer.Write("</td><td>");

10             writer.Write("价格");

11             writer.Write("</td><td>");

12             writer.Write("开始时间");

13             writer.Write("</td><td>");

14             writer.Write("结束时间");

15             writer.Write("</td>");

16             writer.WriteLine("</tr>");

17             ///这里搜索要导出的数据信息(DataTable)

18             foreach (DataRow dr in dt.Rows)

19             {

20                 writer.Write("<tr><td>");

21                 writer.Write(dr["ProviderName"].ToString());

22                 writer.Write("</td><td>");

23                 writer.Write(dr["Name"].ToString());

24                 writer.Write("</td><td>");

25                 writer.Write(dr["Inventory"].ToString());

26                 writer.Write("</td><td>");

27                 writer.Write(dr["Prices"].ToString());

28                 writer.Write("</td><td>");

29                 writer.Write(dr["Begin_Time"].ToString());

30                 writer.Write("</td><td>");

31                 writer.Write(dr["End_Time"].ToString());

32                 writer.Write("</td></tr>");

33             }

34             writer.Write("</table>");

35             writer.Close();

36             dt = null; 

 

你可能感兴趣的:(asp.net)