Пример #1
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());
        }
Пример #2
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;
        }
Пример #3
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 );
        }
Пример #4
0
        private object[] RowValues( int rowNum, int startCol, int numberOfCols )
        {
            if( mSheet == null )
                return null;

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

                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;
            }
        }
Пример #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
        private void WriteRowValues(object[] values, int rowNum, int startCol)
        {
            if (mSheet == null)
                return;

            if (ColumnsHeaders.Count != 0)
            {
                rowNum++;
            }
            
            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);
        }