Exemplo n.º 1
0
        public void IfGivenTheIndexOfAnExistingSheetShouldReturnTheSheet()
        {
            _objectToTest = new SXSSFWorkbook();
            _objectToTest.CreateSheet("1");
            _objectToTest.CreateSheet("2");

            var sheet1 = _objectToTest.GetSheetAt(0);
            var sheet2 = _objectToTest.GetSheetAt(1);

            Assert.AreEqual("1", sheet1.SheetName);
            Assert.AreEqual("2", sheet2.SheetName);
        }
Exemplo n.º 2
0
        public void OverrideRowsInTemplate()
        {
            XSSFWorkbook template = new XSSFWorkbook();

            template.CreateSheet().CreateRow(1);

            IWorkbook wb = new SXSSFWorkbook(template);

            try {
                ISheet sheet = wb.GetSheetAt(0);

                try {
                    sheet.CreateRow(1);
                    Assert.Fail("expected exception");
                } catch (Exception e) {
                    Assert.AreEqual("Attempting to write a row[1] in the range [0,1] that is already written to disk.", e.Message);
                }
                try {
                    sheet.CreateRow(0);
                    Assert.Fail("expected exception");
                } catch (Exception e) {
                    Assert.AreEqual("Attempting to write a row[0] in the range [0,1] that is already written to disk.", e.Message);
                }
                sheet.CreateRow(2);
            } finally {
                wb.Close();
                template.Close();
            }
        }
Exemplo n.º 3
0
        public void IfSettingSheetNameShouldChangeTheSheetNameAtTheSpecifiedIndex()
        {
            _objectToTest = new SXSSFWorkbook();
            _objectToTest.CreateSheet("test1");
            _objectToTest.SetSheetName(0, "renamed");

            Assert.AreEqual("renamed", _objectToTest.GetSheetAt(0).SheetName);
        }
Exemplo n.º 4
0
        public void IfSheetNameByIndexShouldGetSheetNameFromXssfWorkbook()
        {
            _objectToTest = new SXSSFWorkbook();
            _objectToTest.CreateSheet("test1");
            _objectToTest.CreateSheet("test2");

            _objectToTest.SetSelectedTab(0);

            Assert.IsTrue(_objectToTest.GetSheetAt(0).IsSelected);
        }
Exemplo n.º 5
0
        public void IfSettingSelectedTabShouldSetSelectedTabOfXssfWorkbook()
        {
            _objectToTest = new SXSSFWorkbook();
            _objectToTest.CreateSheet("test1");
            _objectToTest.CreateSheet("test2");

            _objectToTest.SetSelectedTab(0);

            Assert.IsTrue(_objectToTest.GetSheetAt(0).IsSelected);
        }
Exemplo n.º 6
0
        public void IfGivenThePositionOfAnExistingSheetShouldRemoveThatSheet()
        {
            _objectToTest = new SXSSFWorkbook();
            _objectToTest.CreateSheet("1");
            _objectToTest.CreateSheet("2");

            _objectToTest.RemoveSheetAt(0);
            var sheet = _objectToTest.GetSheetAt(0);

            Assert.IsTrue(_objectToTest.NumberOfSheets == 1);
            Assert.AreEqual("2", sheet.SheetName);
        }
Exemplo n.º 7
0
        public void ExistingWorkbook()
        {
            XSSFWorkbook xssfWb1 = new XSSFWorkbook();

            xssfWb1.CreateSheet("S1");
            SXSSFWorkbook wb1     = new SXSSFWorkbook(xssfWb1);
            XSSFWorkbook  xssfWb2 = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb1) as XSSFWorkbook;

            Assert.IsTrue(wb1.Dispose());

            SXSSFWorkbook wb2 = new SXSSFWorkbook(xssfWb2);

            Assert.AreEqual(1, wb2.NumberOfSheets);
            ISheet sheet = wb2.GetSheetAt(0);

            Assert.IsNotNull(sheet);
            Assert.AreEqual("S1", sheet.SheetName);
            Assert.IsTrue(wb2.Dispose());
            xssfWb2.Close();
            xssfWb1.Close();

            wb2.Close();
            wb1.Close();
        }
