Example #1
0
        /**
         * Use this to create new cells within the row and return it.
         *
         * @param columnIndex - the column number this cell represents
         * @param type - the cell's data type
         * @return XSSFCell a high level representation of the Created cell.
         * @throws ArgumentException if the specified cell type is invalid, columnIndex < 0
         *   or greater than 16384, the maximum number of columns supported by the SpreadsheetML format (.xlsx)
         * @see Cell#CELL_TYPE_BLANK
         * @see Cell#CELL_TYPE_BOOLEAN
         * @see Cell#CELL_TYPE_ERROR
         * @see Cell#CELL_TYPE_FORMULA
         * @see Cell#CELL_TYPE_NUMERIC
         * @see Cell#CELL_TYPE_STRING
         */
        public ICell CreateCell(int columnIndex, CellType type)
        {
            CT_Cell  ctCell;
            XSSFCell prev = _cells.ContainsKey(columnIndex) ? (XSSFCell)_cells[columnIndex] : null;

            if (prev != null)
            {
                ctCell = prev.GetCTCell();
                ctCell.Set(new CT_Cell());
            }
            else
            {
                ctCell = _row.AddNewC();
            }

            int style = _sheet.GetColDefaultStyle(columnIndex);

            if (style >= 0)
            {
                ctCell.s = (uint)style;
            }

            XSSFCell xcell = new XSSFCell(this, ctCell);

            xcell.SetCellNum(columnIndex);
            if (type != CellType.Blank)
            {
                xcell.SetCellType(type);
            }

            _cells[columnIndex] = xcell;
            return(xcell);
        }
        public void TestMultisheetFormulaEval()
        {
            XSSFWorkbook wb = new XSSFWorkbook();

            try
            {
                XSSFSheet sheet1 = wb.CreateSheet("Sheet1") as XSSFSheet;
                XSSFSheet sheet2 = wb.CreateSheet("Sheet2") as XSSFSheet;
                XSSFSheet sheet3 = wb.CreateSheet("Sheet3") as XSSFSheet;

                // sheet1 A1
                XSSFCell cell = sheet1.CreateRow(0).CreateCell(0) as XSSFCell;
                cell.SetCellType(CellType.Numeric);
                cell.SetCellValue(1.0);

                // sheet2 A1
                cell = sheet2.CreateRow(0).CreateCell(0) as XSSFCell;
                cell.SetCellType(CellType.Numeric);
                cell.SetCellValue(1.0);

                // sheet2 B1
                cell = sheet2.GetRow(0).CreateCell(1) as XSSFCell;
                cell.SetCellType(CellType.Numeric);
                cell.SetCellValue(1.0);

                // sheet3 A1
                cell = sheet3.CreateRow(0).CreateCell(0) as XSSFCell;
                cell.SetCellType(CellType.Numeric);
                cell.SetCellValue(1.0);

                // sheet1 A2 formulae
                cell = sheet1.CreateRow(1).CreateCell(0) as XSSFCell;
                cell.SetCellType(CellType.Formula);
                cell.CellFormula = (/*setter*/ "SUM(Sheet1:Sheet3!A1)");

                // sheet1 A3 formulae
                cell = sheet1.CreateRow(2).CreateCell(0) as XSSFCell;
                cell.SetCellType(CellType.Formula);
                cell.CellFormula = (/*setter*/ "SUM(Sheet1:Sheet3!A1:B1)");

                wb.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();

                cell = sheet1.GetRow(1).GetCell(0) as XSSFCell;
                Assert.AreEqual(3.0, cell.NumericCellValue);

                cell = sheet1.GetRow(2).GetCell(0) as XSSFCell;
                Assert.AreEqual(4.0, cell.NumericCellValue);
            }
            finally
            {
                wb.Close();
            }
        }
Example #3
0
        /**
         * Use this to create new cells within the row and return it.
         *
         * @param columnIndex - the column number this cell represents
         * @param type - the cell's data type
         * @return XSSFCell a high level representation of the Created cell.
         * @throws ArgumentException if the specified cell type is invalid, columnIndex < 0
         *   or greater than 16384, the maximum number of columns supported by the SpreadsheetML format (.xlsx)
         * @see Cell#CELL_TYPE_BLANK
         * @see Cell#CELL_TYPE_BOOLEAN
         * @see Cell#CELL_TYPE_ERROR
         * @see Cell#CELL_TYPE_FORMULA
         * @see Cell#CELL_TYPE_NUMERIC
         * @see Cell#CELL_TYPE_STRING
         */
        public ICell CreateCell(int columnIndex, CellType type)
        {
            CT_Cell  ctCell;
            XSSFCell prev = _cells.ContainsKey(columnIndex) ? (XSSFCell)_cells[columnIndex] : null;

            if (prev != null)
            {
                ctCell = prev.GetCTCell();
                ctCell.Set(new CT_Cell());
            }
            else
            {
                ctCell = _row.AddNewC();
            }
            XSSFCell xcell = new XSSFCell(this, ctCell);

            xcell.SetCellNum(columnIndex);
            if (type != CellType.BLANK)
            {
                xcell.SetCellType(type);
            }
            _cells[columnIndex] = xcell;
            return(xcell);
        }
Example #4
0
        public ICell CreateCell(int columnIndex, CellType type)
        {
            XSSFCell xssfCell1 = this._cells.ContainsKey(columnIndex) ? (XSSFCell)this._cells[columnIndex] : (XSSFCell)null;
            CT_Cell  cell;

            if (xssfCell1 != null)
            {
                cell = xssfCell1.GetCTCell();
                cell.Set(new CT_Cell());
            }
            else
            {
                cell = this._row.AddNewC();
            }
            XSSFCell xssfCell2 = new XSSFCell(this, cell);

            xssfCell2.SetCellNum(columnIndex);
            if (type != CellType.BLANK)
            {
                xssfCell2.SetCellType(type);
            }
            this._cells[columnIndex] = (ICell)xssfCell2;
            return((ICell)xssfCell2);
        }