コード例 #1
0
        public void TestTableFormulas()
        {
            XSSFWorkbook wb = XSSFTestDataSamples.OpenSampleWorkbook("StructuredReferences.xlsx");

            try
            {
                IFormulaEvaluator eval         = new XSSFFormulaEvaluator(wb);
                XSSFSheet         tableSheet   = wb.GetSheet("Table") as XSSFSheet;
                XSSFSheet         formulaSheet = wb.GetSheet("Formulas") as XSSFSheet;

                Confirm(eval, tableSheet.GetRow(5).GetCell(0), 49);
                Confirm(eval, formulaSheet.GetRow(0).GetCell(0), 209);
                Confirm(eval, formulaSheet.GetRow(1).GetCell(0), "one");

                // test changing a table value, to see if the caches are properly Cleared
                // Issue 59814

                // this test passes before the fix for 59814
                tableSheet.GetRow(1).GetCell(1).SetCellValue("ONEA");
                Confirm(eval, formulaSheet.GetRow(1).GetCell(0), "ONEA");

                // test Adding a row to a table, issue 59814
                IRow newRow = tableSheet.GetRow(7);
                if (newRow == null)
                {
                    newRow = tableSheet.CreateRow(7);
                }
                newRow.CreateCell(0, CellType.Formula).CellFormula = (/*setter*/ "\\_Prime.1[[#This Row],[@Number]]*\\_Prime.1[[#This Row],[@Number]]");
                newRow.CreateCell(1, CellType.String).SetCellValue("thirteen");
                newRow.CreateCell(2, CellType.Numeric).SetCellValue(13);

                // update Table
                XSSFTable     table = wb.GetTable("\\_Prime.1");
                AreaReference newArea = new AreaReference(table.StartCellReference, new CellReference(table.EndRowIndex + 1, table.EndColIndex));
                String        newAreaStr = newArea.FormatAsString();
                table.GetCTTable().@ref = (/*setter*/ newAreaStr);
                table.GetCTTable().autoFilter.@ref = (/*setter*/ newAreaStr);
                table.UpdateHeaders();
                //table.UpdateReferences();

                // these fail before the fix for 59814
                Confirm(eval, tableSheet.GetRow(7).GetCell(0), 13 * 13);
                Confirm(eval, formulaSheet.GetRow(0).GetCell(0), 209 + 13 * 13);
            }
            finally
            {
                wb.Close();
            }
        }
コード例 #2
0
ファイル: TestXSSFTable.cs プロジェクト: zzy092/npoi
        public void TestCTTableStyleInfo()
        {
            XSSFWorkbook outputWorkbook = new XSSFWorkbook();
            XSSFSheet    sheet          = outputWorkbook.CreateSheet() as XSSFSheet;

            //Create
            XSSFTable outputTable = sheet.CreateTable();

            outputTable.DisplayName = ("Test");
            CT_Table outputCTTable = outputTable.GetCTTable();

            //Style configurations
            CT_TableStyleInfo outputStyleInfo = outputCTTable.AddNewTableStyleInfo();

            outputStyleInfo.name = ("TableStyleLight1");
            outputStyleInfo.showColumnStripes = (false);
            outputStyleInfo.showRowStripes    = (true);

            XSSFWorkbook     inputWorkbook = XSSFTestDataSamples.WriteOutAndReadBack(outputWorkbook) as XSSFWorkbook;
            List <XSSFTable> tables        = (inputWorkbook.GetSheetAt(0) as XSSFSheet).GetTables();

            Assert.AreEqual(1, tables.Count, "Tables number");

            XSSFTable inputTable = tables[0];

            Assert.AreEqual(outputTable.DisplayName, inputTable.DisplayName, "Table display name");

            CT_TableStyleInfo inputStyleInfo = inputTable.GetCTTable().tableStyleInfo;

            Assert.AreEqual(outputStyleInfo.name, inputStyleInfo.name, "Style name");
            Assert.AreEqual(outputStyleInfo.showColumnStripes, inputStyleInfo.showColumnStripes, "Show column stripes");
            Assert.AreEqual(outputStyleInfo.showRowStripes, inputStyleInfo.showRowStripes, "Show row stripes");
        }
コード例 #3
0
        public void Test56170()
        {
            IWorkbook wb    = XSSFTestDataSamples.OpenSampleWorkbook("56170.xlsx");
            XSSFSheet sheet = (XSSFSheet)wb.GetSheetAt(0);

            IWorkbook wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            ICell     cell;

            // add some contents to table so that the table will need expansion
            IRow row = sheet.GetRow(0);

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell   = row.CreateCell(0);
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell.SetCellValue("demo1");
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell   = row.CreateCell(1);
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell.SetCellValue("demo2");
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell   = row.CreateCell(2);
            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            cell.SetCellValue("demo3");

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);

            row  = sheet.GetRow(1);
            cell = row.CreateCell(0);
            cell.SetCellValue("demo1");
            cell = row.CreateCell(1);
            cell.SetCellValue("demo2");
            cell = row.CreateCell(2);
            cell.SetCellValue("demo3");

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);

            // expand table
            XSSFTable     table    = sheet.GetTables()[0];
            CellReference startRef = table.StartCellReference;
            CellReference endRef   = table.EndCellReference;

            table.GetCTTable().@ref = (new CellRangeAddress(startRef.Row, 1, startRef.Col, endRef.Col).FormatAsString());

            wbRead = XSSFTestDataSamples.WriteOutAndReadBack(wb);
            Assert.IsNotNull(wbRead);

            /*FileOutputStream stream = new FileOutputStream("c:\\temp\\output.xlsx");
             * workbook.Write(stream);
             * stream.Close();*/
        }
