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. SelectMany等LINQ运算符的使用

    public class Racer : IComparable<Racer>, IFormattable { public string FirstName { get; set; } ...

  2. logstash安装与基础用法

    若是搭建elk,建议先安装好elasticsearch 来自官网,版本为2.3 wget -c https://download.elastic.co/logstash/logstash/packag ...

  3. mysql 一些基础的语法和命令

    语法: SELECT 属性列表       FROM 表名或视图名       [ WHERE 条件表达式1 ]       [ GROUP BY 属性名1 [ HAVING 条件表达式2 ] [ W ...

  4. GSEA的使用

    下载GSEA 网址:http://software.broadinstitute.org/gsea/downloads.jsp gsea2-2.2.2.jar c2.cp.kegg.v5.1.symb ...

  5. Android 签名工具 shell脚本

    signApk.sh #!/bin/bash #$1 signed and unaligned apk #$2 unsigned apk #$3 aligned apk #./signApk.sh t ...

  6. Hbase之修改表结构

    import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; impo ...

  7. js高级程序设计(七)BOM

    window 对象 BOM 的核心对象是window,它表示浏览器的一个实例.在浏览器中,window 对象有双重角色,它既是通过JavaScript 访问浏览器窗口的一个接口,又是ECMAScrip ...

  8. Java之美[从菜鸟到高手演变]之设计模式

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...

  9. 使用jQuery Mobile的注意事项(译)

    翻译编辑自:http://www.appnovation.com/blog/7-things-know-about-jquery-mobile-working-it 一.Android和IOS的内置键 ...

  10. linux 环境变量PATH路径的三种方法

    转:http://www.jb51.net/LINUXjishu/150167.html 总结:修改1.#PATH=$PATH:/etc/apache/bin  或者#vi /etc/profile ...