public string GetReportDetail() { try { ReportOP op = new ReportOP(); List <I.MES.Models.WhereCondition> whereList = new List <WhereCondition>(); int intTotal = Request.QueryString.AllKeys.Count(); string strKey = ""; string strValue = ""; for (int i = 0; i < intTotal; i++) { strKey = Request.QueryString.AllKeys[i]; strValue = Request.QueryString[strKey]; if (string.IsNullOrWhiteSpace(strKey)) { continue; } whereList.Add(new WhereCondition() { ColumnName = strKey, Key = strKey, Operator = "=", Value = strValue }); } DataSet ds = op.GetAllReportData(whereList); /* 视图字段被修改?? 导致添加统计行报错*/ DataRow drr = ds.Tables[0].NewRow(); try { drr["PartDesc"] = "总合计"; drr["ReturnQty"] = ds.Tables[0].Compute("sum(ReturnQty)", "TRUE"); drr["RecQty"] = ds.Tables[0].Compute("sum(RecQty)", "TRUE"); } catch { } ds.Tables[0].Rows.Add(drr); var strReportJson = ToJson(ds.Tables[0]); return(JsonHelper.ToJson(ds.Tables[0])); } catch (Exception ex) { return(ex.Message); } }
public void ExportOut() { string ret = ""; try { ReportOP op = new ReportOP(); DataSet dsExport = null; string strJson = Server.UrlDecode(Request["w"]); List <I.MES.Models.WhereCondition> whereList; if (!string.IsNullOrWhiteSpace(strJson)) { whereList = strJson.ToEntities <List <I.MES.Models.WhereCondition> >(); dsExport = op.GetAllReportData(whereList); } Workbook workbook = AsposeExcelTools.DataTableToExcel2(dsExport.Tables[0]); if (workbook != null) { this.DeleteDownLoadTempFile(); //直接导出 Stream outputStream = Response.OutputStream; string filename = "/DownLoad/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; workbook.Save(Server.MapPath(filename), SaveFormat.Xlsx); ret = filename; } } catch (Exception ex) { throw ex; } // Response.Buffer = false; Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Write(ret); Response.Flush(); Response.End(); }