//拷贝

sheet.Cells["6:12"].Copy(sheet.Cells["1:2"]);

//边框无

sheet.Cells[(i * 6 + i + j), 2].Style.Border.Right.Style = ExcelBorderStyle.None;

//设边框颜色

sheet.Cells[5, 5 + i].Style.Border.Right.Style = ExcelBorderStyle.Thin;
sheet.Cells[5, 5 + i].Style.Border.Right.Color.SetColor(Color.FromArgb(223, 223, 223));

//背景色
sheet.Cells[5, 5 + i].Style.Fill.PatternType = ExcelFillStyle.Solid;

sheet.Cells[5, 5 + i].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(89, 89, 89));

//垂直居中

sheet.Cells[5, 5 + i].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

//上下居中

sheet.Cells[5, 5 + i].Style.VerticalAlignment = ExcelVerticalAlignment.Center;

//字体颜色

sheet.Cells[5, 5 + i].Style.Font.Color.SetColor(Color.FromArgb(255, 255, 255));

using (ExcelPackage p = new ExcelPackage(fi))
                {
                    foreach (ExcelWorksheet sheet in p.Workbook.Worksheets)
                    {
                        //Template
                        switch (selectProject)
                        {
                            case "0":
                                for (int i = 2; i < rtList.Count; i++)
                                {
                                    sheet.Cells["6:12"].Copy(sheet.Cells[(i * 6 + i - 1) + ":" + (i * 6 + i + 5)]);
                                    if (i == rtList.Count - 1)
                                    {
                                        for (int j = -1; j < 6; j++)
                                        {
                                            sheet.Cells[(i * 6 + i + j), 2].Style.Border.Right.Style = ExcelBorderStyle.None;
                                            sheet.Cells[(i * 6 + i + j), 1].Style.Border.Right.Style = ExcelBorderStyle.None;
                                        }
                                    }
                                }
                                break;
                            case "1":
                                for (int i = 2; i < rtList.Count; i++)
                                {
                                    sheet.Cells["6:7"].Copy(sheet.Cells[(6 + i + i - 2) + ":" + (6 + i + i - 1)]);
                                    if (i == rtList.Count - 1)
                                    {
                                        sheet.Cells[(6 + i + i - 2 ), 1, (6 + i + i - 1),1].Style.Border.Right.Style = ExcelBorderStyle.None;
                                        sheet.Cells[(6 + i + i - 2), 2, (6 + i + i - 1), 2].Style.Border.Right.Style = ExcelBorderStyle.None;
                                        sheet.Cells[(6 + i + i - 2), 3, (6 + i + i - 1), 3].Style.Border.Left.Style = ExcelBorderStyle.None;
                                        sheet.Cells[(6 + i + i - 2), 2, (6 + i + i - 1), 2].Style.Border.Left.Style = ExcelBorderStyle.None;                                        
                                    }
                                }
                                break;
                            case "2":
                                for (int i = 2; i < rtList.Count; i++)
                                {
                                    sheet.Cells["6:9"].Copy(sheet.Cells[(i * 4 + 2) + ":" + (i * 4 + 5)]);
                                    if (i == rtList.Count - 1)
                                    {
                                        for (int j = 0; j < 4; j++)
                                        {
                                            sheet.Cells[(i * 4 + 2 + j), 2].Style.Border.Right.Style = ExcelBorderStyle.None;
                                            sheet.Cells[(i * 4 + 2 + j), 1].Style.Border.Right.Style = ExcelBorderStyle.None;
                                        }
                                    }
                                }
                                break;
                        }
                        
                        
                        //Title
                        sheet.Cells[1, 2].Value = bs.MEASURES_NM.ToString();
                        sheet.Cells[2, 2].Value = bs.MEASURES_OVERVIEW.ToString();
                        sheet.Cells[3, 2].Value = bs.BEGIN_DATE.ToString() + " ~ " + bs.END_DATE.ToString();
                        //TableTitle
                        sheet.Cells[5, 1].Value="分類";
                        sheet.Cells[5, 2].Value="媒体属性";
                        sheet.Cells[5, 3].Value="ASP/ASID/AS名/運営者";
                        sheet.Cells[5, 4].Value="項目";
                        for (int i = 0; i < rtList[0].DETAIL_TITLE.Count(); i++)
                        {
                            sheet.Cells[5, 5 + i].Value = rtList[0].DETAIL_TITLE[i].ToString().Replace("年", "/").Replace("月", "").Substring(2);
                        }

//Contents
                        int currentrow = 6;
                        for (int i = 1; i < rtList.Count; i++)
                        {
                            switch (selectProject)
                            {
                                case "0":
                                    #region すべて
                                    //1 DataRow
                                    sheet.Cells[currentrow, 1].Value = rtList[i].PROM_NM;
                                    sheet.Cells[currentrow, 2].Value = rtList[i].SITE_CATEGORY;
                                    sheet.Cells[currentrow, 3].Value = rtList[i].ASP_ID;
                                    sheet.Cells[currentrow, 4].Value = MBProject.PV数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.PV_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow, 5 + j].Value = rtList[i].DETAIL.PV_CNT_LIST[j].CalculateValue;
                                    }
                                    //2 DataRow
                                    sheet.Cells[currentrow + 1, 3].Value = rtList[i].AS_ID;
                                    sheet.Cells[currentrow + 1, 4].Value = MBProject.Click数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.CL_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 1, 5 + j].Value = rtList[i].DETAIL.CL_CNT_LIST[j].CalculateValue;
                                    }
                                    //3 DataRow
                                    sheet.Cells[currentrow + 2, 3].Formula = "HYPERLINK(\"" + rtList[i].URL + "\",\"" + rtList[i].AS_NM + "\")";
                                    sheet.Cells[currentrow + 2, 4].Value = MBProject.Click率.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.CL_RATE_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 2, 5 + j].Value = rtList[i].DETAIL.CL_RATE_LIST[j].FormateValue;
                                    }
                                    //4 DataRow
                                    sheet.Cells[currentrow + 3, 3].Value = rtList[i].UNEI_USER_NAME;
                                    sheet.Cells[currentrow + 3, 4].Value = MBProject.申込数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.MOSHI_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 3, 5 + j].Value = rtList[i].DETAIL.MOSHI_CNT_LIST[j].CalculateValue;
                                    }
                                    //5 DataRow
                                    sheet.Cells[currentrow + 4, 4].Value = MBProject.CV率.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.CV_RATE_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 4, 5 + j].Value = rtList[i].DETAIL.CV_RATE_LIST[j].FormateValue;
                                    }
                                    //6 DataRow
                                    sheet.Cells[currentrow + 5, 4].Value = MBProject.契約数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.KEIYAKU_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 5, 5 + j].Value = rtList[i].DETAIL.KEIYAKU_CNT_LIST[j].CalculateValue;
                                    }
                                    //7 DataRow
                                    sheet.Cells[currentrow + 6, 4].Value = MBProject.契約率.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.KEIYAKU_RATE_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 6, 5 + j].Value = rtList[i].DETAIL.KEIYAKU_RATE_LIST[j].FormateValue;
                                    }
                                    currentrow += 7;
                                    #endregion
                                    break;
                                case "1":
                                    #region 申込数
                                    //1 DataRow 申込数
                                    sheet.Cells[currentrow, 1].Value = rtList[i].PROM_NM;
                                    sheet.Cells[currentrow, 2].Value = rtList[i].SITE_CATEGORY;
                                    sheet.Cells[currentrow, 3].Formula = "HYPERLINK(\"" + rtList[i].URL + "\",\"" + rtList[i].AS_NM + "\")";
                                    sheet.Cells[currentrow + 1, 3].Value = rtList[i].UNEI_USER_NAME;
                                    sheet.Cells[currentrow, 4].Value = MBProject.申込数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.MOSHI_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow, 5 + j].Value = rtList[i].DETAIL.MOSHI_CNT_LIST[j].CalculateValue;                                        
                                    }
                                    currentrow += 2;
                                    #endregion
                                    break;
                                case "2":
                                    #region 申込数・CV率・契約数・契約率
                                    //1 DataRow 申込数
                                    sheet.Cells[currentrow, 1].Value = rtList[i].PROM_NM;
                                    sheet.Cells[currentrow, 2].Value = rtList[i].SITE_CATEGORY;
                                    sheet.Cells[currentrow, 3].Value = rtList[i].ASP_ID;
                                    sheet.Cells[currentrow, 4].Value = MBProject.申込数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.MOSHI_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow, 5 + j].Value = rtList[i].DETAIL.MOSHI_CNT_LIST[j].CalculateValue;
                                    }
                                    //2 DataRow CV率
                                    sheet.Cells[currentrow + 1, 3].Value = rtList[i].AS_ID;
                                    sheet.Cells[currentrow + 1, 4].Value = MBProject.CV率.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.CV_RATE_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 1, 5 + j].Value = rtList[i].DETAIL.CV_RATE_LIST[j].FormateValue;
                                    }
                                    //3 DataRow 契約数
                                    sheet.Cells[currentrow + 2, 3].Formula = "HYPERLINK(\"" + rtList[i].URL + "\",\"" + rtList[i].AS_NM + "\")";
                                    sheet.Cells[currentrow + 2, 4].Value = MBProject.契約数.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.KEIYAKU_CNT_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 2, 5 + j].Value = rtList[i].DETAIL.KEIYAKU_CNT_LIST[j].CalculateValue;
                                    }
                                    //4 DataRow 契約率
                                    sheet.Cells[currentrow + 3, 3].Value = rtList[i].UNEI_USER_NAME;
                                    sheet.Cells[currentrow + 3, 4].Value = MBProject.契約率.ToString();
                                    for (int j = 0; j < rtList[i].DETAIL.KEIYAKU_RATE_LIST.Count(); j++)
                                    {
                                        sheet.Cells[currentrow + 3, 5 + j].Value = rtList[i].DETAIL.KEIYAKU_RATE_LIST[j].FormateValue;
                                    }
                                    currentrow += 4;
                                    #endregion
                                    break;
                            }
                        }

}

