Ejemplo n.º 1
0
        private string SafeGetColumn(IExcelRow row, int columnIndex)
        {
            if (row == null)
            {
                return(string.Empty);
            }
            IExcelCell cell = row.GetCell(columnIndex);

            if (cell != null && cell.value != null)
            {
                return(cell.value);
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        public void CompareCells(int columnCount, IExcelSheet left, IExcelSheet right)
        {
            _isDifferent = false;
            _cellStatus  = new bool[columnCount];
            IExcelRow leftRow  = left.GetRow(_leftRowIndex);
            IExcelRow rightRow = right.GetRow(_rightRowIndex);

            if (leftRow == null || rightRow == null)
            {
                for (int i = 0; i < columnCount; i++)
                {
                    _cellStatus[i] = true;
                }
            }
            else
            {
                for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
                {
                    IExcelCell selfCell  = leftRow.GetCell(columnIndex);
                    IExcelCell otherCell = rightRow.GetCell(columnIndex);
                    if ((selfCell == null && otherCell != null) || (selfCell != null && otherCell == null))
                    {
                        _cellStatus[columnIndex] = true;
                    }
                    else
                    {
                        if (selfCell == null && otherCell == null)
                        {
                            _cellStatus[columnIndex] = false;
                        }
                        else
                        {
                            _cellStatus[columnIndex] = string.Compare(selfCell.GetContent(), otherCell.GetContent()) != 0;
                        }
                    }
                }
            }

            for (int i = 0; i < _cellStatus.Length; i++)
            {
                if (_cellStatus[i])
                {
                    _isDifferent = true;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public VRow(VSheet sheet, int rowIndex, IExcelRow referenceRow)
        {
            _sheet    = sheet;
            _rowIndex = rowIndex;

            if (referenceRow != null)
            {
                if (referenceRow is VRow)
                {
                    VRow row = referenceRow as VRow;
                    _realRowIndex   = row.realRowIndex;
                    _targetRowIndex = row.targetRowIndex;
                }
                else
                {
                    ExcelRow row = referenceRow as ExcelRow;
                    _realRowIndex = rowIndex;
                }

                for (int columnIndex = 0; columnIndex < sheet.columnCount; columnIndex++)
                {
                    IExcelCell cell    = referenceRow.GetCell(columnIndex);
                    IExcelCell newCell = null;
                    if (cell == null)
                    {
                        newCell = new ExcelCell(_rowIndex, columnIndex);
                    }
                    else
                    {
                        newCell = new ExcelCell(_rowIndex, columnIndex, cell.cellType, cell.value);
                    }

                    _columns.Add(newCell);
                }
            }
            else
            {
                _realRowIndex = -1;
                for (int columnIndex = 0; columnIndex < sheet.columnCount; columnIndex++)
                {
                    _columns.Add(new ExcelCell(_rowIndex, columnIndex));
                }
            }
        }
Ejemplo n.º 4
0
        public DataTable GetSource()
        {
            DataTable dt = new DataTable();

            for (int j = 0; j < _columnCount; j++)
            {
                dt.Columns.Add(new DataColumn(CellReference.ConvertNumToColString(j)));
            }

            DataRow dr = null;

            for (int i = 0; i < rowCount; i++)
            {
                dr = dt.NewRow();
                IExcelRow row = _rows[i];
                for (int k = 0; k < _columnCount; k++)
                {
                    if (k < columnCount && row != null)
                    {
                        string displayText = row.GetCell(k).value;
                        if (displayText == null)
                        {
                            displayText = string.Empty;
                        }
                        dr[k] = displayText;
                    }
                    else
                    {
                        dr[k] = string.Empty;
                    }
                }

                dt.Rows.Add(dr);
            }
            return(dt);
        }