using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using NPOI.XSSF;
using System.Text;
using NPOI.SS.Util;
using NPOI.SS.Formula.Eval;
namespace TMC.Opti_PlatForm.Timer.CLASS
{
public class Generate_LTE_Post_Evaluation_Report : System.Web.UI.Page
{
public string Generate_LTE_Post_Evaluation_Report2(string enodeb_name, string date, string enodebid, string city, string config, string station_type, string address)
{
Model.RETURN_RESULT r = new Model.RETURN_RESULT();
r.result = "1";
r.data = "success"; //默认值
string basePath = Environment.CurrentDirectory;
string excelModelPath = basePath + "\\excel\\template\\LTE单站后评估报告模板\\LTE单站后评估报告模板.xlsx";
string base_export_path = basePath + "\\UpPostFile\\" + DateTime.Now.ToString("yyyyMMdd")+"\\";
if (!File.Exists(excelModelPath))
{
r.data = "报表模版不存在";
r.result = "-1";
return Newtonsoft.Json.JsonConvert.SerializeObject(r);
}
if (!Directory.Exists(base_export_path))
{
Directory.CreateDirectory(base_export_path);
}
string export_path = base_export_path + "LTE单站后评估报告_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
DataSet ds = ImportExceltoDs(File.OpenRead(excelModelPath));
DataTable dt_rate = new DataTable(); //存储各种比率的表
dt_rate.Columns.Add("SCAN_START_TIME");
dt_rate.Columns.Add("RRC连接建立成功率");
dt_rate.Columns.Add("E-RAB建立成功率");
dt_rate.Columns.Add("无线接通率");
dt_rate.Columns.Add("无线掉线率(小区级)");
dt_rate.Columns.Add("无线接通率(QCI=1)");
dt_rate.Columns.Add("E-RAB掉线率(QCI=1)");
dt_rate.Columns.Add("eNB间切换成功率");
dt_rate.Columns.Add("eNB内切换成功率");
dt_rate.Columns.Add("切换成功率");
dt_rate.Columns.Add("eSRVCC切换成功率");
dt_rate.Columns.Add("VoLTE用户切换成功率(QCI=1)");
dt_rate.Columns.Add("MR(小于-110dbm采样点占比)");
IWorkbook workbook = null;
ISheet sheet = null;
ISheet sheet_alarmList = null;
ISheet sheet_alarmMonitor = null;
ISheet sheet_report = null;
ISheet sheet_problemsSum = null;
ISheet sheet_zhibiaoDefinition = null;
string fileName = excelModelPath;
try
{
// 2007版本
if (fileName.IndexOf(".xlsx") > 0)
workbook = new XSSFWorkbook();
// 2003版本
//else if (fileName.IndexOf(".xls") > 0)
//workbook = new HSSFWorkbook();
sheet_report = workbook.CreateSheet("报告页");
sheet_alarmList = workbook.CreateSheet("重要告警列表");
sheet_alarmMonitor = workbook.CreateSheet("站点重要告警监控");
sheet = workbook.CreateSheet("站点后台指标监控");
sheet_problemsSum = workbook.CreateSheet("问题汇总");
sheet_zhibiaoDefinition = workbook.CreateSheet("指标定义");
XSSFCellStyle headStyle = workbook.CreateCellStyle() as XSSFCellStyle; //2007
headStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
XSSFFont font = workbook.CreateFont() as XSSFFont;
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font);
IDataFormat dataformat = workbook.CreateDataFormat();
ICellStyle cellStyle_per = workbook.CreateCellStyle();
cellStyle_per.DataFormat = dataformat.GetFormat("0.00%");//百分数【小数点后有几个0表示精确到显示小数点后几位】
ICellStyle date_style = workbook.CreateCellStyle();
date_style.DataFormat = dataformat.GetFormat("yyyy年MM月dd日");
XSSFCellStyle leftStyle = workbook.CreateCellStyle() as XSSFCellStyle; //2007
leftStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
DataTable dt_siteMonitor = ds.Tables[3]; //站点后台指标监控
//取得列的数量
int[] arrColWidth_siteMonitor = new int[dt_siteMonitor.Columns.Count]; //模板中获取 站点后台指标监控 列的数量
foreach (DataColumn item in dt_siteMonitor.Columns)
{
arrColWidth_siteMonitor[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length; //计算列宽的长度
}
string start_time = Convert.ToDateTime(date).AddDays(1).ToString("yyyy-MM-dd");
string end_time = Convert.ToDateTime(start_time).AddDays(6).ToString("yyyy-MM-dd");
BLL.DW dw = new BLL.DW();
string sql = "select f.SCAN_START_TIME,f.ENODEB_NAME,f.CELL_LC_NAME,f.CELL_CI,f.VOLTE_PDCP_UPOCT_QC1,f.VOLTE_PDCP_UPOCT_QC2,f.PDCP_UPOCTUL_TUNTU,f.PDCP_UPOCTDL_TUNTU,f.RRC_ATTCONNESTAB,f.RRC_SUCCCONNESTAB,f.ERAB_NBRATTESTAB,f.ERAB_NBRSUCCESTAB,f.CONTEXT_ATTRELENB,f.CONTEXT_ATTRELENB_NORMAL,f.CONTEXT_SUCCINITALSETUP,f.CONTEXT_NBRLEFT,f.ERAB_HOFAIL,f.ERAB_NBRREQRELENB," +
"f.ERAB_NBRLEFT,f.ERAB_NBRHOINC,f.ERAB_NBRSUCCESTAB_QC1,f.ERAB_NBRATTESTAB_QC1,f.HO_SUCCOUTINTERENBS1,f.HO_SUCCOUTINTERENBX2,f.HO_ATTOUTINTERENBS1,f.HO_ATTOUTINTERENBX2,f.NbrReqRelEnb_Normal,f.ERAB_NBRREQRELENB_QC1,f.ERAB_HOFAIL_QC1,f.ERAB_NBRLEFT_QC1,f.ERAB_NBRHOINC_QC1,f.ERAB_NRRELE_NORMAL_QC1,f.HO_SUCCOUTINTRAENB,f.HO_ATTOUTINTRAENB,f.IRATHO_SUCCOUTGERAN,f.IRATHO_ATTOUTGERAN," +
"f.HO_SUCCOUTINTERENBS1_1,f.HO_SUCCOUTINTERENBX2_1,f.HO_SUCCOUTINTRAENB_1,f.HO_ATTOUTINTERENBS1_1,f.HO_ATTOUTINTERENBX2_1,f.HO_ATTOUTINTRAENB_1," +
" g.RSRP_COUNT, g.RSRP_00_06 from (select * from sts_lte_cell_day@Topdb30 where SCAN_START_TIME >= to_date('" + start_time + "','yyyy-mm-dd') and SCAN_START_TIME <= to_date('" + end_time + "','yyyy-mm-dd') and ENODEB_NAME='" + enodeb_name + "')f left join STS_LTE_CELL_RSRP_DAY@Topdb30 g on f.CELL_CI = g.CELL_ID order by f.SCAN_START_TIME asc";
DataTable dt = new DataTable();
dt = dw.GetTableBySqlString(sql).Tables[0];
//dt = dt_siteMonitor; //模拟表数据
int iRow = 1; //初始行号
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
int intTemp = Encoding.GetEncoding(936).GetBytes(dt.Rows[i][j].ToString()).Length; //计算单元格的长度
if (intTemp > arrColWidth_siteMonitor[j]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_siteMonitor[j] = intTemp;
}
}
#region 写单元格
IRow row = sheet.CreateRow(iRow + i);
string SCAN_START_TIME = dt.Rows[i]["SCAN_START_TIME"].ToString().Trim();
//string SCAN_START_TIME = dt.Rows[i][0].ToString().Trim();
row.CreateCell(0).SetCellValue(SCAN_START_TIME);
string ENODEB_NAME = dt.Rows[i]["ENODEB_NAME"].ToString().Trim();
//string ENODEB_NAME = dt.Rows[i][1].ToString().Trim();
row.CreateCell(1).SetCellValue(ENODEB_NAME);
string CELL_LC_NAME = dt.Rows[i]["CELL_LC_NAME"].ToString().Trim();
//string CELL_LC_NAME = dt.Rows[i][2].ToString().Trim();
row.CreateCell(2).SetCellValue(CELL_LC_NAME);
string CELL_CI = dt.Rows[i]["CELL_CI"].ToString().Trim();
//string CELL_CI = dt.Rows[i][3].ToString().Trim();
row.CreateCell(3).SetCellValue(CELL_CI);
string VOLTE_PDCP_UPOCT_QC1 = dt.Rows[i]["VOLTE_PDCP_UPOCT_QC1"].ToString().Trim(); //VoLTE语音总流量
//string VOLTE_PDCP_UPOCT_QC1 = dt.Rows[i][4].ToString().Trim(); //VoLTE语音总流量
row.CreateCell(4).SetCellValue(VOLTE_PDCP_UPOCT_QC1);
string VOLTE_PDCP_UPOCT_QC2 = dt.Rows[i]["VOLTE_PDCP_UPOCT_QC2"].ToString().Trim(); //volte视频总流量
//string VOLTE_PDCP_UPOCT_QC2 = dt.Rows[i][5].ToString().Trim(); //volte视频总流量
row.CreateCell(5).SetCellValue(VOLTE_PDCP_UPOCT_QC2);
string PDCP_UPOCTUL_TUNTU = dt.Rows[i]["PDCP_UPOCTUL_TUNTU"].ToString().Trim(); //自_PDCP层上行流量_Eutrancell
//string PDCP_UPOCTUL_TUNTU = dt.Rows[i][6].ToString().Trim(); //自_PDCP层上行流量_Eutrancell
row.CreateCell(6).SetCellValue(PDCP_UPOCTUL_TUNTU);
string PDCP_UPOCTDL_TUNTU = dt.Rows[i]["PDCP_UPOCTDL_TUNTU"].ToString().Trim(); //自_PDCP层下行流量_Eutrancell
//string PDCP_UPOCTDL_TUNTU = dt.Rows[i][7].ToString().Trim(); //自_PDCP层下行流量_Eutrancell
row.CreateCell(7).SetCellValue(PDCP_UPOCTDL_TUNTU);
string RRC_ATTCONNESTAB = dt.Rows[i]["RRC_ATTCONNESTAB"].ToString().Trim(); //RRC连接建立请求次数
//string RRC_ATTCONNESTAB = dt.Rows[i][8].ToString().Trim(); //RRC连接建立请求次数
row.CreateCell(8).SetCellValue(RRC_ATTCONNESTAB);
string RRC_SUCCCONNESTAB = dt.Rows[i]["RRC_SUCCCONNESTAB"].ToString().Trim(); //RRC连接建立成功次数
//string RRC_SUCCCONNESTAB = dt.Rows[i][9].ToString().Trim(); //RRC连接建立成功次数
row.CreateCell(9).SetCellValue(RRC_SUCCCONNESTAB);
string ERAB_NBRATTESTAB = dt.Rows[i]["ERAB_NBRATTESTAB"].ToString().Trim(); //E-RAB建立请求数
//string ERAB_NBRATTESTAB = dt.Rows[i][10].ToString().Trim(); //E-RAB建立请求数
row.CreateCell(10).SetCellValue(ERAB_NBRATTESTAB);
string ERAB_NBRSUCCESTAB = dt.Rows[i]["ERAB_NBRSUCCESTAB"].ToString().Trim(); //E-RAB建立成功数
//string ERAB_NBRSUCCESTAB = dt.Rows[i][11].ToString().Trim(); //E-RAB建立成功数
row.CreateCell(11).SetCellValue(ERAB_NBRSUCCESTAB);
string CONTEXT_ATTRELENB = dt.Rows[i]["CONTEXT_ATTRELENB"].ToString().Trim(); //eNB请求释放上下文数
//string CONTEXT_ATTRELENB = dt.Rows[i][12].ToString().Trim(); //eNB请求释放上下文数
row.CreateCell(12).SetCellValue(CONTEXT_ATTRELENB);
string CONTEXT_ATTRELENB_NORMAL = dt.Rows[i]["CONTEXT_ATTRELENB_NORMAL"].ToString().Trim(); //正常的eNB请求释放上下文数
//string CONTEXT_ATTRELENB_NORMAL = dt.Rows[i][13].ToString().Trim(); //正常的eNB请求释放上下文数
row.CreateCell(13).SetCellValue(CONTEXT_ATTRELENB_NORMAL);
string CONTEXT_SUCCINITALSETUP = dt.Rows[i]["CONTEXT_SUCCINITALSETUP"].ToString().Trim(); //初始上下文建立成功次数
//string CONTEXT_SUCCINITALSETUP = dt.Rows[i][14].ToString().Trim(); //初始上下文建立成功次数
row.CreateCell(14).SetCellValue(CONTEXT_SUCCINITALSETUP);
string CONTEXT_NBRLEFT = dt.Rows[i]["CONTEXT_NBRLEFT"].ToString().Trim(); //遗留上下文个数
//string CONTEXT_NBRLEFT = dt.Rows[i][15].ToString().Trim(); //遗留上下文个数
row.CreateCell(15).SetCellValue(CONTEXT_NBRLEFT);
string ERAB_HOFAIL = dt.Rows[i]["ERAB_HOFAIL"].ToString().Trim(); //切出失败的E-RAB数
//string ERAB_HOFAIL = dt.Rows[i][16].ToString().Trim(); //切出失败的E-RAB数
row.CreateCell(16).SetCellValue(ERAB_HOFAIL);
string ERAB_NBRREQRELENB = dt.Rows[i]["ERAB_NBRREQRELENB"].ToString().Trim(); //eNB请求释放的E-RAB数
//string ERAB_NBRREQRELENB = dt.Rows[i][17].ToString().Trim(); //eNB请求释放的E-RAB数
row.CreateCell(17).SetCellValue(ERAB_NBRREQRELENB);
string ERAB_NBRLEFT = dt.Rows[i]["ERAB_NBRLEFT"].ToString().Trim(); //遗留E-RAB个数
//string ERAB_NBRLEFT = dt.Rows[i][18].ToString().Trim(); //遗留E-RAB个数
row.CreateCell(18).SetCellValue(ERAB_NBRLEFT);
string ERAB_NBRHOINC = dt.Rows[i]["ERAB_NBRHOINC"].ToString().Trim(); //切换入E-RAB数
//string ERAB_NBRHOINC = dt.Rows[i][19].ToString().Trim(); //切换入E-RAB数
row.CreateCell(19).SetCellValue(ERAB_NBRHOINC);
string ERAB_NBRSUCCESTAB_QC1 = dt.Rows[i]["ERAB_NBRSUCCESTAB_QC1"].ToString().Trim(); //E-RAB建立成功数(QCI=1)
//string ERAB_NBRSUCCESTAB_QC1 = dt.Rows[i][20].ToString().Trim(); //E-RAB建立成功数(QCI=1)
row.CreateCell(20).SetCellValue(ERAB_NBRSUCCESTAB_QC1);
string ERAB_NBRATTESTAB_QC1 = dt.Rows[i]["ERAB_NBRATTESTAB_QC1"].ToString().Trim(); //E-RAB建立请求数(QCI=1)
//string ERAB_NBRATTESTAB_QC1 = dt.Rows[i][21].ToString().Trim(); //E-RAB建立请求数(QCI=1)
row.CreateCell(21).SetCellValue(ERAB_NBRATTESTAB_QC1);
string HO_SUCCOUTINTERENBS1 = dt.Rows[i]["HO_SUCCOUTINTERENBS1"].ToString().Trim(); //eNB间S1切换出成功次数
//string HO_SUCCOUTINTERENBS1 = dt.Rows[i][22].ToString().Trim(); //eNB间S1切换出成功次数
row.CreateCell(22).SetCellValue(HO_SUCCOUTINTERENBS1);
string HO_SUCCOUTINTERENBX2 = dt.Rows[i]["HO_SUCCOUTINTERENBX2"].ToString().Trim(); //eNB间X2切换出成功次数
//string HO_SUCCOUTINTERENBX2 = dt.Rows[i][23].ToString().Trim(); //eNB间X2切换出成功次数
row.CreateCell(23).SetCellValue(HO_SUCCOUTINTERENBX2);
string HO_ATTOUTINTERENBS1 = dt.Rows[i]["HO_ATTOUTINTERENBS1"].ToString().Trim(); //eNB间S1切换出请求次数
//string HO_ATTOUTINTERENBS1 = dt.Rows[i][24].ToString().Trim(); //eNB间S1切换出请求次数
row.CreateCell(24).SetCellValue(HO_ATTOUTINTERENBS1);
string HO_ATTOUTINTERENBX2 = dt.Rows[i]["HO_ATTOUTINTERENBX2"].ToString().Trim(); //eNB间X2切换出请求次数
//string HO_ATTOUTINTERENBX2 = dt.Rows[i][25].ToString().Trim(); //eNB间X2切换出请求次数
row.CreateCell(25).SetCellValue(HO_ATTOUTINTERENBX2);
string NbrReqRelEnb_Normal = dt.Rows[i]["NbrReqRelEnb_Normal"].ToString().Trim(); //正常的eNB请求释放的E-RAB数
//string NbrReqRelEnb_Normal = dt.Rows[i][26].ToString().Trim(); //正常的eNB请求释放的E-RAB数
row.CreateCell(26).SetCellValue(NbrReqRelEnb_Normal);
string ERAB_NBRREQRELENB_QC1 = dt.Rows[i]["ERAB_NBRREQRELENB_QC1"].ToString().Trim(); //eNB请求释放的E-RAB数(QCI=1)
//string ERAB_NBRREQRELENB_QC1 = dt.Rows[i][27].ToString().Trim(); //eNB请求释放的E-RAB数(QCI=1)
row.CreateCell(27).SetCellValue(ERAB_NBRREQRELENB_QC1);
string ERAB_HOFAIL_QC1 = dt.Rows[i]["ERAB_HOFAIL_QC1"].ToString().Trim(); //切出失败的E-RAB数(QCI=1)
//string ERAB_HOFAIL_QC1 = dt.Rows[i][28].ToString().Trim(); //切出失败的E-RAB数(QCI=1)
row.CreateCell(28).SetCellValue(ERAB_HOFAIL_QC1);
string ERAB_NBRLEFT_QC1 = dt.Rows[i]["ERAB_NBRLEFT_QC1"].ToString().Trim(); //遗留E-RAB数(QCI=1)
//string ERAB_NBRLEFT_QC1 = dt.Rows[i][29].ToString().Trim(); //遗留E-RAB数(QCI=1)
row.CreateCell(29).SetCellValue(ERAB_NBRLEFT_QC1);
string ERAB_NBRHOINC_QC1 = dt.Rows[i]["ERAB_NBRHOINC_QC1"].ToString().Trim(); //切换入E-RAB数(QCI=1)
//string ERAB_NBRHOINC_QC1 = dt.Rows[i][30].ToString().Trim(); //切换入E-RAB数(QCI=1)
row.CreateCell(30).SetCellValue(ERAB_NBRHOINC_QC1);
string ERAB_NRRELE_NORMAL_QC1 = dt.Rows[i]["ERAB_NRRELE_NORMAL_QC1"].ToString().Trim(); //正常eNB请求释放的E-RAB数(QCI=1)
//string ERAB_NRRELE_NORMAL_QC1 = dt.Rows[i][31].ToString().Trim(); //正常eNB请求释放的E-RAB数(QCI=1)
row.CreateCell(31).SetCellValue(ERAB_NRRELE_NORMAL_QC1);
string HO_SUCCOUTINTRAENB = dt.Rows[i]["HO_SUCCOUTINTRAENB"].ToString().Trim(); //eNB内切换出成功次数
//string HO_SUCCOUTINTRAENB = dt.Rows[i][32].ToString().Trim(); //eNB内切换出成功次数
row.CreateCell(32).SetCellValue(HO_SUCCOUTINTRAENB);
string HO_ATTOUTINTRAENB = dt.Rows[i]["HO_ATTOUTINTRAENB"].ToString().Trim(); //eNB内切换出请求次数
//string HO_ATTOUTINTRAENB = dt.Rows[i][33].ToString().Trim(); //eNB内切换出请求次数
row.CreateCell(33).SetCellValue(HO_ATTOUTINTRAENB);
string IRATHO_SUCCOUTGERAN = dt.Rows[i]["IRATHO_SUCCOUTGERAN"].ToString().Trim(); //切换至2G成功次数
//string IRATHO_SUCCOUTGERAN = dt.Rows[i][34].ToString().Trim(); //切换至2G成功次数
row.CreateCell(34).SetCellValue(IRATHO_SUCCOUTGERAN);
string IRATHO_ATTOUTGERAN = dt.Rows[i]["IRATHO_ATTOUTGERAN"].ToString().Trim(); //切换至2G请求次数
//string IRATHO_ATTOUTGERAN = dt.Rows[i][35].ToString().Trim(); //切换至2G请求次数
row.CreateCell(35).SetCellValue(IRATHO_ATTOUTGERAN);
string HO_SUCCOUTINTERENBS1_1 = dt.Rows[i]["HO_SUCCOUTINTERENBS1_1"].ToString().Trim(); //VoLTE用户eNB间S1切换出成功次数(QCI=1)
//string HO_SUCCOUTINTERENBS1_1 = dt.Rows[i][36].ToString().Trim(); //VoLTE用户eNB间S1切换出成功次数(QCI=1)
row.CreateCell(36).SetCellValue(HO_SUCCOUTINTERENBS1_1);
string HO_SUCCOUTINTERENBX2_1 = dt.Rows[i]["HO_SUCCOUTINTERENBX2_1"].ToString().Trim(); //VoLTE用户eNB间X2切换出成功次数(QCI=1)
//string HO_SUCCOUTINTERENBX2_1 = dt.Rows[i][37].ToString().Trim(); //VoLTE用户eNB间X2切换出成功次数(QCI=1)
row.CreateCell(37).SetCellValue(HO_SUCCOUTINTERENBX2_1);
string HO_SUCCOUTINTRAENB_1 = dt.Rows[i]["HO_SUCCOUTINTRAENB_1"].ToString().Trim(); //VoLTE用户eNB内切换出成功次数(QCI=1)
//string HO_SUCCOUTINTRAENB_1 = dt.Rows[i][38].ToString().Trim(); //VoLTE用户eNB内切换出成功次数(QCI=1)
row.CreateCell(38).SetCellValue(HO_SUCCOUTINTRAENB_1);
string HO_ATTOUTINTERENBS1_1 = dt.Rows[i]["HO_ATTOUTINTERENBS1_1"].ToString().Trim(); //VoLTE用户eNB间S1切换出请求次数(QCI=1)
//string HO_ATTOUTINTERENBS1_1 = dt.Rows[i][39].ToString().Trim(); //VoLTE用户eNB间S1切换出请求次数(QCI=1)
row.CreateCell(39).SetCellValue(HO_ATTOUTINTERENBS1_1);
string HO_ATTOUTINTERENBX2_1 = dt.Rows[i]["HO_ATTOUTINTERENBX2_1"].ToString().Trim(); //自_复制_VoLTE用户eNB间X2切换出请求次数_Eutrancell
//string HO_ATTOUTINTERENBX2_1 = dt.Rows[i][40].ToString().Trim(); //自_复制_VoLTE用户eNB间X2切换出请求次数_Eutrancell
row.CreateCell(40).SetCellValue(HO_ATTOUTINTERENBX2_1);
string HO_ATTOUTINTRAENB_1 = dt.Rows[i]["HO_ATTOUTINTRAENB_1"].ToString().Trim(); //VoLTE用户eNB内切换出请求次数(QCI=1)
//string HO_ATTOUTINTRAENB_1 = dt.Rows[i][41].ToString().Trim(); //VoLTE用户eNB内切换出请求次数(QCI=1)
row.CreateCell(41).SetCellValue(HO_ATTOUTINTRAENB_1);
string RSRP_COUNT = dt.Rows[i]["RSRP_COUNT"].ToString().Trim(); //参考信号接收功率采样点点数
//string RSRP_COUNT = dt.Rows[i][42].ToString().Trim(); //参考信号接收功率采样点点数
row.CreateCell(42).SetCellValue(RSRP_COUNT);
string RSRP_00_06 = dt.Rows[i]["RSRP_00_06"].ToString().Trim(); //自_参考信号接收功率00-06_Eutrancell
//string RSRP_00_06 = dt.Rows[i][43].ToString().Trim(); //自_参考信号接收功率00-06_Eutrancell
row.CreateCell(43).SetCellValue(RSRP_00_06);
//如果该行计算的相关字段不为空才设置公式计算结果
//通过Cell的CellFormula向单元格中写入公式
//注:直接写公式内容即可,不需要在最前加'='
if (!string.IsNullOrEmpty(RRC_SUCCCONNESTAB) && !string.IsNullOrEmpty(RRC_ATTCONNESTAB))
{
//设置公式时行号要加1
string formula = "IF(I" + (iRow + i + 1) + "=0,1,J" + (iRow + i + 1) + "/I" + (iRow + i + 1) + ")";
row.CreateCell(44).CellFormula = formula; //设置公式 RRC连接建立成功率
row.GetCell(44).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(44), dt_rate, SCAN_START_TIME, "RRC连接建立成功率");
}
if (!string.IsNullOrEmpty(ERAB_NBRSUCCESTAB) && !string.IsNullOrEmpty(ERAB_NBRATTESTAB))
{
string formula = "IF(K" + (iRow + i + 1) + "=0,1,L" + (iRow + i + 1) + "/K" + (iRow + i + 1) + ")";
row.CreateCell(45).CellFormula = formula; //设置公式 E-RAB建立成功率
row.GetCell(45).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(45), dt_rate, SCAN_START_TIME, "E-RAB建立成功率");
}
if (!string.IsNullOrEmpty(RRC_SUCCCONNESTAB) && !string.IsNullOrEmpty(RRC_ATTCONNESTAB) && !string.IsNullOrEmpty(ERAB_NBRSUCCESTAB) && !string.IsNullOrEmpty(ERAB_NBRATTESTAB))
{
string formula = "IF(AND(K" + (iRow + i + 1) + "=0,I" + (iRow + i + 1) + "=0),1,L" + (iRow + i + 1) + "/K" + (iRow + i + 1) + "*J" + (iRow + i + 1) + "/I" + (iRow + i + 1) + ")";
row.CreateCell(46).CellFormula = formula; //设置公式 无线接通率
row.GetCell(46).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(46), dt_rate, SCAN_START_TIME, "无线接通率");
}
if (!string.IsNullOrEmpty(ERAB_HOFAIL) && !string.IsNullOrEmpty(ERAB_NBRREQRELENB) && !string.IsNullOrEmpty(NbrReqRelEnb_Normal) && !string.IsNullOrEmpty(ERAB_NBRLEFT)
&& !string.IsNullOrEmpty(ERAB_NBRSUCCESTAB) && !string.IsNullOrEmpty(ERAB_NBRHOINC))
{
string formula = "IF((S" + (iRow + i + 1) + "+L" + (iRow + i + 1) + "+T" + (iRow + i + 1) + ")=0,1,(Q" + (iRow + i + 1) + "+R" + (iRow + i + 1) + "-AA" + (iRow + i + 1) + ")/(S" + (iRow + i + 1) + "+L" + (iRow + i + 1) + "+T" + (iRow + i + 1) + "))";
row.CreateCell(47).CellFormula = formula; //无线掉线率(小区级)
row.GetCell(47).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(47), dt_rate, SCAN_START_TIME, "无线掉线率(小区级)");
}
if (!string.IsNullOrEmpty(ERAB_NBRSUCCESTAB_QC1) && !string.IsNullOrEmpty(ERAB_NBRATTESTAB_QC1) && !string.IsNullOrEmpty(RRC_SUCCCONNESTAB) && !string.IsNullOrEmpty(RRC_ATTCONNESTAB))
{
string formula = "IF(AND(V" + (iRow + i + 1) + "=0,I" + (iRow + i + 1) + "=0),1,U" + (iRow + i + 1) + "/V" + (iRow + i + 1) + "*J" + (iRow + i + 1) + "/I" + (iRow + i + 1) + ")";
row.CreateCell(48).CellFormula = formula; //无线接通率(QCI=1)
row.GetCell(48).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(48), dt_rate, SCAN_START_TIME, "无线接通率(QCI=1)");
}
if (!string.IsNullOrEmpty(ERAB_NBRREQRELENB_QC1) && !string.IsNullOrEmpty(ERAB_NRRELE_NORMAL_QC1) && !string.IsNullOrEmpty(ERAB_HOFAIL_QC1) && !string.IsNullOrEmpty(ERAB_NBRLEFT_QC1)
&& !string.IsNullOrEmpty(ERAB_NBRSUCCESTAB_QC1) && !string.IsNullOrEmpty(ERAB_NBRHOINC_QC1))
{
string formula = "IF(AD" + (iRow + i + 1) + "+U" + (iRow + i + 1) + "+AE" + (iRow + i + 1) + "=0,1,(AB" + (iRow + i + 1) + "-AF" + (iRow + i + 1) + "+AC" + (iRow + i + 1) + ")/(AD" + (iRow + i + 1) + "+U" + (iRow + i + 1) + "+AE" + (iRow + i + 1) + "))";
row.CreateCell(49).CellFormula = formula; //E-RAB掉线率(QCI=1)
row.GetCell(49).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(49), dt_rate, SCAN_START_TIME, "E-RAB掉线率(QCI=1)");
}
if (!string.IsNullOrEmpty(HO_SUCCOUTINTERENBS1) && !string.IsNullOrEmpty(HO_SUCCOUTINTERENBX2) && !string.IsNullOrEmpty(HO_ATTOUTINTERENBS1) && !string.IsNullOrEmpty(HO_ATTOUTINTERENBX2))
{
string formula = "IF(Y" + (iRow + i + 1) + "+Z" + (iRow + i + 1) + "=0,1,(W" + (iRow + i + 1) + "+X" + (iRow + i + 1) + ")/(Y" + (iRow + i + 1) + "+Z" + (iRow + i + 1) + "))";
row.CreateCell(50).CellFormula = formula;//eNB间切换成功率
row.GetCell(50).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(50), dt_rate, SCAN_START_TIME, "eNB间切换成功率");
}
if (!string.IsNullOrEmpty(HO_SUCCOUTINTRAENB) && !string.IsNullOrEmpty(HO_ATTOUTINTRAENB))
{
string formula = "IF(AH" + (iRow + i + 1) + "=0,1,AG" + (iRow + i + 1) + "/AH" + (iRow + i + 1) + ")";
row.CreateCell(51).CellFormula = formula;//eNB内切换成功率
row.GetCell(51).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(51), dt_rate, SCAN_START_TIME, "eNB内切换成功率");
}
if (!string.IsNullOrEmpty(HO_SUCCOUTINTERENBS1) && !string.IsNullOrEmpty(HO_SUCCOUTINTERENBX2) && !string.IsNullOrEmpty(HO_SUCCOUTINTRAENB) && !string.IsNullOrEmpty(HO_ATTOUTINTERENBS1)
&& !string.IsNullOrEmpty(HO_ATTOUTINTERENBX2) && !string.IsNullOrEmpty(HO_ATTOUTINTRAENB))
{
string formula = "IF(Y" + (iRow + i + 1) + "+Z" + (iRow + i + 1) + "+AH" + (iRow + i + 1) + "=0,1,(W" + (iRow + i + 1) + "+X" + (iRow + i + 1) + "+AG" + (iRow + i + 1) + ")/(Y" + (iRow + i + 1) + "+Z" + (iRow + i + 1) + "+AH" + (iRow + i + 1) + "))";
row.CreateCell(52).CellFormula = formula;//切换成功率
row.GetCell(52).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(52), dt_rate, SCAN_START_TIME, "切换成功率");
}
if (!string.IsNullOrEmpty(IRATHO_SUCCOUTGERAN) && !string.IsNullOrEmpty(IRATHO_ATTOUTGERAN))
{
//=IF(AND(AD8<>"",U8<>"", AE8<>"", AB8<>"", AF8<>"", AC8<>""),(AB9-AF9+AC9)/(AD9+U9+AE9),"") 指定的单元格都不为空,才执行计算,否则为空
if (IRATHO_SUCCOUTGERAN == "0" && IRATHO_ATTOUTGERAN == "0")
{
row.CreateCell(53).SetCellValue(1);
row.GetCell(53).CellStyle = cellStyle_per; //百分比
}
else
{
string formula = "IF(AJ" + (iRow + i + 1) + "=0,1,AI" + (iRow + i + 1) + "/AJ" + (iRow + i + 1) + ")";
row.CreateCell(53).CellFormula = formula;//eSRVCC切换成功率
row.GetCell(53).CellStyle = cellStyle_per; //百分比
}
GetCellValue(row.GetCell(53), dt_rate, SCAN_START_TIME, "eSRVCC切换成功率");
}
if (!string.IsNullOrEmpty(HO_SUCCOUTINTERENBS1_1) && !string.IsNullOrEmpty(HO_SUCCOUTINTERENBX2_1) && !string.IsNullOrEmpty(HO_SUCCOUTINTRAENB_1)
&& !string.IsNullOrEmpty(HO_ATTOUTINTERENBS1_1) && !string.IsNullOrEmpty(HO_ATTOUTINTERENBX2_1) && !string.IsNullOrEmpty(HO_ATTOUTINTRAENB_1))
{
string formula = "(AK" + (iRow + i + 1) + "+AL" + (iRow + i + 1) + "+AM" + (iRow + i + 1) + ")/(AN" + (iRow + i + 1) + "+AO" + (iRow + i + 1) + "+AP" + (iRow + i + 1) + ")";
row.CreateCell(54).CellFormula = formula;//VoLTE用户切换成功率(QCI=1)
row.GetCell(54).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(54), dt_rate, SCAN_START_TIME, "VoLTE用户切换成功率(QCI=1)");
}
if (!string.IsNullOrEmpty(RSRP_COUNT) && !string.IsNullOrEmpty(RSRP_00_06))
{
string formula = "IF(AQ" + (iRow + i + 1) + "=0,\"\",AR" + (iRow + i + 1) + "/AQ" + (iRow + i + 1) + ")";
row.CreateCell(55).CellFormula = formula; //MR(小于-110dbm采样点占比)
row.GetCell(55).CellStyle = cellStyle_per; //百分比
GetCellValue(row.GetCell(55), dt_rate, SCAN_START_TIME, "MR(小于-110dbm采样点占比)");
}
//MR(小于-110dbm采样点占比)异常
row.CreateCell(56).CellFormula = "AND(BD" + (iRow + i + 1) + ">20%,BD" + (iRow + i + 2) + ">20%,BD" + (iRow + i + 1) + "<>\"\",BD" + (iRow + i + 2) + "<>\"\",IF(ISERROR(FIND(\"W-\",C" + (iRow + i + 1) + ",1)),0,1))";
if (i == dt.Rows.Count - 1)
{ //最后一行,计算均值
//=IF(AND(AD8<>"",U8<>"", AE8<>"", AB8<>"", AF8<>"", AC8<>""),(AB9-AF9+AC9)/(AD9+U9+AE9),"") 指定的单元格都不为空,才执行计算,否则为空
//=IF(COUNTBLANK(AJ2:AJ8)>0,"",AVERAGE(AJ2:AJ8)) 指定区域的单元格都不为空,才执行计算,否则为空
//末尾行
IRow rowend = sheet.CreateRow(iRow + dt.Rows.Count);
rowend.CreateCell(0).SetCellValue("均值");
//rowend.CreateCell(4).CellFormula = "AVERAGE(E" + (iRow+1) + ":E" + (dt.Rows.Count + 1) + ")";
//rowend.CreateCell(4).SetCellValue(Avg(4, dt));
rowend.CreateCell(4).SetCellValue(Avg(4, dt));
rowend.GetCell(4).CellStyle = leftStyle;
rowend.CreateCell(5).SetCellValue(Avg(5, dt));
rowend.GetCell(5).CellStyle = leftStyle;
rowend.CreateCell(6).SetCellValue(Avg(6, dt)); //自_PDCP层上行流量_Eutrancell
rowend.GetCell(6).CellStyle = leftStyle;
rowend.CreateCell(7).SetCellValue(Avg(7, dt)); //自_PDCP层下行流量_Eutrancell
rowend.GetCell(7).CellStyle = leftStyle;
rowend.CreateCell(8).SetCellValue(Avg(8, dt));
rowend.GetCell(8).CellStyle = leftStyle;
rowend.CreateCell(9).SetCellValue(Avg(9, dt));
rowend.GetCell(9).CellStyle = leftStyle;
rowend.CreateCell(10).SetCellValue(Avg(10, dt));
rowend.GetCell(10).CellStyle = leftStyle;
rowend.CreateCell(11).SetCellValue(Avg(11, dt));
rowend.GetCell(11).CellStyle = leftStyle;
rowend.CreateCell(12).SetCellValue(Avg(12, dt));
rowend.GetCell(12).CellStyle = leftStyle;
rowend.CreateCell(13).SetCellValue(Avg(13, dt));
rowend.GetCell(13).CellStyle = leftStyle;
rowend.CreateCell(14).SetCellValue(Avg(14, dt));
rowend.GetCell(14).CellStyle = leftStyle;
rowend.CreateCell(15).SetCellValue(Avg(15, dt));
rowend.GetCell(15).CellStyle = leftStyle;
rowend.CreateCell(16).SetCellValue(Avg(16, dt));
rowend.GetCell(16).CellStyle = leftStyle;
rowend.CreateCell(17).SetCellValue(Avg(17, dt));
rowend.GetCell(17).CellStyle = leftStyle;
rowend.CreateCell(18).SetCellValue(Avg(18, dt));
rowend.GetCell(18).CellStyle = leftStyle;
rowend.CreateCell(19).SetCellValue(Avg(19, dt));
rowend.GetCell(19).CellStyle = leftStyle;
rowend.CreateCell(20).SetCellValue(Avg(20, dt));
rowend.GetCell(20).CellStyle = leftStyle;
rowend.CreateCell(21).SetCellValue(Avg(21, dt));
rowend.GetCell(21).CellStyle = leftStyle;
rowend.CreateCell(22).SetCellValue(Avg(22, dt));
rowend.GetCell(22).CellStyle = leftStyle;
rowend.CreateCell(23).SetCellValue(Avg(23, dt));
rowend.GetCell(23).CellStyle = leftStyle;
rowend.CreateCell(24).SetCellValue(Avg(24, dt));
rowend.GetCell(24).CellStyle = leftStyle;
rowend.CreateCell(25).SetCellValue(Avg(25, dt));
rowend.GetCell(25).CellStyle = leftStyle;
rowend.CreateCell(26).SetCellValue(Avg(26, dt));
rowend.GetCell(26).CellStyle = leftStyle;
rowend.CreateCell(27).SetCellValue(Avg(27, dt));
rowend.GetCell(27).CellStyle = leftStyle;
rowend.CreateCell(28).SetCellValue(Avg(28, dt));
rowend.GetCell(28).CellStyle = leftStyle;
rowend.CreateCell(29).SetCellValue(Avg(29, dt));
rowend.GetCell(29).CellStyle = leftStyle;
rowend.CreateCell(30).SetCellValue(Avg(30, dt));
rowend.GetCell(30).CellStyle = leftStyle;
rowend.CreateCell(31).SetCellValue(Avg(31, dt));
rowend.GetCell(31).CellStyle = leftStyle;
rowend.CreateCell(32).SetCellValue(Avg(32, dt));
rowend.GetCell(32).CellStyle = leftStyle;
rowend.CreateCell(33).SetCellValue(Avg(33, dt));
rowend.GetCell(33).CellStyle = leftStyle;
rowend.CreateCell(34).SetCellValue(Avg(34, dt));
rowend.GetCell(34).CellStyle = leftStyle;
rowend.CreateCell(35).SetCellValue(Avg(35, dt));
rowend.GetCell(35).CellStyle = leftStyle;
rowend.CreateCell(36).SetCellValue(Avg(36, dt));
rowend.GetCell(36).CellStyle = leftStyle;
rowend.CreateCell(37).SetCellValue(Avg(37, dt));
rowend.GetCell(37).CellStyle = leftStyle;
rowend.CreateCell(38).SetCellValue(Avg(38, dt));
rowend.GetCell(38).CellStyle = leftStyle;
rowend.CreateCell(39).SetCellValue(Avg(39, dt));
rowend.GetCell(39).CellStyle = leftStyle;
rowend.CreateCell(40).SetCellValue(Avg(40, dt));
rowend.GetCell(40).CellStyle = leftStyle;
rowend.CreateCell(41).SetCellValue(Avg(41, dt));
rowend.GetCell(41).CellStyle = leftStyle;
rowend.CreateCell(42).SetCellValue(Avg(42, dt));
rowend.GetCell(42).CellStyle = leftStyle;
rowend.CreateCell(43).SetCellValue(Avg(43, dt));
rowend.GetCell(43).CellStyle = leftStyle;
rowend.CreateCell(44).CellFormula = "IF(I" + (iRow + dt.Rows.Count + 1) + "=0,1,J" + (iRow + dt.Rows.Count + 1) + "/I" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(44).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(45).CellFormula = "IF(K" + (iRow + dt.Rows.Count + 1) + "=0,1,L" + (iRow + dt.Rows.Count + 1) + "/K" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(45).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(46).CellFormula = "IF(AND(K" + (iRow + dt.Rows.Count + 1) + "=0,I" + (iRow + dt.Rows.Count + 1) + "=0),1,L" + (iRow + dt.Rows.Count + 1) + "/K" + (iRow + dt.Rows.Count + 1) + "*J" + (iRow + dt.Rows.Count + 1) + "/I" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(46).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(47).CellFormula = "IF((S" + (iRow + dt.Rows.Count + 1) + "+L" + (iRow + dt.Rows.Count + 1) + "+T" + (iRow + dt.Rows.Count + 1) + ")=0,1,(Q" + (iRow + dt.Rows.Count + 1) + "+R" + (iRow + dt.Rows.Count + 1) + "-AA" + (iRow + dt.Rows.Count + 1) + ")/(S" + (iRow + dt.Rows.Count + 1) + "+L" + (iRow + dt.Rows.Count + 1) + "+T" + (iRow + dt.Rows.Count + 1) + "))";
rowend.GetCell(47).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(48).CellFormula = "IF(AND(V" + (iRow + dt.Rows.Count + 1) + "=0,I" + (iRow + dt.Rows.Count + 1) + "=0),1,U" + (iRow + dt.Rows.Count + 1) + "/V" + (iRow + dt.Rows.Count + 1) + "*J" + (iRow + dt.Rows.Count + 1) + "/I" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(48).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(49).CellFormula = "IF(AD" + (iRow + dt.Rows.Count + 1) + "+U" + (iRow + dt.Rows.Count + 1) + "+AE" + (iRow + dt.Rows.Count + 1) + "=0,1,(AB" + (iRow + dt.Rows.Count + 1) + "-AF" + (iRow + dt.Rows.Count + 1) + "+AC" + (iRow + dt.Rows.Count + 1) + ")/(AD" + (iRow + dt.Rows.Count + 1) + "+U" + (iRow + dt.Rows.Count + 1) + "+AE" + (iRow + dt.Rows.Count + 1) + "))";
rowend.GetCell(49).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(50).CellFormula = "IF(Y" + (iRow + dt.Rows.Count + 1) + "+Z" + (iRow + dt.Rows.Count + 1) + "=0,1,(W" + (iRow + dt.Rows.Count + 1) + "+X" + (iRow + dt.Rows.Count + 1) + ")/(Y" + (iRow + dt.Rows.Count + 1) + "+Z" + (iRow + dt.Rows.Count + 1) + "))";
rowend.GetCell(50).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(51).CellFormula = "IF(AH" + (iRow + dt.Rows.Count + 1) + "=0,1,AG" + (iRow + dt.Rows.Count + 1) + "/AH" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(51).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(52).CellFormula = "IF(Y" + (iRow + dt.Rows.Count + 1) + "+Z" + (iRow + dt.Rows.Count + 1) + "+AH" + (iRow + dt.Rows.Count + 1) + "=0,1,(W" + (iRow + dt.Rows.Count + 1) + "+X" + (iRow + dt.Rows.Count + 1) + "+AG" + (iRow + dt.Rows.Count + 1) + ")/(Y" + (iRow + dt.Rows.Count + 1) + "+Z" + (iRow + dt.Rows.Count + 1) + "+AH" + (iRow + dt.Rows.Count + 1) + "))";
rowend.GetCell(52).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(53).CellFormula = "IF(AJ" + (iRow + dt.Rows.Count + 1) + "=0,1,AI" + (iRow + dt.Rows.Count + 1) + "/AJ" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(53).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(54).CellFormula = "(AK" + (iRow + dt.Rows.Count + 1) + "+AL" + (iRow + dt.Rows.Count + 1) + "+AM" + (iRow + dt.Rows.Count + 1) + ")/(AN" + (iRow + dt.Rows.Count + 1) + "+AO" + (iRow + dt.Rows.Count + 1) + "+AP" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(54).CellStyle = cellStyle_per; //百分比
rowend.CreateCell(55).CellFormula = "IF(AQ" + (iRow + dt.Rows.Count + 1) + "=0,\"\",AR" + (iRow + dt.Rows.Count + 1) + "/AQ" + (iRow + dt.Rows.Count + 1) + ")";
rowend.GetCell(55).CellStyle = cellStyle_per; //百分比
//MR(小于-110dbm采样点占比)异常
rowend.CreateCell(56).CellFormula = "AND(BD" + (iRow + dt.Rows.Count + 1) + ">20%,BD" + (iRow + dt.Rows.Count + 2) + ">20%,BD" + (iRow + dt.Rows.Count + 1) + "<>\"\",BD" + (iRow + dt.Rows.Count + 2) + "<>\"\",IF(ISERROR(FIND(\"W-\",C" + (iRow + dt.Rows.Count + 1) + ",1)),0,1))";
}
#endregion
}
//上面写完行数据,计算完列宽后再写列名
//设置 站点后台指标监控 列名及列宽
setColumnWidth(sheet, dt_siteMonitor, headStyle, arrColWidth_siteMonitor);
//IRow headerRow_siteMonitor = sheet.CreateRow(0); //上面写完行数据,计算完列宽后再写列名
//foreach (DataColumn column in dt_siteMonitor.Columns)
//{
// headerRow_siteMonitor.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
// headerRow_siteMonitor.GetCell(column.Ordinal).CellStyle = headStyle;
// if (arrColWidth_siteMonitor[column.Ordinal] >= 255)
// {
// sheet.SetColumnWidth(column.Ordinal, 254 * 256);
// }
// else
// {
// sheet.SetColumnWidth(column.Ordinal, (arrColWidth_siteMonitor[column.Ordinal] + 1) * 256);
// }
// //设置列宽
//}
Dictionary
DateTime start_dt2;
DateTime end_dt2;
//起始日期
start_dt2 = DateTime.ParseExact(start_time, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
//结束日期
end_dt2 = DateTime.ParseExact(end_time, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
//int start = 0;
while (DateTime.Compare(start_dt2, end_dt2) <= 0) //比较结果精确到毫秒。
{ //如果结果大于0,则表示 t1晚于t2;如果结果等于0,则表示 t1等于t2;如果结果小0,则表示 t1早于t2。
DataRow[] dr_mr_rate = dt_rate.Select("SCAN_START_TIME ='" + start_dt2 + "'");
double value = 0;
int count = 0;
for (int j = 0; j < dr_mr_rate.Length; j++)
{
string db = dr_mr_rate[j]["MR(小于-110dbm采样点占比)"].ToString().Trim();
if (!string.IsNullOrEmpty(db))
{
count++;
value += Convert.ToDouble(db);
}
}
if (dr_mr_rate.Length > 0)
{ //这一天有记录,才计算这一天的均值
double avg = value != 0 && count != 0 ? value / count : 0;
mr_per_day_avg.Add(start_dt2.ToString("yyyy-MM-dd"), avg);
}
start_dt2 = start_dt2.AddDays(1);
};
/****************************************告警*******************************************/
DataTable dt_alarmList = ds.Tables[1];
//取得 重要告警列表 列的数量
int[] arrColWidth_alarmList = new int[dt_alarmList.Columns.Count]; //模板中获取 重要告警列表 列的数量
foreach (DataColumn item in dt_alarmList.Columns)
{
arrColWidth_alarmList[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length; //计算列宽的长度
}
List
for (int i = 0; i < dt_alarmList.Rows.Count; i++)
{
for (int j = 0; j < dt_alarmList.Columns.Count; j++)
{
int intTemp = Encoding.GetEncoding(936).GetBytes(dt_alarmList.Rows[i][j].ToString()).Length; //计算单元格的长度
if (intTemp > arrColWidth_alarmList[j]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmList[j] = intTemp;
}
}
#region 写单元格 写入重要告警列表sheet数据
IRow row = sheet_alarmList.CreateRow(iRow + i);
string mapNum = dt_alarmList.Rows[i]["映射规则序号"].ToString().Trim();
row.CreateCell(0).SetCellValue(mapNum);
string mapMethod = dt_alarmList.Rows[i]["映射方式"].ToString().Trim();
row.CreateCell(1).SetCellValue(mapMethod);
string profession = dt_alarmList.Rows[i]["专业"].ToString().Trim();
row.CreateCell(2).SetCellValue(profession);
string venderKey = dt_alarmList.Rows[i]["厂家(key)"].ToString().Trim();
row.CreateCell(3).SetCellValue(venderKey);
string deviceTypeKey = dt_alarmList.Rows[i]["设备类型(key)"].ToString().Trim();
row.CreateCell(4).SetCellValue(deviceTypeKey);
string alarmObjectType = dt_alarmList.Rows[i]["告警对象类型"].ToString().Trim();
row.CreateCell(5).SetCellValue(alarmObjectType);
string alarmTitleKey = dt_alarmList.Rows[i]["告警标题(key)"].ToString().Trim();
row.CreateCell(6).SetCellValue(alarmTitleKey);
string venderAlarmKey = dt_alarmList.Rows[i]["厂家告警ID(key)"].ToString().Trim();
row.CreateCell(7).SetCellValue(venderAlarmKey);
string alarmAuxiliaryField = dt_alarmList.Rows[i]["告警解释辅助字段"].ToString().Trim();
row.CreateCell(8).SetCellValue(alarmAuxiliaryField);
string venderAlarm_level = dt_alarmList.Rows[i]["厂家告警级别"].ToString().Trim();
row.CreateCell(9).SetCellValue(venderAlarm_level);
string alarmInterpretation = dt_alarmList.Rows[i]["告警解释"].ToString().Trim();
row.CreateCell(10).SetCellValue(alarmInterpretation);
string impactEventDevice = dt_alarmList.Rows[i]["该事件对设备的影响"].ToString().Trim();
row.CreateCell(11).SetCellValue(impactEventDevice);
string impactEventBusiness = dt_alarmList.Rows[i]["该事件对业务的影响"].ToString().Trim();
row.CreateCell(12).SetCellValue(impactEventBusiness);
string alarmStandardName = dt_alarmList.Rows[i]["告警标准名(必选)"].ToString().Trim();
row.CreateCell(13).SetCellValue(alarmStandardName);
if (!string.IsNullOrEmpty(venderAlarmKey))
{
alarmID_list.Add(venderAlarmKey);
}
#endregion
}
//上面写完行数据,计算完列宽后再写列名
//设置 重要告警列表 列名及列宽
setColumnWidth(sheet_alarmList, dt_alarmList, headStyle, arrColWidth_alarmList);
DataTable dt_alarmMonitor = ds.Tables[2];
//取得 站点重要告警监控 列的数量
int[] arrColWidth_alarmMonitor = new int[dt_alarmMonitor.Columns.Count]; //模板中获取 站点重要告警监控 列的数量及列名
foreach (DataColumn item in dt_alarmMonitor.Columns)
{
arrColWidth_alarmMonitor[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length; //计算列宽的长度
}
//数据库查询 重要告警列表 中的告警
string sql_alarm = "select * from NOP_ALARM_ACTIVE_ALARMLIST where STANDARD_ALARM_ID in (" + string.Join(",", alarmID_list) + ")";
DataTable dt_alarm = new DataTable();
dt_alarm = dw.GetTableBySqlString(sql_alarm).Tables[0];
List
for (int i = 0; i < dt_alarm.Rows.Count; i++)
{
//for (int j = 0; j < alarmMonitor_ColName_arr.Length; j++)
//{
// //计算 指定列名 对应 单元格的长度
// int intTemp = Encoding.GetEncoding(936).GetBytes(dt_alarm.Rows[i][alarmMonitor_ColName_arr[j]].ToString()).Length;
// if (intTemp > arrColWidth_alarmMonitor[j]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
// {
// arrColWidth_alarmMonitor[j] = intTemp;
// }
//}
#region 写单元格 写入站点重要告警监控sheet数据
IRow row = sheet_alarmMonitor.CreateRow(iRow + i);
row.CreateCell(0).SetCellValue(enodebid);
//计算指定列下单元格的长度
int intTemp = Encoding.GetEncoding(936).GetBytes(enodebid).Length;
if (intTemp > arrColWidth_alarmMonitor[0]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[0] = intTemp;
}
row.CreateCell(1).SetCellValue(enodeb_name);
int intTemp1 = Encoding.GetEncoding(936).GetBytes(enodeb_name).Length;
if (intTemp1 > arrColWidth_alarmMonitor[1]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[1] = intTemp1;
}
string CELL_ID = dt_alarm.Rows[i]["CELL_ID"].ToString().Trim();
row.CreateCell(2).SetCellValue(CELL_ID);
int intTemp2 = Encoding.GetEncoding(936).GetBytes(CELL_ID).Length;
if (intTemp2 > arrColWidth_alarmMonitor[2]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[2] = intTemp2;
}
string CELL_NAME = dt_alarm.Rows[i]["CELL_NAME"].ToString().Trim();
row.CreateCell(3).SetCellValue(CELL_NAME);
int intTemp3 = Encoding.GetEncoding(936).GetBytes(CELL_NAME).Length;
if (intTemp3 > arrColWidth_alarmMonitor[3]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[3] = intTemp3;
}
string VENDOR_NAME = dt_alarm.Rows[i]["VENDOR_NAME"].ToString().Trim();
row.CreateCell(4).SetCellValue(VENDOR_NAME);
int intTemp4 = Encoding.GetEncoding(936).GetBytes(VENDOR_NAME).Length;
if (intTemp4 > arrColWidth_alarmMonitor[4]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[4] = intTemp4;
}
string ALARM_BOARD = dt_alarm.Rows[i]["ALARM_BOARD"].ToString().Trim();
row.CreateCell(5).SetCellValue(ALARM_BOARD);
int intTemp5 = Encoding.GetEncoding(936).GetBytes(ALARM_BOARD).Length;
if (intTemp5 > arrColWidth_alarmMonitor[5]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[5] = intTemp5;
}
//告警对象类型
row.CreateCell(6).SetCellValue("");
string ORG_SEVERITY = dt_alarm.Rows[i]["ORG_SEVERITY"].ToString().Trim();
row.CreateCell(7).SetCellValue(ORG_SEVERITY);
int intTemp7 = Encoding.GetEncoding(936).GetBytes(ORG_SEVERITY).Length;
if (intTemp7 > arrColWidth_alarmMonitor[7]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[7] = intTemp7;
}
string ALARM_TITLE_TEXT = dt_alarm.Rows[i]["ALARM_TITLE_TEXT"].ToString().Trim(); //告警标题(key)
row.CreateCell(8).SetCellValue(ALARM_TITLE_TEXT);
int intTemp8 = Encoding.GetEncoding(936).GetBytes(ALARM_TITLE_TEXT).Length;
if (intTemp8 > arrColWidth_alarmMonitor[8]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[8] = intTemp8;
}
string STANDARD_ALARM_ID = dt_alarm.Rows[i]["STANDARD_ALARM_ID"].ToString().Trim();
row.CreateCell(9).SetCellValue(STANDARD_ALARM_ID);
int intTemp9 = Encoding.GetEncoding(936).GetBytes(STANDARD_ALARM_ID).Length;
if (intTemp9 > arrColWidth_alarmMonitor[9]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[9] = intTemp9;
}
string EVENT_TIME = dt_alarm.Rows[i]["EVENT_TIME"].ToString().Trim();
row.CreateCell(10).SetCellValue(EVENT_TIME);
int intTemp10 = Encoding.GetEncoding(936).GetBytes(EVENT_TIME).Length;
if (intTemp10 > arrColWidth_alarmMonitor[10]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[10] = intTemp10;
}
string CANCEL_TIME = dt_alarm.Rows[i]["CANCEL_TIME"].ToString().Trim();
row.CreateCell(11).SetCellValue(CANCEL_TIME);
int intTemp11 = Encoding.GetEncoding(936).GetBytes(CANCEL_TIME).Length;
if (intTemp11 > arrColWidth_alarmMonitor[11]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_alarmMonitor[11] = intTemp11;
}
if (!alarmTitle_list.Contains(ALARM_TITLE_TEXT))
{
alarmTitle_list.Add(ALARM_TITLE_TEXT);
}
#endregion
}
//上面写完行数据,计算完列宽后再写列名
//设置 站点重要告警监控 列名及列宽
setColumnWidth(sheet_alarmMonitor, dt_alarmMonitor, headStyle, arrColWidth_alarmMonitor);
//从模板ds中 获取 问题汇总 表
DataTable dt_problemsSum = ds.Tables[4];
//取得 问题汇总 列的数量
int[] arrColWidth_problemsSum = new int[dt_problemsSum.Columns.Count]; //模板中获取 问题汇总 列的数量
foreach (DataColumn item in dt_problemsSum.Columns)
{
arrColWidth_problemsSum[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length; //计算列宽的长度
}
for (int i = 0; i < dt_problemsSum.Rows.Count; i++)
{
for (int j = 0; j < dt_problemsSum.Columns.Count; j++)
{
//计算 指定列 对应 单元格的长度 列的顺序需要一一对应
int intTemp = Encoding.GetEncoding(936).GetBytes(dt_problemsSum.Rows[i][j].ToString()).Length;
if (intTemp > arrColWidth_problemsSum[j]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_problemsSum[j] = intTemp;
}
}
#region 写单元格 写入问题汇总sheet数据
//IRow row = sheet_problemsSum.CreateRow(iRow + i); //无数据
#endregion
}
//上面写完行数据,计算完列宽后再写列名
//设置 问题汇总 列名及列宽
setColumnWidth(sheet_problemsSum, dt_problemsSum, headStyle, arrColWidth_problemsSum);
//从模板ds中 获取 指标定义 表
DataTable dt_zhibiaoDefinition = ds.Tables[5];
//取得 指标定义 列的数量
int[] arrColWidth_zhibiaoDefinition = new int[dt_zhibiaoDefinition.Columns.Count]; //模板中获取 指标定义 列的数量
foreach (DataColumn item in dt_zhibiaoDefinition.Columns)
{
arrColWidth_zhibiaoDefinition[item.Ordinal] = Encoding.GetEncoding(936).GetBytes(item.ColumnName.ToString()).Length; //计算列宽的长度
}
for (int i = 0; i < dt_zhibiaoDefinition.Rows.Count; i++)
{
for (int j = 0; j < dt_zhibiaoDefinition.Columns.Count; j++)
{
//计算 指定列 对应 单元格的长度 列的顺序需要一一对应
int intTemp = Encoding.GetEncoding(936).GetBytes(dt_zhibiaoDefinition.Rows[i][j].ToString()).Length;
if (intTemp > arrColWidth_zhibiaoDefinition[j]) //如果单元格的长度大于列宽的长度就设置列宽为单元格的长度
{
arrColWidth_zhibiaoDefinition[j] = intTemp;
}
}
#region 写单元格 写入 指标定义 sheet数据
IRow row = sheet_zhibiaoDefinition.CreateRow(iRow + i); //无数据
string serialNumber = dt_zhibiaoDefinition.Rows[i]["序号"].ToString().Trim();
row.CreateCell(0).SetCellValue(serialNumber);
string zhibiaoName = dt_zhibiaoDefinition.Rows[i]["指标名称"].ToString().Trim();
row.CreateCell(1).SetCellValue(zhibiaoName);
string calculationFormula = dt_zhibiaoDefinition.Rows[i]["计算公式(来源:网优平台2.0)"].ToString().Trim();
row.CreateCell(2).SetCellValue(calculationFormula);
string remark_ = dt_zhibiaoDefinition.Rows[i]["备注"].ToString().Trim();
row.CreateCell(3).SetCellValue(remark_);
#endregion
}
//上面写完行数据,计算完列宽后再写列名
//设置 指标定义 列名及列宽
setColumnWidth(sheet_zhibiaoDefinition, dt_zhibiaoDefinition, headStyle, arrColWidth_zhibiaoDefinition);
/******************************************报告******************************************/
/********************************画报表************************************/
ICellStyle title_style = workbook.CreateCellStyle();
//设置单元格的样式:水平对齐居中
title_style.Alignment = HorizontalAlignment.Center;
title_style.VerticalAlignment = VerticalAlignment.Center;//垂直居中
//新建一个字体样式对象
XSSFFont title_font = workbook.CreateFont() as XSSFFont;
title_font.FontName = "黑体";//字体
title_font.FontHeightInPoints = 18; //字号
title_font.Boldweight = 900; //设置字体加粗样式
//使用SetFont方法将字体样式添加到单元格样式中
title_style.SetFont(title_font);
title_style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
title_style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
title_style.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
title_style.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle nomar_style = workbook.CreateCellStyle();
nomar_style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
nomar_style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
nomar_style.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
nomar_style.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle border_Medium = workbook.CreateCellStyle();
border_Medium.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
border_Medium.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
border_Medium.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
border_Medium.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle border_Dotted = workbook.CreateCellStyle();
border_Dotted.BorderBottom = NPOI.SS.UserModel.BorderStyle.Dotted;
border_Dotted.BorderLeft = NPOI.SS.UserModel.BorderStyle.Dotted;
border_Dotted.BorderRight = NPOI.SS.UserModel.BorderStyle.Dotted;
border_Dotted.BorderTop = NPOI.SS.UserModel.BorderStyle.Dotted;
ICellStyle Dotted_style = workbook.CreateCellStyle();
Dotted_style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Dotted;
Dotted_style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Dotted;
Dotted_style.BorderRight = NPOI.SS.UserModel.BorderStyle.Dotted;
Dotted_style.BorderTop = NPOI.SS.UserModel.BorderStyle.Dotted;
Dotted_style.VerticalAlignment = VerticalAlignment.Top;
Dotted_style.WrapText = true;
//新建一个字体样式对象
XSSFFont Dotted_font = workbook.CreateFont() as XSSFFont;
Dotted_font.FontName = "宋体";//字体
Dotted_font.FontHeightInPoints = 10; //字号
//使用SetFont方法将字体样式添加到单元格样式中
Dotted_style.SetFont(Dotted_font);
ICellStyle Dotted_TopBorder = workbook.CreateCellStyle();
Dotted_TopBorder.BorderTop = NPOI.SS.UserModel.BorderStyle.Dotted;
ICellStyle Top_Dotted_Left_Right_Medium_Border = workbook.CreateCellStyle();
Top_Dotted_Left_Right_Medium_Border.BorderTop = NPOI.SS.UserModel.BorderStyle.Dotted;
Top_Dotted_Left_Right_Medium_Border.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
Top_Dotted_Left_Right_Medium_Border.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
//ICellStyle Top_Dotted_Right_Medium_Border = workbook.CreateCellStyle();
//Top_Dotted_Right_Medium_Border.BorderTop = NPOI.SS.UserModel.BorderStyle.Dotted;
//Top_Dotted_Right_Medium_Border.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle Left_Bottom_Medium_Border = workbook.CreateCellStyle();
Left_Bottom_Medium_Border.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
Left_Bottom_Medium_Border.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle Right_Bottom_Medium_Border = workbook.CreateCellStyle();
Right_Bottom_Medium_Border.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
Right_Bottom_Medium_Border.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle remark_style = workbook.CreateCellStyle();
remark_style.VerticalAlignment = VerticalAlignment.Top;
remark_style.WrapText = true; //自动换行
remark_style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
remark_style.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle left_border_Medium = workbook.CreateCellStyle();
left_border_Medium.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle right_border_Medium = workbook.CreateCellStyle();
right_border_Medium.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle top_border_Medium = workbook.CreateCellStyle();
top_border_Medium.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium;
ICellStyle bottom_border_Medium = workbook.CreateCellStyle();
bottom_border_Medium.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium;
for (int column = 3; column < 36; column++)
{
sheet_report.SetColumnWidth(column, 2 * 256); //设置列宽
}
//画大边框
for (int i = 2; i < 47; i++)
{
IRow row = sheet_report.GetRow(i);
if (row == null)
{
row = sheet_report.CreateRow(i);
}
ICell cell = row.GetCell(3);
if (cell == null)
{
row.CreateCell(3);
}
row.GetCell(3).CellStyle = left_border_Medium; //画左边框
ICell cell39 = row.GetCell(39);
if (cell39 == null)
{
row.CreateCell(39);
}
row.GetCell(39).CellStyle = right_border_Medium; //画右边框
if (i == 46)
{
for (int j = 3; j < 40; j++)
{
if (j == 3)
{
row.CreateCell(j).CellStyle = Left_Bottom_Medium_Border; //最后一行第一个单元格底部边框
}
else if (j == 39)
{
row.CreateCell(j).CellStyle = Right_Bottom_Medium_Border;
}
else
{
row.CreateCell(j).CellStyle = bottom_border_Medium; //最后一行最后一个单元格底部边框
}
}
}
}
//设置一个合并单元格区域,使用上下左右定义CellRangeAddress区域
//CellRangeAddress四个参数为:起始行,结束行,起始列,结束列
CellRangeAddress region_title = new CellRangeAddress(2, 4, 3, 39);
sheet_report.AddMergedRegion(region_title);
setRegionStyle(border_Medium, region_title, sheet_report); //合并单元格后设置边框,会创建所有行和列(单元格)
IRow title_row = sheet_report.GetRow(2); //这里只要获取行和列就行了
ICell titel_cell = title_row.GetCell(3);
titel_cell.SetCellValue("TD-LTE单站点后评估报告");
//设置单元格的高度
//title_row.Height = 30 * 20;
//将新的样式赋给单元格
titel_cell.CellStyle = title_style;
CellRangeAddress region_site_des = new CellRangeAddress(5, 5, 3, 39);
sheet_report.AddMergedRegion(region_site_des);
setRegionStyle(border_Medium, region_site_des, sheet_report);
IRow site_des_row = sheet_report.GetRow(5); //这里只要获取行和列就行了
ICell site_des_cell = site_des_row.GetCell(3);
site_des_cell.SetCellValue("基站描述");
site_des_cell.CellStyle = nomar_style;
sheet_report.GetRow(7).CreateCell(4).SetCellValue("站名:");
sheet_report.GetRow(7).CreateCell(25).SetCellValue("单验日期:");
sheet_report.GetRow(9).CreateCell(4).SetCellValue("站号:");
sheet_report.GetRow(9).CreateCell(27).SetCellValue("市县:");
sheet_report.GetRow(11).CreateCell(4).SetCellValue("配置:");
sheet_report.GetRow(11).CreateCell(27).SetCellValue("站型:");
sheet_report.GetRow(13).CreateCell(4).SetCellValue("地址:");
sheet_report.GetRow(13).CreateCell(24).SetCellValue("后评估日期:");
CellRangeAddress region_pinggu = new CellRangeAddress(17, 17, 3, 39);
sheet_report.AddMergedRegion(region_pinggu);
setRegionStyle(border_Medium, region_pinggu, sheet_report); //合并单元格后设置边框,会创建所有行和列(单元格)
sheet_report.GetRow(17).GetCell(3).SetCellValue("性能评估");
sheet_report.GetRow(17).GetCell(3).CellStyle = nomar_style;
sheet_report.GetRow(19).CreateCell(4).SetCellValue("业务量评估:");
sheet_report.GetRow(21).CreateCell(4).SetCellValue("接通率评估:");
sheet_report.GetRow(23).CreateCell(4).SetCellValue("掉线率评估:");
sheet_report.GetRow(25).CreateCell(4).SetCellValue("切换成功率评估:");
sheet_report.GetRow(27).CreateCell(4).SetCellValue("MR指标评估:");
CellRangeAddress region_zhibiaospec = new CellRangeAddress(19, 27, 18, 38);
sheet_report.AddMergedRegion(region_zhibiaospec);
setRegionStyle(border_Dotted, region_zhibiaospec, sheet_report); //合并单元格后设置边框,会创建所有行和列(单元格)
sheet_report.GetRow(19).GetCell(18).SetCellValue("指标说明:\n" +
"宏站:零流量小区、低业务量(日流量小于10M)、无线接通率大于98%、无线掉线率小于2%、切换成功率大于90%。无线接通率(QCI=1)>=98%, E-RAB掉线率(QCI=1)<=2%, VoLTE用户切换成功率(QCI=1)>=90%, eSRVCC切换成功率>=90%,非农村区域连续2天以上MR(小于-110dbm采样点占比小于20%)。\n" +
"室分:低业务量(日流量小于5M)、无线接通率大于98%、无线掉线率小于2%、切换成功率大于90%,无线接通率(QCI=1)>=98%, E-RAB掉线率(QCI=1)<=2%, VoLTE用户切换成功率(QCI=1)>=90%, eSRVCC切换成功率>=90%,连续2天以上MR(小于-110dbm采样点占比小于20%)。");
sheet_report.GetRow(19).GetCell(18).CellStyle = Dotted_style;
CellRangeAddress region_alarmpinggu = new CellRangeAddress(29, 29, 3, 39);
sheet_report.AddMergedRegion(region_alarmpinggu);
setRegionStyle(border_Medium, region_alarmpinggu, sheet_report); //合并单元格后设置边框,会创建所有行和列(单元格)
sheet_report.GetRow(29).GetCell(3).SetCellValue("告警评估");
sheet_report.GetRow(29).GetCell(3).CellStyle = nomar_style;
sheet_report.GetRow(31).CreateCell(4).SetCellValue("告警评估:");
CellRangeAddress region_pinggujielun = new CellRangeAddress(33, 33, 3, 39);
sheet_report.AddMergedRegion(region_pinggujielun);
setRegionStyle(border_Medium, region_pinggujielun, sheet_report); //合并单元格后设置边框,会创建所有行和列(单元格)
sheet_report.GetRow(33).GetCell(3).SetCellValue("评估结论");
sheet_report.GetRow(33).GetCell(3).CellStyle = nomar_style;
sheet_report.GetRow(35).CreateCell(4).SetCellValue("是否同意入网:");
sheet_report.GetRow(37).CreateCell(4).SetCellValue("备注:");
CellRangeAddress region_remark = new CellRangeAddress(38, 42, 3, 39);
sheet_report.AddMergedRegion(region_remark);
setRegionStyle(remark_style, region_remark, sheet_report);
//sheet_report.GetRow(38).GetCell(3).SetCellValue("该站已通过单站验证,通过指标评估存在下列指标不达标:切换成功率大于90%; 请优化人员关注");
CellRangeAddress region_43 = new CellRangeAddress(43, 43, 3, 39); //画一条虚线
sheet_report.AddMergedRegion(region_43);
setRegionStyle(Top_Dotted_Left_Right_Medium_Border, region_43, sheet_report);
sheet_report.GetRow(44).CreateCell(4).SetCellValue("验收人员");
sheet_report.GetRow(44).CreateCell(15).SetCellValue("姓名");
sheet_report.GetRow(44).CreateCell(20).SetCellValue("电话");
sheet_report.GetRow(44).CreateCell(25).SetCellValue("联系方式");
sheet_report.GetRow(45).CreateCell(4).SetCellValue("eNB后台工程师");
sheet_report.GetRow(45).CreateCell(15).SetCellValue("XXX");
/********************************画报表结束************************************/
/**********************************指标计算*********************************************/
sheet_report.GetRow(7).CreateCell(7).SetCellValue(enodeb_name);
sheet_report.GetRow(7).CreateCell(30).SetCellValue(date);
sheet_report.GetRow(9).CreateCell(7).SetCellValue(enodebid);
sheet_report.GetRow(9).CreateCell(30).SetCellValue(city);
sheet_report.GetRow(11).CreateCell(7).SetCellValue(config);
sheet_report.GetRow(11).CreateCell(30).SetCellValue(station_type);
sheet_report.GetRow(13).CreateCell(7).SetCellValue(address);
sheet_report.GetRow(13).CreateCell(30).SetCellValue(DateTime.Now.ToString("yyyy-MM-dd"));
string nopass_str = string.Empty; //保存未通过指标的字符串
if (dt.Rows.Count > 0)
{ //当表中有数据时才计算是否通过
//#define eps 1e-10 定义精度
//当单元格数据类型不是数字时会返回负数
double PDCP_UPOCTUL_TUNTU_AVE = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(6)); //自_PDCP层上行流量_Eutrancell
//当单元格数据类型不是数字时会返回负数
double PDCP_UPOCTDL_TUNTU_AVE = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(7)); //自_PDCP层下行流量_Eutrancell
double Zero_flow = PDCP_UPOCTUL_TUNTU_AVE + PDCP_UPOCTDL_TUNTU_AVE; //零流量小区
double Low_business = PDCP_UPOCTUL_TUNTU_AVE + PDCP_UPOCTDL_TUNTU_AVE; //低业务量
if (Zero_flow >= 0 && Low_business >= 0) //当单元格数据类型不是数字时会返回负数
{
if (station_type.Equals("宏站"))
{
if (Zero_flow == 0 || Low_business < 10)
{
sheet_report.GetRow(19).CreateCell(12).SetCellValue("未通过");
if (Zero_flow == 0)
{
nopass_str += "零流量小区;"; //拼接不达标的指标
}
if (Low_business < 10)
{
nopass_str += "低业务量(日流量小于10M);";
}
}
else
{
sheet_report.GetRow(19).CreateCell(12).SetCellValue("通过");
}
}
else if (station_type.Equals("窒分"))
{
if (Low_business < 5)
{
sheet_report.GetRow(19).CreateCell(12).SetCellValue("未通过");
if (Low_business < 5)
{
nopass_str += "低业务量(日流量小于5M);";//拼接不达标的指标
}
}
else
{
sheet_report.GetRow(19).CreateCell(12).SetCellValue("通过");
}
}
}
else
{ //任意一个为负数(没有均值)则不通过
//m_objRange = m_objSheet_report.get_Range("K22", m_objOpt);
//m_objRange.Value = "未通过";
}
//无线接通率
//当单元格数据类型不是数字时会返回负数
double Wireless_connection_rate = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(46));
//无线接通率(QCI=1)
//当单元格数据类型不是数字时会返回负数
double Wireless_connection_rate_QCI_1 = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(48));
//1、Math.Round(0.333333,2);//按照四舍五入的国际标准
//Wireless_connection_rate = Math.Round(Wireless_connection_rate, 4);
//Wireless_connection_rate_QCI_1 = Math.Round(Wireless_connection_rate_QCI_1, 4);
if (Wireless_connection_rate >= 0 && Wireless_connection_rate_QCI_1 >= 0) //当单元格数据类型不是数字时会返回负数
{
if (Wireless_connection_rate > 0.98 && Wireless_connection_rate_QCI_1 >= 0.98)
{
sheet_report.GetRow(21).CreateCell(12).SetCellValue("通过"); //接通率评估
}
else
{
sheet_report.GetRow(21).CreateCell(12).SetCellValue("未通过");
if (Wireless_connection_rate <= 0.98)
{
nopass_str += "无线接通率大于98%;";
}
if (Wireless_connection_rate_QCI_1 < 0.98)
{
nopass_str += "无线接通率(QCI=1)>=98%;";
}
}
}
else
{ //任意一个为负数(没有均值)则不通过 -2146826281.0
//m_objRange = m_objSheet_report.get_Range("K23", m_objOpt);
//m_objRange.Value = "未通过";
}
//无线掉线率(小区级)
//当单元格数据类型不是数字时会返回负数
double Wireless_drop_rate = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(47));
//E-RAB掉线率(QCI=1)
//当单元格数据类型不是数字时会返回负数
double E_RAB_drop_rate_QCI_1 = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(49));
if (Wireless_drop_rate >= 0 && E_RAB_drop_rate_QCI_1 >= 0)
{ //当没有均值时,为负数
if (Wireless_drop_rate < 0.02 && E_RAB_drop_rate_QCI_1 <= 0.02)
{
sheet_report.GetRow(23).CreateCell(12).SetCellValue("通过"); //掉线率评估
}
else
{
sheet_report.GetRow(23).CreateCell(12).SetCellValue("未通过");//掉线率评估
if (Wireless_drop_rate >= 0.02)
{
nopass_str += "无线掉线率小于2%;";
}
if (E_RAB_drop_rate_QCI_1 > 0.02)
{
nopass_str += "E-RAB掉线率(QCI=1)<=2%;";
}
}
}
else
{//任意一个为负数(没有均值)则不通过
//m_objRange = m_objSheet_report.get_Range("K24", m_objOpt); //掉线率评估
//m_objRange.Value = "未通过";
}
//切换成功率
//当单元格数据类型不是数字时会返回负数
double Switch_success_rate = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(52));
//VoLTE用户切换成功率(QCI=1)
//当单元格数据类型不是数字时会返回负数
double VoLTE_user_switching_success_rate = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(54));
//eSRVCC切换成功率
//当单元格数据类型不是数字时会返回负数
double ESRVCC_switching_success_rate = GetCellDoubleValue(sheet.GetRow(iRow + dt.Rows.Count).GetCell(53));
if (Switch_success_rate >= 0 && VoLTE_user_switching_success_rate >= 0 && ESRVCC_switching_success_rate >= 0) //当没有均值时,为负数
{
if (Switch_success_rate > 0.9 && VoLTE_user_switching_success_rate >= 0.9 && ESRVCC_switching_success_rate >= 0.9)
{
sheet_report.GetRow(25).CreateCell(12).SetCellValue("通过");//切换成功率评估
}
else
{
sheet_report.GetRow(25).CreateCell(12).SetCellValue("未通过");//切换成功率评估
if (Switch_success_rate <= 0.9)
{
nopass_str += "切换成功率大于90%;";
}
if (VoLTE_user_switching_success_rate < 0.9)
{
nopass_str += "VoLTE用户切换成功率(QCI=1)>=90%;";
}
if (ESRVCC_switching_success_rate < 0.9)
{
nopass_str += "eSRVCC切换成功率>=90%;";
}
}
}
else
{ //任意一个为负数(没有均值)则不通过
//m_objRange = m_objSheet_report.get_Range("K25", m_objOpt); //切换成功率评估
//m_objRange.Value = "未通过";
}
int mrcount = 0; //统计 连续2天以上MR(小于-110dbm采样点占比小于20%)的数量
//MR指标评估
foreach (var mr in mr_per_day_avg)
{
if (mr.Value < 0.2 && mr.Value >= 0) //如果小于20%就加1 当没有均值时,为负数(-2146826281.0)
{
mrcount++;
}
else
{
if (mrcount >= 2) //如果己经有 连续2天 小于20%就不将count清零了
{
}
else
{
mrcount = 0;
}
}
}
if (mrcount >= 2)
{
sheet_report.GetRow(27).CreateCell(12).SetCellValue("通过");//MR指标评估
}
else
{
sheet_report.GetRow(27).CreateCell(12).SetCellValue("未通过");//MR指标评估
nopass_str += "连续2天以上MR(小于-110dbm采样点占比小于20%);";
}
}
string remark = "该站已通过单站验证,"; //
if (!string.IsNullOrEmpty(nopass_str))
{
remark += "通过指标评估存在下列指标不达标:" + nopass_str;
}
if (alarmTitle_list.Count > 0)
{ //存在告警
remark += "存在下列告警:" + string.Join(";", alarmTitle_list);
sheet_report.GetRow(31).CreateCell(12).SetCellValue("未通过");
sheet_report.GetRow(31).CreateCell(20).SetCellValue("存在严重影响业务和性能重要告警");
}
else
{
sheet_report.GetRow(31).CreateCell(12).SetCellValue("通过");
sheet_report.GetRow(31).CreateCell(20).SetCellValue("无严重影响业务和性能重要告警");
}
if (!string.IsNullOrEmpty(nopass_str) || alarmTitle_list.Count > 0)
{
remark += " 请优化人员关注";
}
sheet_report.GetRow(38).GetCell(3).SetCellValue(remark);
if (r.result == "1")
{ //没有错误
sheet.ForceFormulaRecalculation = true; //模板自动公式需要激活
//将工作簿写入文件
using (FileStream fs_export = new FileStream(export_path, FileMode.Create))
{
workbook.Write(fs_export);
}
r.data = export_path + "-" + remark;
}
}
catch (Exception ex)
{
r.result = "-1";
r.data = ex.ToString();
}
return Newtonsoft.Json.JsonConvert.SerializeObject(r);
}
public double Avg(int column, DataTable dt)
{
double value = 0;
int count = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
string db = dt.Rows[i][column].ToString().Trim();
if (!string.IsNullOrEmpty(db))
{
count++;
value += Convert.ToDouble(db);
}
}
return value != 0 && count != 0 ? value / count : 0;
}
public void GetCellValue(ICell cell, DataTable dt_rate, string SCAN_START_TIME, string columnName)
{
DataRow dataRow = dt_rate.NewRow();
dataRow["SCAN_START_TIME"] = SCAN_START_TIME;
switch (cell.CellType)
{
case CellType.Blank:
dataRow[columnName] = string.Empty;
break;
case CellType.Boolean:
dataRow[columnName] = cell.BooleanCellValue;
break;
case CellType.Numeric:
if (DateUtil.IsCellDateFormatted(cell))//日期
{
dataRow[columnName] = cell.DateCellValue;
}
else
{
dataRow[columnName] = cell.NumericCellValue;
}
break;
case CellType.String:
break;
case CellType.Error:
dataRow[columnName] = cell.ErrorCellValue;
break;
case CellType.Formula://公式
try
{
XSSFFormulaEvaluator e = new XSSFFormulaEvaluator(cell.Sheet.Workbook);
e.EvaluateInCell(cell);
dataRow[columnName] = cell.ToString();
}
catch
{
if (DateUtil.IsCellDateFormatted(cell))//日期
{
dataRow[columnName] = cell.DateCellValue;
}
else
{
dataRow[columnName] = cell.NumericCellValue;
}
}
break;
default:
dataRow[columnName] = cell.ToString();
break;
}
dt_rate.Rows.Add(dataRow);
}
public Double GetCellDoubleValue(ICell cell)
{
switch (cell.CellType)
{
case CellType.Blank:
return -1; //自定义的标识
break;
case CellType.Boolean:
return -2;
break;
case CellType.Numeric:
if (DateUtil.IsCellDateFormatted(cell))//日期
{
return -3;
}
else
{
return cell.NumericCellValue;
}
break;
case CellType.String:
return Convert.ToDouble(cell.ToString());
break;
case CellType.Error:
return cell.ErrorCellValue;
break;
case CellType.Formula://公式
try
{
XSSFFormulaEvaluator e = new XSSFFormulaEvaluator(cell.Sheet.Workbook);
e.EvaluateInCell(cell);
return Convert.ToDouble(cell.ToString());
}
catch
{
if (DateUtil.IsCellDateFormatted(cell))//日期
{
return -3;
}
else
{
return cell.NumericCellValue;
}
}
break;
default:
return Convert.ToDouble(cell.ToString());
break;
}
}
//注意1:如果合并在前,则在后面不能直接用
//Row row=sheet.createRow(0);
//而应该改为
//Row row=sheet.getRow(0);
//if(row==null){
//row2=sheet.createRow(2);
//}
//否则直接createRow会覆盖先前合并时定义的边框样式。
private static void setRegionStyle(ICellStyle cs, CellRangeAddress region, ISheet sheet)
{
for (int i = region.FirstRow; i <= region.LastRow; i++)
{
IRow row = sheet.GetRow(i);
if (row == null) row = sheet.CreateRow(i);
for (int j = region.FirstColumn; j <= region.LastColumn; j++)
{
ICell cell = row.GetCell(j);
if (cell == null)
{
cell = row.CreateCell(j);
cell.SetCellValue("");
}
cell.CellStyle = cs;
}
}
}
///
/// 设置列名及列宽
///
public void setColumnWidth(ISheet sheet, DataTable dt, ICellStyle headStyle, int[] arrColWidth)
{
IRow headerRow = sheet.CreateRow(0); //上面写完行数据,计算完列宽后再写列名
foreach (DataColumn column in dt.Columns)
{
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
headerRow.GetCell(column.Ordinal).CellStyle = headStyle;
if (arrColWidth[column.Ordinal] >= 255)
{
sheet.SetColumnWidth(column.Ordinal, 254 * 256);
}
else
{
sheet.SetColumnWidth(column.Ordinal, (arrColWidth[column.Ordinal] + 1) * 256);
}
//设置列宽
}
}
///
/// 读取Excel流到DataSet
///
/// Excel流
///
public static DataSet ImportExceltoDs(Stream stream)
{
try
{
DataSet ds = new DataSet();
IWorkbook wb;
using (stream)
{
wb = WorkbookFactory.Create(stream);
}
for (int i = 0; i < wb.NumberOfSheets; i++)
{
string sheet_name = wb.GetSheetAt(i).SheetName;
DataTable dt = new DataTable(sheet_name);
ISheet sheet = wb.GetSheetAt(i);
dt = ImportDt(sheet, 0, true, sheet_name);
ds.Tables.Add(dt);
}
return ds;
}
catch (Exception)
{
throw;
}
}
static DataTable ImportDt(ISheet sheet, int HeaderRowIndex, bool needHeader, string table_name)
{
DataTable table = new DataTable(table_name);
IRow headerRow;
int cellCount;
try
{
if (HeaderRowIndex < 0 || !needHeader)
{
headerRow = sheet.GetRow(0);
cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i <= cellCount; i++)
{
DataColumn column = new DataColumn(Convert.ToString(i));
table.Columns.Add(column);
}
}
else
{
headerRow = sheet.GetRow(HeaderRowIndex);
cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
if (headerRow.GetCell(i) == null)
{
if (table.Columns.IndexOf(Convert.ToString(i)) > 0)
{
DataColumn column = new DataColumn(Convert.ToString("重复列名" + i));
table.Columns.Add(column);
}
else
{
DataColumn column = new DataColumn(Convert.ToString(i));
table.Columns.Add(column);
}
}
else if (table.Columns.IndexOf(headerRow.GetCell(i).ToString()) > 0)
{
DataColumn column = new DataColumn(Convert.ToString("重复列名" + i));
table.Columns.Add(column);
}
else
{
DataColumn column = new DataColumn(headerRow.GetCell(i).ToString());
table.Columns.Add(column);
}
}
}
int rowCount = sheet.LastRowNum;
for (int i = (HeaderRowIndex + 1); i <= sheet.LastRowNum; i++)
{
try
{
IRow row;
if (sheet.GetRow(i) == null)
{
row = sheet.CreateRow(i);
}
else
{
row = sheet.GetRow(i);
}
DataRow dataRow = table.NewRow();
for (int j = row.FirstCellNum; j <= cellCount; j++)
{
try
{
if (row.GetCell(j) != null)
{
switch (row.GetCell(j).CellType)
{
case CellType.String:
string str = row.GetCell(j).StringCellValue;
if (str != null && str.Length > 0)
{
dataRow[j] = str.ToString();
}
else
{
dataRow[j] = null;
}
break;
case CellType.Numeric:
if (DateUtil.IsCellDateFormatted(row.GetCell(j)))
{
dataRow[j] = DateTime.FromOADate(row.GetCell(j).NumericCellValue);
}
else
{
dataRow[j] = Convert.ToDouble(row.GetCell(j).NumericCellValue);
}
break;
case CellType.Boolean:
dataRow[j] = Convert.ToString(row.GetCell(j).BooleanCellValue);
break;
case CellType.Error:
dataRow[j] = ErrorEval.GetText(row.GetCell(j).ErrorCellValue);
break;
case CellType.Formula:
switch (row.GetCell(j).CachedFormulaResultType)
{
case CellType.String:
string strFORMULA = row.GetCell(j).StringCellValue;
if (strFORMULA != null && strFORMULA.Length > 0)
{
dataRow[j] = strFORMULA.ToString();
}
else
{
dataRow[j] = null;
}
break;
case CellType.Numeric:
dataRow[j] = Convert.ToString(row.GetCell(j).NumericCellValue);
break;
case CellType.Boolean:
dataRow[j] = Convert.ToString(row.GetCell(j).BooleanCellValue);
break;
case CellType.Error:
dataRow[j] = ErrorEval.GetText(row.GetCell(j).ErrorCellValue);
break;
default:
dataRow[j] = "";
break;
}
break;
default:
dataRow[j] = "";
break;
}
}
}
catch (Exception exception)
{
//wl.WriteLogs(exception.ToString());
}
}
table.Rows.Add(dataRow);
}
catch (Exception exception)
{
// wl.WriteLogs(exception.ToString());
}
}
}
catch (Exception exception)
{
// wl.WriteLogs(exception.ToString());
}
return table;
}
}
}