Exemplo n.º 1
0
 /// <summary>Determines whether a specific Excel cell is empty.
 /// </summary>
 /// <param name="rowIndex">The null-based index of the row.</param>
 /// <param name="columnIndex">The null-based index of the column.</param>
 /// <param name="emptyExcelCellMode">The method how to interpret whether a specific Excel cell is empty.</param>
 /// <returns><c>true</c> if the Excel cell at the specific position is empty; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentException">Thrown, if the row/column position is not valid.</exception>
 public bool IsEmptyExcelCell(int rowIndex, int columnIndex, eEmptyExcelCellMode emptyExcelCellMode = eEmptyExcelCellMode.Standard)
 {
     if ((rowIndex < m_Data.Count) && (rowIndex >= 0) && (columnIndex < m_ColumnCount) && (columnIndex >= 0))
     {
         return(IsEmptyExcelCell(m_Data[rowIndex][columnIndex], rowIndex, columnIndex, emptyExcelCellMode));
     }
     throw new ArgumentException("Invalid cell position, row = " + rowIndex + " column = " + columnIndex + ".");
 }
Exemplo n.º 2
0
        /// <summary>Gets the number of non-empty rows.
        /// </summary>
        /// <param name="emptyExcelCellMode">The method how to interpret whether a specific Excel cell is empty.</param>
        /// <returns>The number of non-empty rows.</returns>
        public int GetNonEmptyRowCount(eEmptyExcelCellMode emptyExcelCellMode = eEmptyExcelCellMode.Standard)
        {
            int rowCount = 0;

            for (int j = 0; j < m_Data.Count; j++)
            {
                if (IsEmptyRow(j, emptyExcelCellMode) == false)
                {
                    rowCount++;
                }
            }
            return(rowCount);
        }
Exemplo n.º 3
0
        /// <summary>Determines whether a specific row is empty, i.e. contains <see cref="Type.Missing"/> only.
        /// </summary>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="emptyExcelCellMode">The method how to interpret whether a specific Excel cell is empty.</param>
        /// <returns><c>true</c> if the specified row is empty; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentException">Thrown, if <paramref name="rowIndex"/> does not represents a valid row index.</exception>
        public bool IsEmptyRow(int rowIndex, eEmptyExcelCellMode emptyExcelCellMode = eEmptyExcelCellMode.Standard)
        {
            if ((rowIndex >= 0) && (rowIndex < m_Data.Count))
            {
                object[] row = m_Data[rowIndex];

                int j = 0;
                while (j < m_ColumnCount)
                {
                    object data = row[j];

                    if (IsEmptyExcelCell(data, rowIndex, j, emptyExcelCellMode) == false)
                    {
                        return(false);
                    }
                    j++;
                }
                return(true);
            }
            throw new ArgumentException("Invalid cell position, row = " + rowIndex + ".");
        }
Exemplo n.º 4
0
        /// <summary>Determines whether a specific Excel cell is empty.
        /// </summary>
        /// <param name="excelCellData">The data of the Excel cell.</param>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="emptyExcelCellMode">The method how to interpret whether a specific Excel cell is empty.</param>
        /// <returns><c>true</c> if the Excel cell at the specific position is empty; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentException">Thrown, if the row/column position is not valid.</exception>
        public bool IsEmptyExcelCell(object excelCellData, int rowIndex, int columnIndex, eEmptyExcelCellMode emptyExcelCellMode = eEmptyExcelCellMode.IsNull | eEmptyExcelCellMode.HasMissingType | eEmptyExcelCellMode.IsEmptyExcelCell)
        {
            if (emptyExcelCellMode.HasFlag(eEmptyExcelCellMode.IsNull) && (excelCellData == null))
            {
                return(true);
            }
            else if (emptyExcelCellMode.HasFlag(eEmptyExcelCellMode.HasMissingType) && ((excelCellData == Type.Missing) || (excelCellData is System.Reflection.Missing)))
            {
                return(true);
            }
            else if (emptyExcelCellMode.HasFlag(eEmptyExcelCellMode.IsEmptyExcelCell) && (excelCellData is ExcelEmpty))
            {
                return(true);
            }
            else if (emptyExcelCellMode.HasFlag(eEmptyExcelCellMode.ContainsEmptyString) && (excelCellData is string) && (((string)excelCellData).Length == 0))
            {
                return(true);
            }

            bool isType        = (excelCellData is Type);
            bool hasDataAdvice = m_DataAdvice.ContainsKey(m_ColumnCount * rowIndex + columnIndex);

            if (emptyExcelCellMode.HasFlag(eEmptyExcelCellMode.HasSpecificTypeWithoutAdvice) && isType && (hasDataAdvice == false))
            {
                return(true);
            }
            else if (emptyExcelCellMode.HasFlag(eEmptyExcelCellMode.HasSpecificTypeWithAdvice) && isType && hasDataAdvice)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }