Sampson-Li
Sampson.Li学习经验总结博客 学历代表过去,能力代表现在.学习力代表未来!
不使用excel组件导出excel  重点就是一个样式.假如一个单元格内想写多行数据.只需要在数据连接时加上<br style='mso-data-placement:same-cell;'/> 这个样式就可以了.还有就是导出图片.这个可能大家都认为只有使用组件才可以.其实不然.用html标签一样可以<img href=""> 插入td也可以显示图片.不过也有个弊端. 图片不是真是存在excel,而是从src地址中加载出来
        //           DataSet ds = bllor.Select_Order_Member("OID in (" + sVal + ")");  数据源
// DataTable dt = ds.Tables[0];
// StringBuilder result = new StringBuilder();
// if (dt.Rows.Count > 0)
// {
// result.Append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>");
// result.Append("<head><title></title><meta http-equiv='Content-Type' content=\"text/html; charset=UTF-8\">");
////注意:[if gte mso 9]到[endif]之间的代码,用于显示Excel的网格线,若不想显示Excel的网格线,可以去掉此代码
// result.Append("<!--[if gte mso 9]>");
// result.Append("<xml>");
// result.Append(" <x:ExcelWorkbook>");
// result.Append(" <x:ExcelWorksheets>");
// result.Append(" <x:ExcelWorksheet>");
// result.Append(" <x:Name>Sheet1</x:Name>");
// result.Append(" <x:WorksheetOptions>");
// result.Append(" <x:Print>");
// result.Append(" <x:ValidPrinterInfo />");
// result.Append(" </x:Print>");
// result.Append(" </x:WorksheetOptions>");
// result.Append(" </x:ExcelWorksheet>");
// result.Append(" </x:ExcelWorksheets>");
// result.Append("</x:ExcelWorkbook>");
// result.Append("</xml>");
// result.Append("<![endif]-->");
// result.Append("</head><body><table style='border-collapse:collapse;table-layout:fixed;'><tr>");
// result.Append("<td><b>" + "序号" + "</b></td>");
// result.Append("<td><b>" + "公司订单号" + "</b></td>");
// result.Append("<td><b>" + "物品编号" + "</b></td>");
// result.Append("<td><b>" + "日期" + "</b></td>");
// result.Append("<td><b>" + "物品名" + "</b></td>");
// result.Append("</tr>\n");
// for (int j = 0; j < dt.Rows.Count; j++)
// {

// DataTable dt1 = bllsc.Select("SC_O_OrderID='" + dt.Rows[j]["O_ID"].ToString() + "'").Tables[0];
// if (dt1.Rows.Count > 0)
// {
// int i = 1;
// foreach (DataRow row in dt1.Rows)
// {
// result.Append("<tr>");
// result.Append("<td><b>" +i + "</b></td><td><b>" + dt.Rows[j]["O_ID"] + "</b></td><td><b>" + row["SC_P_Code"] + "</b></td>");
// result.Append("<td><b>" + dt.Rows[j]["O_PayDate"] + "</b></td><td><b>" + row["SC_G_Name"] + "</b></td>");
// result.Append("</tr>\n");
// i++;
// }
// }
// }
// result.Append("</table>");
// Response.Clear();
// Response.Buffer = true;
// Response.ContentEncoding = Encoding.UTF8;
// Response.Charset = "utf-8";
// Response.ContentType = "application/vnd.ms-excel";
// Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(DateTime.Now.ToString("yyMMddHHmmss"), Encoding.UTF8) + ".xls");
// Response.Write(result.ToString());
// Response.Flush();
// Response.End();
posted on 2011-12-15 09:36  Sampson  阅读(342)  评论(0编辑  收藏  举报