Exemplo n.º 8
0
        public void AddToExistingWorkbook()
        {
            XSSFWorkbook xssfWb1 = new XSSFWorkbook();

            xssfWb1.CreateSheet("S1");
            ISheet sheet = xssfWb1.CreateSheet("S2");
            IRow   row   = sheet.CreateRow(1);
            ICell  cell  = row.CreateCell(1);

            cell.SetCellValue("value 2_1_1");
            SXSSFWorkbook wb1     = new SXSSFWorkbook(xssfWb1);
            XSSFWorkbook  xssfWb2 = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb1) as XSSFWorkbook;

            Assert.IsTrue(wb1.Dispose());
            xssfWb1.Close();

            SXSSFWorkbook wb2 = new SXSSFWorkbook(xssfWb2);
            // Add a row to the existing empty sheet
            ISheet sheet1    = wb2.GetSheetAt(0);
            IRow   row1_1    = sheet1.CreateRow(1);
            ICell  cell1_1_1 = row1_1.CreateCell(1);

            cell1_1_1.SetCellValue("value 1_1_1");

            // Add a row to the existing non-empty sheet
            ISheet sheet2    = wb2.GetSheetAt(1);
            IRow   row2_2    = sheet2.CreateRow(2);
            ICell  cell2_2_1 = row2_2.CreateCell(1);

            cell2_2_1.SetCellValue("value 2_2_1");

            // Add a sheet with one row
            ISheet sheet3    = wb2.CreateSheet("S3");
            IRow   row3_1    = sheet3.CreateRow(1);
            ICell  cell3_1_1 = row3_1.CreateCell(1);

            cell3_1_1.SetCellValue("value 3_1_1");

            XSSFWorkbook xssfWb3 = SXSSFITestDataProvider.instance.WriteOutAndReadBack(wb2) as XSSFWorkbook;

            wb2.Close();

            Assert.AreEqual(3, xssfWb3.NumberOfSheets);
            // Verify sheet 1
            sheet1 = xssfWb3.GetSheetAt(0);
            Assert.AreEqual("S1", sheet1.SheetName);
            Assert.AreEqual(1, sheet1.PhysicalNumberOfRows);
            row1_1 = sheet1.GetRow(1);
            Assert.IsNotNull(row1_1);
            cell1_1_1 = row1_1.GetCell(1);
            Assert.IsNotNull(cell1_1_1);
            Assert.AreEqual("value 1_1_1", cell1_1_1.StringCellValue);
            // Verify sheet 2
            sheet2 = xssfWb3.GetSheetAt(1);
            Assert.AreEqual("S2", sheet2.SheetName);
            Assert.AreEqual(2, sheet2.PhysicalNumberOfRows);
            IRow row2_1 = sheet2.GetRow(1);

            Assert.IsNotNull(row2_1);
            ICell cell2_1_1 = row2_1.GetCell(1);

            Assert.IsNotNull(cell2_1_1);
            Assert.AreEqual("value 2_1_1", cell2_1_1.StringCellValue);
            row2_2 = sheet2.GetRow(2);
            Assert.IsNotNull(row2_2);
            cell2_2_1 = row2_2.GetCell(1);
            Assert.IsNotNull(cell2_2_1);
            Assert.AreEqual("value 2_2_1", cell2_2_1.StringCellValue);
            // Verify sheet 3
            sheet3 = xssfWb3.GetSheetAt(2);
            Assert.AreEqual("S3", sheet3.SheetName);
            Assert.AreEqual(1, sheet3.PhysicalNumberOfRows);
            row3_1 = sheet3.GetRow(1);
            Assert.IsNotNull(row3_1);
            cell3_1_1 = row3_1.GetCell(1);
            Assert.IsNotNull(cell3_1_1);
            Assert.AreEqual("value 3_1_1", cell3_1_1.StringCellValue);

            xssfWb2.Close();
            xssfWb3.Close();
            wb1.Close();
        }