コード例 #1
0
        public void TestFormulaCache()
        {
            IWorkbook wb = new XSSFWorkbook();
            ISheet sheet = new SheetBuilder(wb, plotData).Build();
            IDrawing Drawing = sheet.CreateDrawingPatriarch();
            IClientAnchor anchor = Drawing.CreateAnchor(0, 0, 0, 0, 1, 1, 10, 30);
            IChart chart = Drawing.CreateChart(anchor);

            IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.BOTTOM);
            IChartAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.LEFT);

            IScatterChartData scatterChartData =
                chart.GetChartDataFactory().CreateScatterChartData();

            DataMarker xMarker = new DataMarker(sheet, CellRangeAddress.ValueOf("A1:E1"));
            DataMarker yMarker = new DataMarker(sheet, CellRangeAddress.ValueOf("A2:E2"));
            IScatterChartSerie serie = scatterChartData.AddSerie(xMarker, yMarker);

            chart.Plot(scatterChartData, bottomAxis, leftAxis);

            XSSFScatterChartData.Serie xssfScatterSerie =
                (XSSFScatterChartData.Serie)serie;
            XSSFNumberCache yCache = xssfScatterSerie.LastCalculatedYCache;

            Assert.AreEqual(5, yCache.PointCount);
            Assert.AreEqual(4.0, yCache.GetValueAt(3), 0.00001);
            Assert.AreEqual(16.0, yCache.GetValueAt(5), 0.00001);
        }
コード例 #2
0
        public void TestOneSeriePlot()
        {
            IWorkbook wb = new XSSFWorkbook();
            ISheet sheet = new SheetBuilder(wb, plotData).Build();
            IDrawing Drawing = sheet.CreateDrawingPatriarch();
            IClientAnchor anchor = Drawing.CreateAnchor(0, 0, 0, 0, 1, 1, 10, 30);
            IChart chart = Drawing.CreateChart(anchor);

            IChartAxis bottomAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Bottom);
            IChartAxis leftAxis = chart.GetChartAxisFactory().CreateValueAxis(AxisPosition.Left);

            IScatterChartData<string, double> scatterChartData =
                chart.GetChartDataFactory().CreateScatterChartData<string, double>();

            IChartDataSource<String> xs = DataSources.FromStringCellRange(sheet, CellRangeAddress.ValueOf("A1:J1"));
            IChartDataSource<double> ys = DataSources.FromNumericCellRange(sheet, CellRangeAddress.ValueOf("A2:J2"));
            IScatterChartSerie<string, double> serie = scatterChartData.AddSerie(xs, ys);

            Assert.IsNotNull(serie);

            Assert.AreEqual(1, scatterChartData.GetSeries().Count);
            Assert.IsTrue(scatterChartData.GetSeries().Contains(serie));

            chart.Plot(scatterChartData, bottomAxis, leftAxis);
        }
コード例 #3
0
ファイル: TestSheetBuilder.cs プロジェクト: ctddjyds/npoi
        public void TestNotCreateEmptyCells()
        {
            IWorkbook wb = new HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet = new SheetBuilder(wb, testData).Build();

            Assert.AreEqual(sheet.PhysicalNumberOfRows, 3);

            NPOI.SS.UserModel.IRow firstRow = sheet.GetRow(0);
            NPOI.SS.UserModel.ICell firstCell = firstRow.GetCell(0);

            Assert.AreEqual(firstCell.CellType, CellType.NUMERIC);
            Assert.AreEqual(1.0, firstCell.NumericCellValue, 0.00001);

            NPOI.SS.UserModel.IRow secondRow = sheet.GetRow(1);
            Assert.IsNotNull(secondRow.GetCell(0));
            Assert.IsNull(secondRow.GetCell(2));

            NPOI.SS.UserModel.IRow thirdRow = sheet.GetRow(2);
            Assert.AreEqual(CellType.STRING, thirdRow.GetCell(0).CellType);
            String cellValue = thirdRow.GetCell(0).StringCellValue;
            Assert.AreEqual(testData[2][0].ToString(), cellValue);

            Assert.AreEqual(CellType.FORMULA, thirdRow.GetCell(2).CellType);
            Assert.AreEqual("A1+B2", thirdRow.GetCell(2).CellFormula);
        }
コード例 #4
0
ファイル: TestSheetBuilder.cs プロジェクト: xiepeixing/npoi
 public void TestSheetName()
 {
     String sheetName = "TEST SHEET NAME";
     IWorkbook wb = new HSSFWorkbook();
     ISheet sheet = new SheetBuilder(wb, testData).SetSheetName(sheetName).Build();
     Assert.AreEqual(sheetName, sheet.SheetName);
 }
コード例 #5
0
ファイル: TestSheetBuilder.cs プロジェクト: ctddjyds/npoi
        public void TestEmptyCells()
        {
            NPOI.SS.UserModel.IWorkbook wb = new HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet = new SheetBuilder(wb, testData).SetCreateEmptyCells(true).Build();

            NPOI.SS.UserModel.ICell emptyCell = sheet.GetRow(1).GetCell(1);
            Assert.IsNotNull(emptyCell);
            Assert.AreEqual(CellType.BLANK, emptyCell.CellType);
        }
コード例 #6
0
ファイル: TestCellWalk.cs プロジェクト: 89sos98/npoi
        public void TestNotTraverseEmptyCells()
        {
            IWorkbook wb = new HSSFWorkbook();
            ISheet sheet = new SheetBuilder(wb, TestData).Build();
            CellRangeAddress range = CellRangeAddress.ValueOf("A1:C3");

            CellWalk cellWalk = new CellWalk(sheet, range);
            countCellHandler.reset();
            cellWalk.Traverse(countCellHandler);

            Assert.AreEqual(4, countCellHandler.GetVisitedCellsNumber());
            /* 1 + 2 + 5 + 9 */
            Assert.AreEqual(17L, countCellHandler.GetOrdinalNumberSum());
        }