p.Workbook.Worksheets[1].View.TabSelected = true;
                    p.Save();
                }

Epplus 使用案例的更多相关文章

  1. 建议收藏:.net core 使用导入导出Excel详细案例,精心整理源码已更新至开源模板

    还记得刚曾经因为导入导出不会做而发愁的自己吗?我见过自己前同事因为一个导出改了好几天,然后我们发现虽然有开源的库但是用起来却不得心应手,主要是因为百度使用方案的时候很多方案并不能解决问题. 尤其是尝试 ...

  2. [转]比NPOI更討喜的Excel元件-EPPlus

    本文转自:http://blog.darkthread.net/post-2012-05-12-epplus.aspx 前陣子發表 [潛盾機]將檔案結構匯成Excel文件,從網友佑翔的留言(特此感謝) ...

  3. 一次 C# 查詢數據庫 算法優化的案例

    最近有次在修改某段程式時,發現一段程式算法看起來簡單. 但背後因為多次查詢數據庫,導致效能問題. 這段程式主要是利用 EPPLUS 讀取 Excel 資料,檢查資料是否已存在數據庫中,若有就將已存在的 ...

  4. .NET CORE webapi epplus 导入导出 (实习第一个月的笔记)

    最近有个需求就是网页表格里面的数据导出到excel  于是从各位前辈的博客园搜了搜demo  大部分非为两类 都是用的插件NPOI和Eppluse ,因此在这里就介绍Eppluse 用法,还有就是在博 ...

  5. 数据库优化案例——————某市中心医院HIS系统

    记得在自己学习数据库知识的时候特别喜欢看案例,因为优化的手段是容易掌握的,但是整体的优化思想是很难学会的.这也是为什么自己特别喜欢看案例,今天也开始分享自己做的优化案例. 最近一直很忙,博客产出也少的 ...

  6. SQL Server内存遭遇操作系统进程压榨案例

    场景: 最近一台DB服务器偶尔出现CPU报警,我的邮件报警阈(请读yù)值设置的是15%,开始时没当回事,以为是有什么统计类的查询,后来越来越频繁. 探索: 我决定来查一下,究竟是什么在作怪,我排查的 ...

  7. solr_架构案例【京东站内搜索】(附程序源代码)

    注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...

  8. Yeoman 官网教学案例:使用 Yeoman 构建 WebApp

    STEP 1:设置开发环境 与yeoman的所有交互都是通过命令行.Mac系统使用terminal.app,Linux系统使用shell,windows系统可以使用cmder/PowerShell/c ...

  9. 了不起的 nodejs-TwitterWeb 案例 bug 解决

    了不起的nodejs算是一本不错的入门书,不过书中个别案例存在bug,按照书中源码无法做出和书中相同效果,原本兴奋的心情掺杂着些许失落. 现在我们看一下第七章HTTP,一个Twitter Web客户端 ...

