Exemplo n.º 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);
            }
        }
Exemplo n.º 2
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
            {
                var values             = new List <object>();
                CellRangeAddress range = new CellRangeAddress(rowNum, rowNum, startCol, startCol + numberOfCols - 1);

                for (var i = startCol; i < numberOfCols; ++i)
                {
                    var cell = mSheet.GetRow(rowNum).GetCell(i, MissingCellPolicy.RETURN_BLANK_AS_NULL);
                    if (range.IsInRange(rowNum, i))
                    {
                        values.Add((cell != null) ? cell.ToString() : null);
                    }
                }

                return(values.ToArray());
            }
        }
Exemplo n.º 3
0
 public void OnCell(ICell cell, ICellWalkContext ctx)
 {
     if (_valuesEnumerator.MoveNext())
     {
         NPOIUtils.SetCellValue(cell, _valuesEnumerator.Current);
     }
     else
     {
         NPOIUtils.SetCellValue(cell, null);
     }
 }
Exemplo n.º 4
0
 public void OnCell(ICell cell, ICellWalkContext ctx)
 {
     _cells.Add(NPOIUtils.GetCellValue(cell));
 }