Пример #1
0
        //static string _ColLetter( int col /* 0 origin */) {
        //	// col = [0...25]
        //	if( col >= 0 && col <= 25 )
        //		return ((char)('A' + col)).ToString();
        //	return "";
        //}
        //static string ColLetter( int col /* 1 Origin */) {
        //	if( col < 1 || col > 256 )
        //		throw new ExcelBadUsageException( "Column out of range; must be between 1 and 256" ); // Excel limits
        //	col--; // make 0 origin
        //	// good up to col ZZ
        //	int col2 = (col / 26) - 1;
        //	int col1 = (col % 26);
        //	return _ColLetter( col2 ) + _ColLetter( col1 );
        //}

        #endregion

        #region "  RowValues  "

        private object[] RowValues(int rowNum, int startCol, int numberOfCols)
        {
            if (mSheet == null)
            {
                return(null);
            }

            if (numberOfCols == 1)
            {
                IRow row = mSheet.GetRow(rowNum);

                ICell cell = HSSFCellUtil.GetCell(row, startCol);
                return(new object[] { NPOIUtils.GetCellValue(cell) });
            }
            else
            {
                CellRangeAddress range = new CellRangeAddress(rowNum, rowNum, startCol, startCol + numberOfCols - 1);

                CellWalk cw = new CellWalk(mSheet, range);
                cw.SetTraverseEmptyCells(true);

                CellExtractor ce = new CellExtractor();

                cw.Traverse(ce);

                return(ce.CellValues);
            }
        }
Пример #2
0
        private void WriteRowValues(object[] values, int rowNum, int startCol)
        {
            if (mSheet == null)
            {
                return;
            }

            var row = mSheet.GetRow(rowNum);

            if (row == null)
            {
                row = mSheet.CreateRow(rowNum);
            }
            for (int i = 0; i <= startCol + values.Length; i++)
            {
                var cell = row.GetCell(i);
                if (cell == null)
                {
                    row.CreateCell(i);
                }
            }

            CellRangeAddress range = new CellRangeAddress(rowNum, rowNum, startCol, startCol + values.Length - 1);

            CellWalk cw = new CellWalk(mSheet, range);

            cw.SetTraverseEmptyCells(true);

            CellInserter ci = new CellInserter(new List <object>(values));

            cw.Traverse(ci);
        }
Пример #3
0
        public void TestNotTraverseEmptyCells()
        {
            IWorkbook        wb    = new HSSFWorkbook();
            ISheet           sheet = new SheetBuilder(wb, TestData).Build();
            CellRangeAddress range = CellRangeAddress.ValueOf("A1:C3");

            CellWalk cellWalk = new CellWalk(sheet, range);

            countCellHandler.reset();
            cellWalk.Traverse(countCellHandler);

            Assert.AreEqual(4, countCellHandler.GetVisitedCellsNumber());
            /* 1 + 2 + 5 + 9 */
            Assert.AreEqual(17L, countCellHandler.GetOrdinalNumberSum());
        }
Пример #4
0
        private void WriteRowValues(object[] values, int rowNum, int startCol)
        {
            if (mSheet == null)
            {
                return;
            }

            CellRangeAddress range = new CellRangeAddress(rowNum, rowNum, startCol, startCol + values.Length - 1);

            CellWalk cw = new CellWalk(mSheet, range);

            cw.SetTraverseEmptyCells(true);

            CellInserter ci = new CellInserter(new List <object>(values));

            cw.Traverse(ci);
        }
Пример #5
0
        private void AddHeaderColumns(int startCol, int rowNum)
        {
            if (ColumnsHeaders.Count != 0)
            {
                if (mSheet == null)
                {
                    return;
                }

                var row = mSheet.GetRow(rowNum);
                if (row == null)
                {
                    row = mSheet.CreateRow(rowNum);
                }
                for (int i = 0; i <= startCol + ColumnsHeaders.ToArray().Length; i++)
                {
                    var cell = row.GetCell(i);
                    if (cell == null)
                    {
                        row.CreateCell(i);
                    }
                }

                CellRangeAddress range = new CellRangeAddress(StartRow == 0
                        ? 0
                        : StartRow, StartRow == 0
                        ? 0
                        : StartRow, startCol, startCol + ColumnsHeaders.ToArray().Length - 1);

                CellWalk cw = new CellWalk(mSheet, range);
                cw.SetTraverseEmptyCells(true);

                CellInserter ci = new CellInserter(new List <object>(ColumnsHeaders));

                cw.Traverse(ci);
            }
        }
Пример #6
0
        /**
         * Builds new numeric cache Container.
         * @param marker data marker to use for cache Evaluation
         * @param ctNumRef parent number reference
         * @return numeric cache instance
         */
        internal static XSSFNumberCache BuildCache(DataMarker marker, CT_NumRef ctNumRef)
        {
            CellRangeAddress range = marker.Range;
            int numOfPoints        = range.NumberOfCells;

            if (numOfPoints == 0)
            {
                // Nothing to do.
                return(null);
            }

            XSSFNumberCache cache = new XSSFNumberCache(ctNumRef.AddNewNumCache());

            cache.SetPointCount(numOfPoints);

            IWorkbook         wb        = marker.Sheet.Workbook;
            IFormulaEvaluator Evaluator = wb.GetCreationHelper().CreateFormulaEvaluator();

            CellWalk            cellWalk        = new CellWalk(marker);
            NumCacheCellHandler numCacheHandler = new NumCacheCellHandler(Evaluator, cache.ctNumData);

            cellWalk.Traverse(numCacheHandler);
            return(cache);
        }