Exemplo n.º 1
0
 public void Bug60158()
 {
     try
     {
         FromFile(POIDataSamples.GetDocumentInstance(), "60158.docm");
         POITestCase.TestPassesNow(60158);
     }
     catch (IndexOutOfRangeException e)
     {
         POITestCase.SkipTest(e);
     }
 }
Exemplo n.º 2
0
        public void ShiftWithMergedRegions_bug56454()
        {
            IWorkbook wb    = _testDataProvider.CreateWorkbook();
            ISheet    sheet = wb.CreateSheet();

            // populate sheet cells
            for (int i = 0; i < 10; i++)
            {
                IRow row = sheet.CreateRow(i);

                for (int j = 0; j < 10; j++)
                {
                    ICell cell = row.CreateCell(j, CellType.String);
                    cell.SetCellValue(i + "x" + j);
                }
            }

            CellRangeAddress A4_B7 = CellRangeAddress.ValueOf("A4:B7");
            CellRangeAddress C4_D7 = CellRangeAddress.ValueOf("C4:D7");

            sheet.AddMergedRegion(A4_B7);
            sheet.AddMergedRegion(C4_D7);

            Assume.That(sheet.LastRowNum > 8);

            // Insert a row in the middle of both merged regions.
            sheet.ShiftRows(4, sheet.LastRowNum, 1);

            // all regions should still start at row 3, and elongate by 1 row
            List <CellRangeAddress> expectedMergedRegions = new List <CellRangeAddress>();
            CellRangeAddress        A4_B8 = CellRangeAddress.ValueOf("A4:B8"); //A4:B7 should be elongated by 1 row
            CellRangeAddress        C4_D8 = CellRangeAddress.ValueOf("C4:D8"); //C4:B7 should be elongated by 1 row

            expectedMergedRegions.Add(A4_B8);
            expectedMergedRegions.Add(C4_D8);

            // This test is written as expected-to-fail and should be rewritten
            // as expected-to-pass when the bug is fixed.
            // FIXME: remove try, catch, and testPassesNow, skipTest when test passes
            try
            {
                Assert.AreEqual(expectedMergedRegions, sheet.MergedRegions);
                POITestCase.TestPassesNow(56454);
            }
            catch (AssertionException e)
            {
                POITestCase.SkipTest(e);
            }
            wb.Close();
        }
Exemplo n.º 3
0
        public void ShiftRowsWithMergedRegionsThatDoNotContainColumnZero()
        {
            IWorkbook wb    = _testDataProvider.CreateWorkbook();
            ISheet    sheet = wb.CreateSheet("test");

            // populate sheet cells
            for (int i = 0; i < 10; i++)
            {
                IRow row = sheet.CreateRow(i);
                for (int j = 0; j < 12; j++)
                {
                    ICell cell = row.CreateCell(j);
                    cell.SetCellValue(i + "x" + j);
                }
            }
            CellRangeAddress A4_B7 = new CellRangeAddress(3, 6, 0, 1);
            CellRangeAddress C5_D7 = new CellRangeAddress(4, 6, 2, 3);

            sheet.AddMergedRegion(A4_B7);
            sheet.AddMergedRegion(C5_D7);
            // A4:B7 will elongate vertically
            // C5:D7 will be shifted down with same size
            sheet.ShiftRows(4, sheet.LastRowNum, 1);

            // This test is written as expected-to-fail and should be rewritten
            // as expected-to-pass when the bug is fixed.
            // FIXME: remove try, catch, and testPassesNow, skipTest when test passes
            try
            {
                Assert.AreEqual(2, sheet.NumMergedRegions);
                Assert.AreEqual(CellRangeAddress.ValueOf("A4:B8"), sheet.GetMergedRegion(0));
                Assert.AreEqual(CellRangeAddress.ValueOf("C5:D8"), sheet.GetMergedRegion(1));
                POITestCase.TestPassesNow(56454);
            }
            catch (AssertionException e)
            {
                POITestCase.SkipTest(e);
            }

            wb.Close();
        }
Exemplo n.º 4
0
        public void Bug59733()
        {
            IWorkbook workbook = new XSSFWorkbook();
            ISheet    sheet    = workbook.CreateSheet();

            for (int r = 0; r <= 3; r++)
            {
                sheet.CreateRow(r);
            }
            // Shift the 2nd row on top of the 0th row
            sheet.ShiftRows(2, 2, -2);

            /*
             * The following error is thrown when shifting the 3rd row on top of the 0th row
             * If the rows are not created, the error does not occur
             *
             * org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
             *  at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1258)
             *  at org.Openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl.GetR(Unknown Source)
             *  at org.apache.poi.xssf.usermodel.XSSFRow.GetRowNum(XSSFRow.java:363)
             *  at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2926)
             *  at org.apache.poi.xssf.usermodel.XSSFSheet.shiftRows(XSSFSheet.java:2901)
             *  at org.apache.poi.xssf.usermodel.TestXSSFSheetShiftRows.bug59733(TestXSSFSheetShiftRows.java:393)
             */
            try
            {
                sheet.RemoveRow(sheet.GetRow(0));
                Assert.AreEqual(1, sheet.GetRow(1).RowNum);
                POITestCase.TestPassesNow(59733);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                POITestCase.SkipTest(e);
            }

            workbook.Close();
        }
Exemplo n.º 5
0
 public void Bug59858()
 {
     try
     {
         FromFile(POIDataSamples.GetSpreadSheetInstance(), "59858.xls");
         POITestCase.TestPassesNow(59858);
     }
     catch (IOException e)
     {
         if (Regex.Match(e.Message, "Module offset for '.+' was never Read.").Success)
         {
             //e.PrintStackTrace();
             // NPE when Reading module.offset in VBAMacroReader.ReadMacros (approx line 258)
             POITestCase.SkipTest(e);
         }
         else
         {
             // something unexpected failed
             throw e;
         }
     }
 }
Exemplo n.º 6
0
        public void TestSharedFormulas()
        {
            XSSFWorkbook wb    = XSSFTestDataSamples.OpenSampleWorkbook("TestShiftRowSharedFormula.xlsx");
            XSSFSheet    sheet = wb.GetSheetAt(0) as XSSFSheet;

            Assert.AreEqual("SUM(C2:C4)", getCellFormula(sheet, "C5"));
            Assert.AreEqual("SUM(D2:D4)", getCellFormula(sheet, "D5"));
            Assert.AreEqual("SUM(E2:E4)", getCellFormula(sheet, "E5"));
            sheet.ShiftRows(3, sheet.LastRowNum, 1);
            try
            {
                Assert.AreEqual("SUM(C2:C5)", getCellFormula(sheet, "C6"));
                Assert.AreEqual("SUM(D2:D5)", getCellFormula(sheet, "D6"));
                Assert.AreEqual("SUM(E2:E5)", getCellFormula(sheet, "E6"));
                POITestCase.TestPassesNow(59983);
            }
            catch (AssertionException e)
            {
                POITestCase.SkipTest(e);
            }

            wb.Close();
        }