当前位置: 首页>>代码示例>>C#>>正文


C# IWorkbook.GetSheetAt方法代码示例

本文整理汇总了C#中IWorkbook.GetSheetAt方法的典型用法代码示例。如果您正苦于以下问题:C# IWorkbook.GetSheetAt方法的具体用法?C# IWorkbook.GetSheetAt怎么用?C# IWorkbook.GetSheetAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWorkbook的用法示例。


在下文中一共展示了IWorkbook.GetSheetAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestMissingWorkbookMissingOverride

        public void TestMissingWorkbookMissingOverride()
        {
            mainWorkbook = HSSFTestDataSamples.OpenSampleWorkbook(MAIN_WORKBOOK_FILENAME);
            ISheet lSheet = mainWorkbook.GetSheetAt(0);
            ICell lA1Cell = lSheet.GetRow(0).GetCell(0);
            ICell lB1Cell = lSheet.GetRow(1).GetCell(0);
            ICell lC1Cell = lSheet.GetRow(2).GetCell(0);

            Assert.AreEqual(CellType.Formula, lA1Cell.CellType);
            Assert.AreEqual(CellType.Formula, lB1Cell.CellType);
            Assert.AreEqual(CellType.Formula, lC1Cell.CellType);

            // Check cached values
            Assert.AreEqual(10.0d, lA1Cell.NumericCellValue, 0.00001d);
            Assert.AreEqual("POI rocks!", lB1Cell.StringCellValue);
            Assert.AreEqual(true, lC1Cell.BooleanCellValue);

            // Evaluate
            IFormulaEvaluator evaluator = mainWorkbook.GetCreationHelper().CreateFormulaEvaluator();
            evaluator.IgnoreMissingWorkbooks = (true);

            Assert.AreEqual(CellType.Numeric, evaluator.EvaluateFormulaCell(lA1Cell));
            Assert.AreEqual(CellType.String, evaluator.EvaluateFormulaCell(lB1Cell));
            Assert.AreEqual(CellType.Boolean, evaluator.EvaluateFormulaCell(lC1Cell));

            Assert.AreEqual(10.0d, lA1Cell.NumericCellValue, 0.00001d);
            Assert.AreEqual("POI rocks!", lB1Cell.StringCellValue);
            Assert.AreEqual(true, lC1Cell.BooleanCellValue);
        }
开发者ID:newlysoft,项目名称:npoi,代码行数:29,代码来源:TestMissingWorkbook.cs

示例2: ReadBook

		//ブックの読み込み
		static void ReadBook(IWorkbook book, string path, StringGridDictionary gridDictionary)
		{
			for (int i = 0; i < book.NumberOfSheets; ++i)
			{
				ISheet sheet = book.GetSheetAt(i);
				StringGrid grid = ReadSheet(sheet, path);
				gridDictionary.Add(new StringGridDictionaryKeyValue(sheet.SheetName, grid));
			}
		}
开发者ID:OsamaRazaAnsari,项目名称:2DDressUpGame,代码行数:10,代码来源:ExcelParser.cs

示例3: Parse

 public ExcelMetaData Parse(IWorkbook workbook)
 {
     var meta = new ExcelMetaData();
     meta.Workbook = workbook;
     for (int i = 0; i < workbook.NumberOfSheets; i++)
     {
         ISheet sheet = workbook.GetSheetAt(i);
         ExcelSheetMetaData sheetMeta = ParseSheet(sheet);
         sheetMeta.SheetIndex = i;
         meta.Sheets.Add(sheetMeta);
     }
     return meta;
 }
开发者ID:alittletired,项目名称:mysoft,代码行数:13,代码来源:ExcelMetaDataParser.cs

