首页 > 代码库 > 导出带图形的数据excel表
导出带图形的数据excel表
public static string StatisticsSR(string parmStr) { try { StatisticsSRInfo parm = JsonConvert.DeserializeObject<StatisticsSRInfo>(parmStr); ServieRequestService ws = new ServieRequestService(); ws.Url = ConfigurationManager.AppSettings["ServiceRequestService"]; ReportDown.ServiceRequestService.MySoapHeader header = new ReportDown.ServiceRequestService.MySoapHeader(); string databaseStr = "UserId:0," + "Pass:," + "Time:" + DateTime.Now.ToString("u").Substring(0, 10) + ",Database:" + ConnManager.GetDatabase(); header.database = DES1.des(databaseStr).Replace("%2B", "+"); ws.MySoapHeaderValue = http://www.mamicode.com/header;"SRStatistics_" + parm.graphType + ".xlsx"); //加载模板 Microsoft.Office.Interop.Excel.Sheets sheets = workbook.Sheets; Microsoft.Office.Interop.Excel._Worksheet worksheet = (Microsoft.Office.Interop.Excel._Worksheet)sheets.get_Item(1); //第一个工作薄。 if (worksheet == null) return "Error:worksheet not exists in workbook! "; //工作薄中没有工作表. //写入数据,Excel索引从1开始。 if (parm.groupBy == "year" || parm.groupBy == "quarter" || parm.groupBy == "month" || parm.groupBy == "day") { worksheet.Cells[2, 1] = "时间段"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; //Excel模板上表头和标题行占了2行,根据实际模板需要修改; worksheet.Cells[row_, 1] = ds[i].groupValue; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else { if (parm.groupBy == "province") { worksheet.Cells[2, 1] = "地区"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].provinceName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else if (parm.groupBy == "customer") { worksheet.Cells[2, 1] = "客户"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].customerName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else if (parm.groupBy == "department") { worksheet.Cells[2, 1] = "部门"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].departmentName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else if (parm.groupBy == "owner") { worksheet.Cells[2, 1] = "员工"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].ownerName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else if (parm.groupBy == "productId") { worksheet.Cells[2, 1] = "产品"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].productName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else if (parm.groupBy == "item") { worksheet.Cells[2, 1] = "配件"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].productName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else if (parm.groupBy == "faultPoint") { worksheet.Cells[2, 1] = "故障点"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].faultPointName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } else { worksheet.Cells[2, 1] = "故障类型"; worksheet.Cells[2, 2] = "请求总数"; for (int i = 0; i < ds.Length; i++) { int row_ = 3 + i; worksheet.Cells[row_, 1] = ds[i].faultTypeName; worksheet.Cells[row_, 2] = ds[i].totalCount; } } } //Microsoft.Office.Interop.Excel.Range rg = worksheet.Cells.get_Range("A3", worksheet.Cells[ds.Length + 2, 8]); //rg.Borders.LineStyle = 1; //单元格加边框。 worksheet.Columns.AutoFit(); //自动调整列宽。 string savaPath = fileDir + "服务请求统计.xlsx"; workbook.SaveAs(savaPath, Missing.Value, Missing.Value, Missing.Value, false, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); workbook.Close(); return savaPath; } catch (Exception e) { return ("Error:" + e.Message); } }
导出带图形的数据excel表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。