Epplus 使用案例

//拷贝

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();
                }

时间: 2024-10-21 10:51:14

Epplus 使用案例的相关文章

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

本文转自:http://blog.darkthread.net/post-2012-05-12-epplus.aspx 前陣子發表 [潛盾機]將檔案結構匯成Excel文件,從網友佑翔的留言(特此感謝),認識了一顆被我錯過的l好元件 -- EPPlus! NPOI源於POI,在很多介面設計上,帶點Java的觀點與風格,雖然能實現各項Excel操作,但函數介面及呼叫步驟,總讓.NET老鳥感覺不順手,就像用筷子吃手扒雞一樣彆扭.例如: 要寫入文字到新的Cell,必須先CreateRow(),再Crea

一次測試即學習的案例

一般工程人員都知道 TDD 的使用方式,也明白 UnitTest 對於程式碼品質有著良好的保護 但比較少去探討的另一個好處應該是「學習」這件事了 雖然一般來說我們寫 Testing 其實是針對已知的事物(Business logic)去做測試與保護 比較少做未知的探索測試,但在一般有寫 Testing 情況下,還是有機會學習的 (所以還是鼓勵大家多多寫測試 ) 以下我分享一個測試即學習的案例給各位小夥伴 這個案例其實很簡單,我寫了一個 UnitTest 想要測試 EPPlus 在讀取完我建立的

解决 libev.so.4()(64bit) is needed by percona-xtrabackup-2.3.4-1.el6.x86_64案例

在mysql主从同步时经常会用到Xtra, XtraBackup可以说是一个相对完美的免费开源数据备份工具,支持在线无锁表同步复制和可并行高效率的安全备份恢复机制相比mysqldump来说优势较大好处多,在RHEL6中安装XtraBackup时会发生缺少依赖包的现象 本案例针对Xtra缺少依赖包的情况进行安装分析解决 1.本实验环境 [root@master ~]# uname  -r 2.6.32-573.el6.x86_64 [root@master ~]# cat /etc/redhat-

系统内存耗尽的案例分析

近日遇到一个RAC节点hang导致节点被重启的问题,最后经过分析,发现在系统运行一段时间后,系统内存就会耗尽,原本256G的内存,最后只剩几百M. 1. 问题时间段的TOP输出可以看到,内存只剩7G,而分析内存问题,TOP输出是不够的,一般情况下,Database的SGA和PGA是内存使用大户,所以,在TOP很难发现谁是使用内存最多的. 除非某些进程内存使用的格外明显 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Linux OSWbb v7.3.

案例分享:使用员工电脑监控,有什么好处?

下面分享一个真实案例: 北京**科技有限公司梁总想要通过企业员工电脑监控来对员工上网进行管理,通过软件的监控与管理,减少上班与工作无关的上网行为,从而提高员工有效工作效率. 员工工作效率低,上网无节制 梁总发现,最近公司业绩颇有下滑的趋势,于是想要了解员工的详细工作进展,当他在公司时,每一个员工看起来都在忙碌着工作,似乎没什么不妥,但是原因到底是什么呢?难道这只是表面的工作,平时我不在公司,是这样的状态吗?员工会在我离开时,大部分时间在做与工作无关的事,上网聊天?购物? 后来,梁总经朋友介绍,说

OpenFEA应用案例

OpenFEA分析性能卓越,使用简便,自发布以来,即受到大数据分析师的推祟,在各行各业广泛得到应用.    案例一:网络安全态势感知     网络安全态势感知,是基于OpenFEA技术,通过对影响网络安全的资产.漏洞.攻击.异常流量等因素进行大数据分析,使用户宏观.全局的了解网络的安全状况,动态把握特定环境下的网络风险演变过程.从而有效保障网络空间的安全,构筑"防护+监测"的全方位安全保障体系.      案例二:用户异常行为分析     用户异常行为分析(简称UBA),是以OpenF

Android Multimedia框架总结(十四)Camera框架初识及自定义相机案例

转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼yuiop:http://blog.csdn.net/hejjunlin/article/details/52738492 前言:国庆节告一段落,又是新一月,上月主要是围绕MediaPlayer相关展开,从今天开始,开始分析多媒体框架中的Camera模块,看下今天的Agenda: Camera拍照 Camera录像 新API android.hardware.camera2 新旧API特点对比 Camera自定义相机 新API andro

Ext.js入门:常用组件与综合案例(七)

一:datefield简单示例 二:timefield简单示例 三:numberfield简单示例 四:FormPanel提交 datefield简单示例: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="Ext/resources/css/ext-all.css&

linux入门之grep 正则表达式案例

grep 正则表达式案例 案例一: 1.显示/proc/meminfo文件中以大小s开头的行:(要求:使用两种方式) #grep -i '^s' /proc/meminfo #grep  '^[Ss]' /proc/meminfo #grep -E '^(s|S)' /proc/meinfo 2.显示/etc/passwd文件中不以/bin/bash结尾的行 #grep -v '/bin/bash$' /etc/passwd 3.显示用户rpc默认的shell程序 #grep '^\<rpc\>