示例4: Convert

    private List<UserTicketTable> Convert(IWorkbook excelbook)
    {
        List<UserTicketTable> usertickets = new List<UserTicketTable>();
        System.Collections.IEnumerator rowEnumerator = excelbook.GetSheetAt(0).GetRowEnumerator();
        var sht = excelbook.GetSheetAt(0);
        int rowCount = sht.PhysicalNumberOfRows;
        int currentIndex = 0;
        while (rowEnumerator.MoveNext())
        {
            currentIndex++;
            if (currentIndex == 1) { continue; }
            HSSFRow row = rowEnumerator.Current as HSSFRow;
            if (row.Cells[0].CellType== CellType.BLANK) break;
            UserTicketTable userticket = new UserTicketTable();
            userticket.gdate = DateTime.Now;
          string productCode=row.Cells[1].StringCellValue;
          Model.Ticket t = bllTicket.GetByProductCode(productCode);
          if (t == null)
          {
              throw new Exception("没有参加活动的门票:" +productCode );
          }
          userticket.gid = productCode;
          string mobile = string.Empty;
            if(row.GetCell(4)!=null)
            {
                userticket.mobile = row.GetCell(4).ToString().Trim();
            }
            userticket.orderfrom = tbxPartnerCode.Text.Trim();
            userticket.postcode = row.Cells[3].StringCellValue.Trim();
            userticket.syncState = 0;
            userticket.truename = row.Cells[2].StringCellValue.Trim();
            userticket.type =tbxActivityCode.Text.Trim()=="suichang2013"? 2:tbxActivityCode.Text.Trim()=="quzhouspring"?1:0;

            usertickets.Add(userticket);

        }
        return usertickets;
    }
开发者ID:phiree,项目名称:testttt,代码行数:38,代码来源:ImportForUserTicket.aspx.cs

示例5: EvaluateWorkbook

     // TODO should we have this stuff in the FormulaEvaluator?
     private void EvaluateWorkbook(IWorkbook workbook){
     IFormulaEvaluator eval = workbook.GetCreationHelper().CreateFormulaEvaluator();
     for(int i=0; i < workbook.NumberOfSheets; i++) {
         ISheet sheet = workbook.GetSheetAt(i);
         IEnumerator rows = sheet.GetRowEnumerator();
         for (IRow r = null; rows.MoveNext(); )
         {
             r = (IRow)rows.Current;
             foreach (ICell c in r)
             {
                 if (c.CellType == CellType.FORMULA)
                 {
                     eval.EvaluateFormulaCell(c);
                 }
             }
         }
     }
 }
开发者ID:WPG,项目名称:npoi,代码行数:19,代码来源:BaseTestSheetAutosizeColumn.cs

示例6: CExcelFile

    public CExcelFile(string excelPath)
    {
        Path = excelPath;

        using (var file = new FileStream(excelPath, FileMode.Open, FileAccess.Read))
        {
            try
            {
                Workbook = WorkbookFactory.Create(file);
            }
            catch (Exception e)
            {
                CDebug.LogError("无法打开Excel: {0}, 可能原因:正在打开?或是Office2007格式(尝试另存为)? {1}", excelPath, e.Message);
                IsLoadSuccess = false;
            }
            
        }
        if (IsLoadSuccess)
        {
            CDebug.Assert(Workbook);

            //var dt = new DataTable();

            Worksheet = Workbook.GetSheetAt(0);
            ColName2Index = new Dictionary<string, int>();
            var headerRow = Worksheet.GetRow(0);
            int columnCount = headerRow.LastCellNum;

            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
            {
                var cell = headerRow.GetCell(columnIndex);
                if (cell == null)
                {
                    //CDebug.LogError("Null Cel on Column: {0}, File: {1}", columnIndex, excelPath);
                    // 可能是空字符串的格子,忽略!
                    continue;
                }
                var headerName = cell.ToString().Split('|', '[', ':', ']')[0]; // 去掉参数定义
                ColName2Index[headerName] = columnIndex;
            }
        }
        
    }
开发者ID:henry-yuxi,项目名称:CosmosEngine,代码行数:43,代码来源:CExcelFile.cs

