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 = header; SRStatisticsInfo[] ds = ws.StatisticsSR(parm.statisticsType, parm.fromDate, parm.toDate, parm.groupBy, parm.orderDirection);
//以上是获取数据
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = false;
app.UserControl = true;
app.DisplayAlerts = false;//不弹出窗口 Microsoft.Office.Interop.Excel.Workbooks workbooks = app.Workbooks;
Microsoft.Office.Interop.Excel._Workbook workbook = workbooks.Add(fileDir + "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表的更多相关文章

  1. 导出数据excel表--身份证号后三位是0--〉还原

    导出数据excel表的身份证号后三位是0,怎么办? 数据导出前,在身份证号前加任意符号即可 例如: 结果

  2. jsp导出table数据excel表

    <html> <head> <meta http-equiv="content-Type" content="text/html;chars ...

  3. 如何使用mysqldump命令导入导出数据库下的数据或表结构(远程or本地都适合)

    不多说,直接上干货! https://www.cloudera.com/documentation/manager/5-1-x/Cloudera-Manager-Installation-Guide/ ...

  4. sqlserver怎么将excel表的数据导入到数据库中

    在数据库初始阶段,我们有些数据在EXCEL中做好之后,需要将EXCEL对应列名(导入后对应数据库表的字段名),对应sheet(改名为导入数据库之后的表名)导入指定数据库, 相当于导入一张表的整个数据. ...

  5. thinkphp导入导出excel表单数据

    在PHP项目经常要导入导出Excel表单. 先去下载PHPExcel类库文件,放到相应位置. 我在thinkphp框架中的位置为ThinkPHP/Library/Org/Util/ 导入 在页面上传e ...

  6. 将数据导出成excel表

    /// <summary> /// 生成excel表 /// </summary> /// <param name="dt">数据表</p ...

  7. 【ITOO 1】将List数据导出Excel表

    需求描述:在课表导入的时候,首先给用户提供模板(excel),然后将用户填写好的数据读取到list集合中.再进行判空处赋值处理,以及去重处理.这篇博客,主要介绍读取excel表和导出excel表的方法 ...

  8. asp.net使用MVC4框架基于NPOI做导出数据到Excel表

    NPOI 是 POI 项目的 .NET 版本.POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目. 使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 ...

  9. PHP将数据导出Excel表中(投机型)

    1.简介 如何利用最简单粗糙暴力的方法将数据写入Excel文件中呢? 因为ms word和excel的文档都支持html文本格式,因此我们可以基于这个原理采用html文本格式进行数据的输出. 在htm ...

随机推荐

  1. 四大开源协议比较:BSD、Apache、GPL、LGPL (转)

    转自:http://www.lupaworld.com/portal.php?mod=view&aid=205552&page=all 本文参考文献:http://www.fsf.or ...

  2. memcache内存估算整理

    参考文章: http://blog.csdn.net/tonyxf121/article/details/7906428 http://zhihuzeye.com/archives/2361 memc ...

  3. linux应用程序开发-文件编程-库函数

    ---恢复内容开始--- c库函数文件操作独立于具体的系统平台,可移植性较好. 库函数-创建和打开 FILE*fopen(const char*filename,const char*mode) mo ...

  4. Linux 系统启动过程

    linux启动时我们会看到许多启动信息. Linux系统的启动过程并不是大家想象中的那么复杂,其过程可以分为5个阶段: 内核的引导. 运行init. 系统初始化. 建立终端 . 用户登录系统. 内核引 ...

  5. Linux 下 git连接github的使用

    1.安装git sudo apt-get install git 2.创建github帐号 3.Linux创建SSH密钥: ssh-keygen  //一直默认 4.将公钥加入到Github账户信息A ...

  6. SPSS数据分析—相关分析

    相关系数是衡量变量之间相关程度的度量,也是很多分析的中的当中环节,SPSS做相关分析比较简单,主要是区别如何使用这些相关系数,如果不想定量的分析相关性的话,直接观察散点图也可以. 相关系数有一些需要注 ...

  7. css文字两端对齐

    css文字两端对齐 text-align:Justify(火狐); text-justify:inter-ideograph(IE) text-justify(IE) 基本语法 text-justif ...

  8. DEV GridControl TableView隔行换色/奇偶行换色

    GridControl中的TableView“奇偶行换色”这件事情纠结了我好几天,虽然已经是上个月的事情,好歹记录一下吧,万一有谁要用到呢. GridControl是长这个样子的, <dxg:G ...

  9. OllyDBG 1.10

    OllyDBG 1.10 OllyDBG.exeOllyDBG SoftICE文件->打开 (快捷键是 F3)F2 断点 F9F8 步过 F10F7 步入 F8F4 运行到位置 F7F9 运行 ...

  10. subplot demo

    Y=[6484.05190614446 3479.60374683749 2326.82521799362 862.207727785871 423.711173743815 299.23540931 ...