随机推荐

  1. synchronous interrupt and asynchronous interrupt

    Asynchronous interrupt 中斷请求信号来自CM3内核的外面,来自各种片上外设和外扩的外设,对CM3来说是"异步"的: e.g. usb otg device S ...

  2. Gym 101064 D Black Hills golden jewels 【二分套二分/给定一个序列,从序列中任意取两个数形成一个和,两个数不可相同,要求求出第k小的组合】

    D. Black Hills golden jewels time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. BZOJ1801 [Ahoi2009]chess 中国象棋(DP, 计数)

    题目链接 [Ahoi2009]chess 中国象棋 设$f[i][j][k]$为前i行,$j$列放了1个棋子,$k$列放了2个棋子的方案数 分6种情况讨论,依次状态转移. #include <b ...

  4. fetch API 简单解读

    http://f2e.souche.com/blog/fetch-api-jie-du/?utm_source=tuicool&utm_medium=referral 在我们日常的前端开发中, ...

  5. Java中获取当前时间并格式化

    主要有两种方式,其中使用Date比较好控制,代码如下: //使用Calendar Calendar now = Calendar.getInstance(); System.out.println(& ...

  6. Beginning Auto Layout Tutorial in iOS 7: Part 1

    可以更好的结局屏幕方向和兼容iphone和ipad的解决方案. iOS6有一个新的技术auto layout来帮助解决这个问题.这个技术不仅可以支持app不同尺寸下的开发,而且你也不需要为每一种语言创 ...

  7. mac搭建安卓开发环境

    下载 android studio,利用android studio自带sdk manager下载安卓sdk,在sdk manager中设置相关代理地址,下载完sdk后,在bash_profile中把 ...

  8. GraphMatrix::BFS广度优先搜索

    查找某一结点的邻居: virtual int firstNbr(int i) { return nextNbr(i, n); } //首个邻接顶点 virtual int nextNbr(int i, ...

  9. C 作用域规则

    C 作用域规则 任何一种编程中,作用域是程序中定义的变量所存在的区域,超过该区域变量就不能被访问.C 语言中有三个地方可以声明变量: 在函数或块内部的局部变量 在所有函数外部的全局变量 在形式参数的函 ...

  10. GSL 1.15 and 1.16 building with Visual Studio 2010 --FROM 4fire

    http://4fire.wordpress.com/2012/03/18/gsl-1-15-building-with-visual-studio-2010/ Update 05/02/2014: ...