Пример #1
0
        public void TestArraysAndTables()
        {
            HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("testArraysAndTables.xls");

            Record[] sheetRecs = RecordInspector.GetRecords(wb.GetSheetAt(0), 0);

            int countArrayFormulas = verifySharedValues(sheetRecs, typeof(ArrayRecord));

            Assert.AreEqual(5, countArrayFormulas);
            int countTableFormulas = verifySharedValues(sheetRecs, typeof(TableRecord));

            Assert.AreEqual(3, countTableFormulas);

            // Note - SharedFormulaRecords are currently not re-serialized by POI (each is extracted
            // into many non-shared formulas), but if they ever were, the same rules would apply.
            int countSharedFormulas = verifySharedValues(sheetRecs, typeof(SharedFormulaRecord));

            Assert.AreEqual(0, countSharedFormulas);


            //if (false) { // set true to observe re-serialized file
            //    File f = new File(System.getProperty("java.io.tmpdir") + "/testArraysAndTables-out.xls");
            //    try {
            //        OutputStream os = new FileOutputStream(f);
            //        wb.write(os);
            //        os.close();
            //    } catch (IOException e) {
            //        throw new RuntimeException(e);
            //    }
            //    System.Console.WriteLine("Output file to " + f.getAbsolutePath());
            //}

            wb.Close();
        }
        public void TestPartiallyOverlappingRanges()
        {
            Npoi.Core.HSSF.Record.Record[] records;

            int attempt = 1;

            do
            {
                HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook(SAMPLE_FILE_NAME);

                HSSFSheet sheet = (HSSFSheet)wb.GetSheetAt(0);
                RecordInspector.GetRecords(sheet, 0);
                Assert.AreEqual("1+1", sheet.GetRow(2).GetCell(0).CellFormula);
                if ("1+1".Equals(sheet.GetRow(3).GetCell(0).CellFormula))
                {
                    throw new AssertionException("Identified bug - wrong shared formula record chosen"
                                                 + " (attempt " + attempt + ")");
                }
                Assert.AreEqual("2+2", sheet.GetRow(3).GetCell(0).CellFormula);
                records = RecordInspector.GetRecords(sheet, 0);
            } while (attempt++ < MAX_ATTEMPTS);

            int count = 0;

            for (int i = 0; i < records.Length; i++)
            {
                if (records[i] is SharedFormulaRecord)
                {
                    count++;
                }
            }
            Assert.AreEqual(2, count);
        }
        public void TestCompletelyOverlappedRanges()
        {
            Npoi.Core.HSSF.Record.Record[] records;

            int attempt = 1;

            do
            {
                HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook(SAMPLE_FILE_NAME);

                HSSFSheet sheet = (HSSFSheet)wb.GetSheetAt(1);
                try
                {
                    records = RecordInspector.GetRecords(sheet, 0);
                }
                catch (NullReferenceException)
                {
                    throw new AssertionException("Identified bug " +
                                                 "- cannot reserialize completely overlapped shared formula"
                                                 + " (attempt " + attempt + ")");
                }
            } while (attempt++ < MAX_ATTEMPTS);

            int count = 0;

            for (int i = 0; i < records.Length; i++)
            {
                if (records[i] is SharedFormulaRecord)
                {
                    count++;
                }
            }
            Assert.AreEqual(2, count);
        }
Пример #4
0
        /**
         * @return the number of {@link SharedFormulaRecord}s encoded for the specified sheet
         */
        private static int countSharedFormulas(ISheet sheet)
        {
            NPOI.HSSF.Record.Record[] records = RecordInspector.GetRecords(sheet, 0);
            int count = 0;

            for (int i = 0; i < records.Length; i++)
            {
                NPOI.HSSF.Record.Record rec = records[i];
                if (rec is SharedFormulaRecord)
                {
                    count++;
                }
            }
            return(count);
        }
Пример #5
0
        public void TestStartBlock_EndBlock_Write()
        {
            HSSFWorkbook wb = HSSFTestDataSamples.OpenSampleWorkbook("chartdemo.xls");

            Record[] sheetRecs = RecordInspector.GetRecords(wb.GetSheetAt(0), 0);

            RecordStream rs = new RecordStream(sheetRecs.ToList(), 0);

            rs.FindChartSubStream();
            int pos = rs.GetCountRead();

            ChartSheetAggregate csAgg = new ChartSheetAggregate(rs, null);

            RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector();
            csAgg.VisitContainedRecords(rv);
            Record[] outRecs = rv.Records;
            for (int i = 0; i < outRecs.Length; i++)
            {
                Assert.AreEqual(sheetRecs[pos + i].GetType(), outRecs[i].GetType());
            }
        }