示例7: doTest49928Core

        public void doTest49928Core(IWorkbook wb)
        {
            DataFormatter df = new DataFormatter();

            ISheet sheet = wb.GetSheetAt(0);
            ICell cell = sheet.GetRow(0).GetCell(0);
            ICellStyle style = cell.CellStyle;

            String poundFmt = "\"\u00a3\"#,##0;[Red]\\-\"\u00a3\"#,##0";
            // not expected normally, id of a custom format should be greater
            // than BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX
            short poundFmtIdx = 6;

            Assert.AreEqual(poundFmt, style.GetDataFormatString());
            Assert.AreEqual(poundFmtIdx, style.DataFormat);
            Assert.AreEqual("\u00a31", df.FormatCellValue(cell));

            IDataFormat dataFormat = wb.CreateDataFormat();
            Assert.AreEqual(poundFmtIdx, dataFormat.GetFormat(poundFmt));
            Assert.AreEqual(poundFmt, dataFormat.GetFormat(poundFmtIdx));
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:21,代码来源:BaseTestDataFormat.cs

示例8: antennis

 private Brain antennis(int matches, IWorkbook wb, string v, bool ten, int mode)
 {
     games = new List<List<string>>();
     for (int j = 3; j < wb.GetSheetAt(0).LastRowNum + 1; j++)
     {
         if (j < matches)
         {
             string opponent = Convert.ToString(wb.GetSheetAt(0).GetRow(j).GetCell(0));
             List<String> a = new List<string>();
             games.Add(a);
             for (int i = 0; i < wb.GetSheetAt(0).GetRow(2).LastCellNum; i++)
             {
                 bool inmas = false;
                 for (int k = 0; k < gcolumns.Length; k++)
                 {
                     if (i == gcolumns[k])
                         inmas = true;
                 }
                 if (ten)
                 {
                     if (inmas)
                     {
                         v = Convert.ToString(wb.GetSheetAt(0).GetRow(j).GetCell(i));
                         if (i > 0)
                         {
                             if (v == "")
                                 games[j - 3].Add("Н");
                             else
                                 games[j - 3].Add(v);
                         }
                     }
                 }
                 else
                 {
                     v = Convert.ToString(wb.GetSheetAt(0).GetRow(j).GetCell(i));
                     if (i > 0)
                     {
                         if (v == "")
                             games[j - 3].Add("Н");
                         else
                             games[j - 3].Add(v);
                     }
                 }
             }
         }
         else break;
     }
     Brain brain = new Brain(games, ten, bigwave, smallwave, verysmallwave, mode);
     brain.analiserows();
     return brain;
 }
开发者ID:mikel365,项目名称:git-github.com-mikel365-betting,代码行数:51,代码来源:MainWindow.xaml.cs

示例9: CheckUnicodeValues

 private void CheckUnicodeValues(IWorkbook wb)
 {
     Assert.AreEqual((wb is HSSFWorkbook ? "row 0, cell 0 _x0046_ without Changes" : "row 0, cell 0 F without Changes"),
             wb.GetSheetAt(0).GetRow(0).GetCell(0).ToString());
     Assert.AreEqual((wb is HSSFWorkbook ? "row 0, cell 1 _x005fx0046_ with Changes" : "row 0, cell 1 _x005fx0046_ with Changes"),
             wb.GetSheetAt(0).GetRow(0).GetCell(1).ToString());
     Assert.AreEqual((wb is HSSFWorkbook ? "hgh_x0041_**_x0100_*_x0101_*_x0190_*_x0200_*_x0300_*_x0427_*" : "hghA**\u0100*\u0101*\u0190*\u0200*\u0300*\u0427*"),
             wb.GetSheetAt(0).GetRow(0).GetCell(2).ToString());
 }
开发者ID:newlysoft,项目名称:npoi,代码行数:9,代码来源:BaseTestCell.cs

示例10: Parse

        ToxyTable Parse(IWorkbook workbook, int sheetIndex, bool extractHeader, bool extractFooter, bool hasHeader, bool fillBlankCells, bool includeComment, HSSFDataFormatter formatter)
        {
            ToxyTable table = new ToxyTable();
            if (workbook.NumberOfSheets - 1 < sheetIndex)
            {
                throw new ArgumentOutOfRangeException(string.Format("This file only contains {0} sheet(s).", workbook.NumberOfSheets));
            }
            ISheet sheet = workbook.GetSheetAt(sheetIndex);
            table.Name = sheet.SheetName;

            if (extractHeader && sheet.Header != null)
            {
                table.PageHeader = sheet.Header.Left + "|" + sheet.Header.Center + "|" + sheet.Header.Right;
            }

            if (extractFooter && sheet.Footer != null)
            {
                table.PageFooter = sheet.Footer.Left + "|" + sheet.Footer.Center + "|" + sheet.Footer.Right;
            }

            bool firstRow = true;
            table.LastRowIndex = sheet.LastRowNum;
            foreach (IRow row in sheet)
            {
                ToxyRow tr = null;
                if (!hasHeader || !firstRow)
                {
                    tr = new ToxyRow(row.RowNum);
                }
                else if (hasHeader && firstRow)
                {
                    table.HeaderRows.Add(new ToxyRow(row.RowNum));
                }
                foreach (ICell cell in row)
                {
                    if (hasHeader && firstRow)
                    {
                        table.HeaderRows[0].Cells.Add(new ToxyCell(cell.ColumnIndex, cell.ToString()));
                    }
                    else
                    {
                        if (tr.LastCellIndex < cell.ColumnIndex)
                        {
                            tr.LastCellIndex = cell.ColumnIndex;
                        }
                        ToxyCell c = new ToxyCell(cell.ColumnIndex, formatter.FormatCellValue(cell));
                        if (!string.IsNullOrEmpty(cell.ToString()))
                        {
                            tr.Cells.Add(c);
                        }
                        else if (fillBlankCells)
                        {
                            tr.Cells.Add(c);
                        }
                        if (includeComment && cell.CellComment != null)
                        {
                            c.Comment = cell.CellComment.String.String;
                        }
                    }
                }
                if (tr != null)
                {
                    tr.RowIndex = row.RowNum;
                    table.Rows.Add(tr);

                    if (table.LastColumnIndex < tr.LastCellIndex)
                        table.LastColumnIndex = tr.LastCellIndex;
                }
                if (firstRow)
                {
                    firstRow = false;
                }
            }
            for (int j = 0; j < sheet.NumMergedRegions; j++)
            {
                var range = sheet.GetMergedRegion(j);
                table.MergeCells.Add(new MergeCellRange() { FirstRow = range.FirstRow, FirstColumn = range.FirstColumn, LastRow = range.LastRow, LastColumn = range.LastColumn });
            }
            return table;
        }
开发者ID:iraychen,项目名称:toxy,代码行数:80,代码来源:ExcelSpreadsheetParser.cs

示例11: GenerateSheet

 /// <summary>
 /// 修改工作簿内容
 /// </summary>
 /// <param name="readworkbook"></param>
 /// <param name="para"></param>
 /// <returns></returns>
 public IWorkbook GenerateSheet(IWorkbook readworkbook, QueryParameters para)
 {
     //获取工作簿
     ISheet sheet = readworkbook.GetSheetAt(0);
     //设置日期
     if (para.ReportType == 18)
     {
         SetReportDate(sheet, 1, 14, para.StartTime.Value, para.ReportType);
     }
     using (DataSubmittedEntities db = new DataSubmittedEntities())
     {
         //设置表头
         var holidayName = db.OT_Dic.Where(a => a.Id == para.HolidayId).Select(a => a.Name).ToList();
         if (!string.IsNullOrEmpty(holidayName[0]))
             SetValue(sheet, 0, 0, string.Format("{0}假期高速公路交通流量统计表", holidayName[0]));
         //数据集合
         List<HDayAADTViewModel> pHdayAADT = db.RP_HDayAADTSta.Where(s => s.CalcuTime == para.StartTime).Select(s => new HDayAADTViewModel()
         {
             LineType = s.LineType,
             ExNat = s.ExNat,
             EnNat = s.EnNat,
             NatSum = s.ExNat + s.EnNat,
             ExEqu = s.ExEqu,
             EnEqu = s.EnEqu,
             EquSum = s.ExEqu + s.EnEqu,
             CrowDeg = s.CrowDeg,
             SmaEx = s.SmaEx,
             SmaEn = s.SmaEn,
             SmaSum = s.SmaEx + s.SmaEn,
             MedEn = s.MedEn,
             MedEx = s.MedEx,
             MedSum = s.MedEx + s.MedEn,
             LarEx = s.LarEx,
             LarEn = s.LarEn,
             LarSum = s.LarEn + s.LarEx,
             HeaEn = s.HeaEn,
             HeaEx = s.HeaEx,
             HeaSum = s.HeaEx + s.HeaEn,
             SupEn = s.SupEn,
             SupEx = s.SupEx,
             SupSum = s.SupEn + s.SupEx,
             EnExTrukNum = s.EnExTrukNum,
             CarTrukPer = s.CarTrukPer,
             SupTruNum = s.SupTruNum,
             SupTruPer = s.SupTruPer
         }).ToList().OrderBy(s => s.Sorting).ToList();
         if (pHdayAADT.Count > 0)
         {
             for (int i = 0; i < pHdayAADT.Count; i++)
             {
                 SetValue(sheet, i + 5, 7, pHdayAADT[i].NatSum.ToString());
                 SetValue(sheet, i + 5, 8, pHdayAADT[i].ExNat.ToString());
                 SetValue(sheet, i + 5, 9, pHdayAADT[i].EnNat.ToString());
                 SetValue(sheet, i + 5, 10, pHdayAADT[i].EquSum.ToString());
                 SetValue(sheet, i + 5, 11, pHdayAADT[i].ExEqu.ToString());
                 SetValue(sheet, i + 5, 12, pHdayAADT[i].EnEqu.ToString());
                 SetValue(sheet, i + 5, 14, pHdayAADT[i].CrowDeg.ToString());
                 SetValue(sheet, i + 5, 15, pHdayAADT[i].SmaSum.ToString());
                 SetValue(sheet, i + 5, 16, pHdayAADT[i].SmaEx.ToString());
                 SetValue(sheet, i + 5, 17, pHdayAADT[i].SmaEn.ToString());
                 SetValue(sheet, i + 5, 18, pHdayAADT[i].MedSum.ToString());
                 SetValue(sheet, i + 5, 19, pHdayAADT[i].MedEx.ToString());
                 SetValue(sheet, i + 5, 20, pHdayAADT[i].MedEn.ToString());
                 SetValue(sheet, i + 5, 21, pHdayAADT[i].LarSum.ToString());
                 SetValue(sheet, i + 5, 22, pHdayAADT[i].LarEx.ToString());
                 SetValue(sheet, i + 5, 23, pHdayAADT[i].LarEn.ToString());
                 SetValue(sheet, i + 5, 24, pHdayAADT[i].HeaSum.ToString());
                 SetValue(sheet, i + 5, 25, pHdayAADT[i].HeaEx.ToString());
                 SetValue(sheet, i + 5, 26, pHdayAADT[i].HeaEn.ToString());
                 SetValue(sheet, i + 5, 27, pHdayAADT[i].SupSum.ToString());
                 SetValue(sheet, i + 5, 28, pHdayAADT[i].SupEx.ToString());
                 SetValue(sheet, i + 5, 29, pHdayAADT[i].SupEn.ToString());
                 SetValue(sheet, i + 5, 30, pHdayAADT[i].EnExTrukNum.ToString());
                 if (i == 5 && string.IsNullOrEmpty(pHdayAADT[i].CarTrukPer.ToString()))
                 {
                     SetValue(sheet, i + 5, 31, 0);
                 }
                 else
                 {
                     SetValue(sheet, i + 5, 31, pHdayAADT[i].CarTrukPer.ToString());
                 }
                 SetValue(sheet, i + 5, 32, pHdayAADT[i].SupTruNum.ToString());
                 if (i == 5 && string.IsNullOrEmpty(pHdayAADT[i].SupTruPer.ToString()))
                 {
                     SetValue(sheet, i + 5, 33, 0);
                 }
                 else
                 {
                     SetValue(sheet, i + 5, 33, pHdayAADT[i].SupTruPer.ToString());
                 }
             }
         }
         if (pHdayAADT.Count(s => s.LineType == 3) > 0)
         {
//.........这里部分代码省略.........
开发者ID:ibcLee,项目名称:Wttech.DataSubmitted,代码行数:101,代码来源:HDayAADTStatistical.cs

示例12: Load5MINKExcelFile

 private void Load5MINKExcelFile(string sFilePath)
 {
     if (File.Exists(sFilePath))
     {
         Form1.g_UI_ShowInfo("Loading 5K xml");
         using (FileStream fs = new FileStream(sFilePath, FileMode.Open, FileAccess.Read))
         {
             m_MIN5KWorkBook = new XSSFWorkbook(fs);
             m_MIN5KSheet = (XSSFSheet)m_MIN5KWorkBook.GetSheetAt(0);
         }
         Form1.g_UI_ShowInfo("Load 5K xml Finished");
     }
     else
     {
         Form1.g_UI_ShowInfo("Cannot find 5K xml");
     }
 }
开发者ID:s850042002,项目名称:ostock-simulation,代码行数:17,代码来源:SimulateSystem.cs

示例13: LoadFPExcel

 private void LoadFPExcel(string sFilePath)
 {
     if (File.Exists(sFilePath))
     {
         Form1.g_UI_ShowInfo("Loading FP xml");
         using (FileStream fs = new FileStream(sFilePath, FileMode.Open, FileAccess.Read))
         {
             m_FPWorkBook = new NPOI.HSSF.UserModel.HSSFWorkbook(fs);
             m_FPSheet = (ISheet)m_FPWorkBook.GetSheetAt(0);
         }
         Form1.g_UI_ShowInfo("Load FP xml Finished");
     }
     else
     {
         Form1.g_UI_ShowInfo("Cannot find FP xml");
     }
 }
开发者ID:s850042002,项目名称:ostock-simulation,代码行数:17,代码来源:SimulateSystem.cs

示例14: CheckWorkbookGrouping

        private void CheckWorkbookGrouping(IWorkbook wb, bool?[] collapsed, bool[] hidden, int[] outlineLevel)
        {
            printWorkbook(wb);
            ISheet sheet = wb.GetSheetAt(0);

            Assert.AreEqual(collapsed.Length, hidden.Length);
            Assert.AreEqual(collapsed.Length, outlineLevel.Length);
            Assert.AreEqual(collapsed.Length, sheet.LastRowNum - sheet.FirstRowNum + 1,
                "Expected " + collapsed.Length + " rows with collapsed state, but had " + (sheet.LastRowNum - sheet.FirstRowNum + 1) + " rows ("
                    + sheet.FirstRowNum + "-" + sheet.LastRowNum + ")");
            for (int i = sheet.FirstRowNum; i < sheet.LastRowNum; i++)
            {
                if (collapsed[i - sheet.FirstRowNum] == null)
                {
                    continue;
                }
                XSSFRow row = (XSSFRow)sheet.GetRow(i);
                Assert.IsNotNull(row, "Could not read row " + i);
                Assert.IsNotNull(row.GetCTRow(), "Could not read row " + i);
                Assert.AreEqual(collapsed[i - sheet.FirstRowNum], row.GetCTRow().collapsed, "Row: " + i + ": collapsed");
                Assert.AreEqual(hidden[i - sheet.FirstRowNum], row.GetCTRow().hidden, "Row: " + i + ": hidden");

                Assert.AreEqual(outlineLevel[i - sheet.FirstRowNum], row.GetCTRow().outlineLevel, "Row: " + i + ": level");
            }

            WriteToFile(wb);
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:27,代码来源:TestXSSFSheetRowGrouping.cs

示例15: GenerateSheet

        /// <summary>
        /// 修改工作簿内容
        /// </summary>
        /// <param name="readworkbook"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        public IWorkbook GenerateSheet(IWorkbook readworkbook, QueryParameters para)
        {
            try
            {
                using (DataSubmittedEntities db = new DataSubmittedEntities())
                {
                    //日期合计
                    //获取工作簿
                    ISheet sheet = readworkbook.GetSheetAt(0);
                    int pDataCount = 0;
                    if (para.EndTime.Value >= para.StartTime.Value)
                    {
                        pDataCount = (para.EndTime.Value - para.StartTime.Value).Days + 1;
                    }
                    //设置标题
                    var holidayName = db.OT_Dic.Where(a => a.Id == para.HolidayId).Select(a => a.Name).ToList();
                    string title = string.Format("天津市高速公路支队{0}年{1}假期流量表(出口)", ((DateTime)para.EndTime).Year, holidayName[0].ToString());
                    SetValue(sheet, 0, 0, title);
                    //如果多于4天,则手动添加单元格
                    if (pDataCount > 4)
                    {
                        int pTemp = pDataCount - 4;
                        //遍历创建所有单元格
                        //列
                        for (int i = 0; i < pTemp; i++)
                        {
                            //行--该模版有隐藏行
                            for (int n = 0; n < 19; n++)
                            {
                                IRow row = sheet.GetRow(n);
                                ICell cell = row.CreateCell(9 + i);//创建列
                                cell.CellStyle = GetCellStyle(readworkbook, 1);
                            }
                        }

                    }
                    else if (pDataCount < 4)//如果小于4天,则删除列
                    {
                        int pTemp = 4 - pDataCount;
                        //遍历设置所有单元格没有边框
                        //列
                        for (int i = 0; i < pTemp; i++)
                        {

                            for (int n = 0; n < 19; n++)
                            {
                                ICell cell = sheet.GetRow(n).GetCell(i + 5 + pDataCount);
                                cell.CellStyle = GetCellStyle(readworkbook, 0);
                            }
                        }
                    }
                    double? pSum = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) >= para.StartTime.Value && DbFunctions.TruncateTime(s.CalcuTime) <= para.EndTime.Value).Sum(s => s.Out);
                    double? pLastSum = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) >= para.LastYearStart.Value && DbFunctions.TruncateTime(s.CalcuTime) <= para.LastYearEnd.Value).Sum(s => s.Out);
                    double? Growth = null;
                    if (pLastSum.HasValue && pLastSum != 0 && pLastSum != 0.0 && pSum.HasValue)
                    {
                        Growth = Math.Round((pSum.Value - pLastSum.Value) / pLastSum.Value, 2);
                    }
                    if (pSum.HasValue)
                    {
                        SetValue(sheet, 17, 2 + pDataCount, pSum.ToString());
                        SetValue(sheet, 18, 2 + pDataCount, pSum.ToString());
                    }
                    if (pLastSum.HasValue)
                    {
                        SetValue(sheet, 17, 3 + pDataCount, pLastSum.ToString());
                        SetValue(sheet, 18, 3 + pDataCount, pLastSum.ToString());
                    }

                    if (Growth.HasValue)
                    {
                        SetValue(sheet, 17, 4 + pDataCount, Growth.ToString());
                        SetValue(sheet, 18, 4 + pDataCount, Growth.ToString());
                    }
                    //合并单元格
                    //标题行
                    SetCellRangeAddress(sheet, 0, 0, 0, 4 + pDataCount);
                    //日期行
                    SetCellRangeAddress(sheet, 1, 1, 2, pDataCount + 1);
                    //合并最后三列
                    SetCellRangeAddress(sheet, 1, 2, 2 + pDataCount, 2 + pDataCount);
                    SetCellRangeAddress(sheet, 1, 2, 3 + pDataCount, 3 + pDataCount);
                    SetCellRangeAddress(sheet, 1, 2, 4 + pDataCount, 4 + pDataCount);
                    //
                    SetValue(sheet, 1, 2 + pDataCount, "合计");
                    SetValue(sheet, 1, 3 + pDataCount, "去年同期总流量");
                    SetValue(sheet, 1, 4 + pDataCount, "同比增幅");

                    for (int i = 0; i < pDataCount; i++)
                    {
                        DateTime? pDt = para.StartTime.Value.AddDays(i);
                        List<RP_HDayAADT> pHourAADTList = db.RP_HDayAADT.Where(s => DbFunctions.TruncateTime(s.CalcuTime) == pDt).ToList();

                        if (pHourAADTList.Count == 1)
//.........这里部分代码省略.........
开发者ID:ibcLee,项目名称:Wttech.DataSubmitted,代码行数:101,代码来源:HDayExStatistical.cs


注:本文中的IWorkbook.GetSheetAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。