コード例 #4
0
ファイル: TestXSSFTable.cs プロジェクト: zzy092/npoi
        public void GetRowCount()
        {
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sh      = wb.CreateSheet() as XSSFSheet;
            XSSFTable    table   = sh.CreateTable() as XSSFTable;
            CT_Table     ctTable = table.GetCTTable();

            Assert.AreEqual(0, table.RowCount);
            ctTable.@ref = "B2:B2";
            // update cell references to clear the cache
            table.UpdateReferences();
            Assert.AreEqual(1, table.RowCount);
            ctTable.@ref = "B2:B12";
            // update cell references to clear the cache
            table.UpdateReferences();
            Assert.AreEqual(11, table.RowCount);
        }
コード例 #5
0
ファイル: TestXSSFTable.cs プロジェクト: zzy092/npoi
        public void GetCellReferences()
        {
            // make sure that cached start and end cell references
            // can be synchronized with the underlying CTTable
            XSSFWorkbook wb      = new XSSFWorkbook();
            XSSFSheet    sh      = wb.CreateSheet() as XSSFSheet;
            XSSFTable    table   = sh.CreateTable() as XSSFTable;
            CT_Table     ctTable = table.GetCTTable();

            ctTable.@ref = "B2:E8";
            Assert.AreEqual(new CellReference("B2"), table.StartCellReference);
            Assert.AreEqual(new CellReference("E8"), table.EndCellReference);
            // At this point start and end cell reference are cached
            // and may not follow changes to the underlying CTTable
            ctTable.@ref = "C1:M3";
            Assert.AreEqual(new CellReference("B2"), table.StartCellReference);
            Assert.AreEqual(new CellReference("E8"), table.EndCellReference);
            // Force a synchronization between CTTable and XSSFTable
            // start and end cell references
            table.UpdateReferences();
            Assert.AreEqual(new CellReference("C1"), table.StartCellReference);
            Assert.AreEqual(new CellReference("M3"), table.EndCellReference);
        }
コード例 #6
0
        public static void WriteDMToTable(this ISheet sheet, List <DefineSelectItem> lst, string tableName, int numCol)
        {
            if (lst == null || lst.Count == 0)
            {
                return;
            }
            XSSFSheet s   = (XSSFSheet)sheet;
            XSSFTable tbl = s.GetTables().Where(a => a.Name == tableName).FirstOrDefault();

            if (tbl == null)
            {
                return;
            }
            CT_Table ctTBl = tbl.GetCTTable();

            if (numCol < 2 || ctTBl.tableColumns.count < numCol)
            {
                return;
            }
            CellReference cellRefStart = tbl.GetStartCellReference();
            int           rowStart     = cellRefStart.Row + 1;
            short         colStart     = cellRefStart.Col;
            CellReference cellRefEnd   = tbl.GetEndCellReference();
            AreaReference reference    = new AreaReference(cellRefStart, new CellReference(cellRefStart.Row + lst.Count, cellRefEnd.Col));

            ctTBl.insertRow      = true;
            ctTBl.insertRowShift = true;
            ctTBl.@ref           = reference.FormatAsString();
            IRow row = GetCreateRow(sheet, rowStart);

            switch (numCol)
            {
            case 3:
                foreach (DefineSelectItem item in lst)
                {
                    row = GetCreateRow(sheet, rowStart++);

                    row.GetCreateCell(colStart).SetCellValue(item.Value);

                    row.GetCreateCell(colStart + 1).SetCellValue(item.Value2);

                    row.GetCreateCell(colStart + 2).SetCellValue(item.Text);
                }
                break;

            case 4:
                foreach (DefineSelectItem item in lst)
                {
                    row = GetCreateRow(sheet, rowStart++);

                    row.GetCreateCell(colStart).SetCellValue(item.Value);

                    row.GetCreateCell(colStart + 1).SetCellValue(item.Value2);

                    row.GetCreateCell(colStart + 2).SetCellValue(item.Value3);

                    row.GetCreateCell(colStart + 3).SetCellValue(item.Text);
                }
                break;

            case 2:
            default:
                foreach (DefineSelectItem item in lst)
                {
                    row = GetCreateRow(sheet, rowStart++);

                    row.GetCreateCell(colStart).SetCellValue(item.Value);

                    row.GetCreateCell(colStart + 1).SetCellValue(item.Text);
                }
                break;
            }
        }