Example #1
0
        public void ExportToExcel(HttpContext context)
        {
            SupplierQuery dataQuery = this.GetDataQuery(context);
            IList <SupplierExportModel> supplierExportData = SupplierHelper.GetSupplierExportData(dataQuery);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("<table border='1'>");
            stringBuilder.Append("<thead><tr>");
            stringBuilder.Append("<th>用户名</th>");
            stringBuilder.Append("<th>供应商名称</th>");
            stringBuilder.Append("<th>联系人</th>");
            stringBuilder.Append("<th>联系电话</th>");
            stringBuilder.Append("<th>上架商品数</th>");
            stringBuilder.Append("<th>订单数</th>");
            stringBuilder.Append("<th>状态</th>");
            stringBuilder.Append("<th>详细地址</th>");
            stringBuilder.Append("</tr></thead>");
            StringBuilder stringBuilder2 = new StringBuilder();

            foreach (SupplierExportModel item in supplierExportData)
            {
                stringBuilder2.Append("<tr>");
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.UserName, true));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.SupplierName, true));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.ContactMan, true));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.Tel, true));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.ProductNums, false));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.OrderNums, true));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(item.StatusText, true));
                stringBuilder2.Append(ExcelHelper.GetXLSFieldsTD(RegionHelper.GetFullRegion(item.RegionId, " ", true, 0) + " " + item.Address, true));
                stringBuilder2.Append("</tr>");
            }
            stringBuilder.AppendFormat("<tbody>{0}</tbody></table>", stringBuilder2.ToString());
            StringWriter stringWriter = new StringWriter();

            stringWriter.Write(stringBuilder);
            DownloadHelper.DownloadFile(context.Response, stringWriter.GetStringBuilder(), "SupplierList" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
            stringWriter.Close();
            context.Response.End();
        }