Esempio n. 1
0
        public void TestGetOrCreateColumn()
        {
            XSSFWorkbook workbook     = new XSSFWorkbook();
            XSSFSheet    sheet        = (XSSFSheet)workbook.CreateSheet("Sheet 1");
            ColumnHelper columnHelper = sheet.GetColumnHelper();

            // Check POI 0 based, OOXML 1 based
            CT_Col col = columnHelper.GetOrCreateColumn1Based(3, false);

            Assert.IsNotNull(col);
            Assert.IsNull(columnHelper.GetColumn(1, false));
            Assert.IsNotNull(columnHelper.GetColumn(2, false));
            Assert.IsNotNull(columnHelper.GetColumn1Based(3, false));
            Assert.IsNull(columnHelper.GetColumn(3, false));

            CT_Col col2 = columnHelper.GetOrCreateColumn1Based(30, false);

            Assert.IsNotNull(col2);
            Assert.IsNull(columnHelper.GetColumn(28, false));
            Assert.IsNotNull(columnHelper.GetColumn(29, false));
            Assert.IsNotNull(columnHelper.GetColumn1Based(30, false));
            Assert.IsNull(columnHelper.GetColumn(30, false));
        }
Esempio n. 2
0
        public void TestGetSetColDefaultStyle()
        {
            XSSFWorkbook workbook     = new XSSFWorkbook();
            XSSFSheet    sheet        = (XSSFSheet)workbook.CreateSheet();
            CT_Worksheet ctWorksheet  = sheet.GetCTWorksheet();
            ColumnHelper columnHelper = sheet.GetColumnHelper();

            // POI column 3, OOXML column 4
            CT_Col col = columnHelper.GetOrCreateColumn1Based(4, false);

            Assert.IsNotNull(col);
            Assert.IsNotNull(columnHelper.GetColumn(3, false));
            columnHelper.SetColDefaultStyle(3, 2);
            Assert.AreEqual(2, columnHelper.GetColDefaultStyle(3));
            Assert.AreEqual(-1, columnHelper.GetColDefaultStyle(4));
            StylesTable stylesTable = workbook.GetStylesSource();
            CT_Xf       cellXf      = new CT_Xf();

            cellXf.fontId   = (0);
            cellXf.fillId   = (0);
            cellXf.borderId = (0);
            cellXf.numFmtId = (0);
            cellXf.xfId     = (0);
            stylesTable.PutCellXf(cellXf);
            CT_Col col_2 = ctWorksheet.GetColsArray(0).AddNewCol();

            col_2.min            = (10);
            col_2.max            = (12);
            col_2.style          = (1);
            col_2.styleSpecified = true;
            Assert.AreEqual(1, columnHelper.GetColDefaultStyle(11));
            XSSFCellStyle cellStyle = new XSSFCellStyle(0, 0, stylesTable, null);

            columnHelper.SetColDefaultStyle(11, cellStyle);
            Assert.AreEqual(0u, col_2.style);
            Assert.AreEqual(1, columnHelper.GetColDefaultStyle(10));
        }