コード例 #1
0
ファイル: TestDataSources.cs プロジェクト: zanhaipeng/npoi
        public void TestIobExceptionOnInvalidIndex()
        {
            IWorkbook                 wb            = new HSSFWorkbook();
            ISheet                    sheet         = new SheetBuilder(wb, numericCells).Build();
            CellRangeAddress          rangeAddress  = CellRangeAddress.ValueOf("A2:E2");
            IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, rangeAddress);
            IndexOutOfRangeException  exception     = null;

            try
            {
                numDataSource.GetPointAt(-1);
            }
            catch (IndexOutOfRangeException e)
            {
                exception = e;
            }
            Assert.IsNotNull(exception);

            exception = null;
            try
            {
                numDataSource.GetPointAt(numDataSource.PointCount);
            }
            catch (IndexOutOfRangeException e)
            {
                exception = e;
            }
            Assert.IsNotNull(exception);
        }
コード例 #2
0
ファイル: TestDataSources.cs プロジェクト: zanhaipeng/npoi
 private void AssertDataSourceIsEqualToArray <T>(IChartDataSource <T> ds, T[] array)
 {
     Assert.AreEqual(ds.PointCount, array.Length);
     for (int i = 0; i < array.Length; ++i)
     {
         Assert.AreEqual(ds.GetPointAt(i), array[i]);
     }
 }
コード例 #3
0
ファイル: TestDataSources.cs プロジェクト: zanhaipeng/npoi
        public void TestMixedCellDataSource()
        {
            IWorkbook                 wb             = new HSSFWorkbook();
            ISheet                    sheet          = new SheetBuilder(wb, mixedCells).Build();
            CellRangeAddress          mixedCellRange = CellRangeAddress.ValueOf("A1:F1");
            IChartDataSource <String> strDataSource  = DataSources.FromStringCellRange(sheet, mixedCellRange);
            IChartDataSource <double> numDataSource  = DataSources.FromNumericCellRange(sheet, mixedCellRange);

            for (int i = 0; i < mixedCells[0].Length; ++i)
            {
                if (i % 2 == 0)
                {
                    Assert.IsNull(strDataSource.GetPointAt(i));
                    Assert.AreEqual(((double)mixedCells[0][i]),
                                    numDataSource.GetPointAt(i), 0.00001);
                }
                else
                {
                    Assert.IsNaN(numDataSource.GetPointAt(i));
                    Assert.AreEqual(mixedCells[0][i], strDataSource.GetPointAt(i));
                }
            }
        }
コード例 #4
0
ファイル: TestDataSources.cs プロジェクト: zanhaipeng/npoi
        public void TestStringCellDataSource()
        {
            IWorkbook                 wb            = new HSSFWorkbook();
            ISheet                    sheet         = new SheetBuilder(wb, stringCells).Build();
            CellRangeAddress          numCellRange  = CellRangeAddress.ValueOf("A2:E2");
            IChartDataSource <String> numDataSource = DataSources.FromStringCellRange(sheet, numCellRange);

            Assert.IsTrue(numDataSource.IsReference);
            Assert.IsFalse(numDataSource.IsNumeric);
            Assert.AreEqual(numericCells[0].Length, numDataSource.PointCount);
            for (int i = 0; i < stringCells[1].Length; ++i)
            {
                Assert.AreEqual(stringCells[1][i], numDataSource.GetPointAt(i));
            }
        }
コード例 #5
0
ファイル: TestDataSources.cs プロジェクト: zanhaipeng/npoi
        public void TestNumericCellDataSource()
        {
            IWorkbook                 wb            = new HSSFWorkbook();
            ISheet                    sheet         = new SheetBuilder(wb, numericCells).Build();
            CellRangeAddress          numCellRange  = CellRangeAddress.ValueOf("A2:E2");
            IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, numCellRange);

            Assert.IsTrue(numDataSource.IsReference);
            Assert.IsTrue(numDataSource.IsNumeric);
            Assert.AreEqual(numericCells[0].Length, numDataSource.PointCount);
            for (int i = 0; i < numericCells[0].Length; ++i)
            {
                Assert.AreEqual(((double)numericCells[0][i]) * 2,
                                numDataSource.GetPointAt(i), 0.00001);
            }
        }
コード例 #6
0
        private static void FillNumCache <T>(CT_NumData cache, IChartDataSource <T> dataSource)
        {
            int pointCount = dataSource.PointCount;

            cache.AddNewPtCount().val = (uint)pointCount;
            for (int index = 0; index < pointCount; ++index)
            {
                double d = Convert.ToDouble((object)dataSource.GetPointAt(index));
                if (!double.IsNaN(d))
                {
                    CT_NumVal ctNumVal = cache.AddNewPt();
                    ctNumVal.idx = (uint)index;
                    ctNumVal.v   = d.ToString();
                }
            }
        }
コード例 #7
0
        private static void FillStringCache <T>(CT_StrData cache, IChartDataSource <T> dataSource)
        {
            int pointCount = dataSource.PointCount;

            cache.AddNewPtCount().val = (uint)pointCount;
            for (int index = 0; index < pointCount; ++index)
            {
                object pointAt = (object)dataSource.GetPointAt(index);
                if (pointAt != null)
                {
                    CT_StrVal ctStrVal = cache.AddNewPt();
                    ctStrVal.idx = (uint)index;
                    ctStrVal.v   = pointAt.ToString();
                }
            }
        }
コード例 #8
0
ファイル: XSSFChartUtil.cs プロジェクト: hiodava/Romero
        private static void FillNumCache <T>(CT_NumData cache, IChartDataSource <T> dataSource)
        {
            int numOfPoints = dataSource.PointCount;

            cache.AddNewPtCount().val = (uint)(numOfPoints);
            for (int i = 0; i < numOfPoints; ++i)
            {
                double value = Convert.ToDouble(dataSource.GetPointAt(i));
                if (!double.IsNaN(value))
                {
                    CT_NumVal ctNumVal = cache.AddNewPt();
                    ctNumVal.idx = (uint)(i);
                    ctNumVal.v   = (value.ToString());
                }
            }
        }
コード例 #9
0
ファイル: XSSFChartUtil.cs プロジェクト: hiodava/Romero
        private static void FillStringCache <T>(CT_StrData cache, IChartDataSource <T> dataSource)
        {
            int numOfPoints = dataSource.PointCount;

            cache.AddNewPtCount().val = (uint)(numOfPoints);
            for (int i = 0; i < numOfPoints; ++i)
            {
                object value = dataSource.GetPointAt(i);
                if (value != null)
                {
                    CT_StrVal ctStrVal = cache.AddNewPt();
                    ctStrVal.idx = (uint)(i);
                    ctStrVal.v   = (value.ToString());
                }
            }
        }