コード例 #1
0
        /// <summary>Gets the null-based row index of a specific property.
        /// </summary>
        /// <param name="propertyName">The name of the property to search (in the first column).</param>
        /// <param name="rowIndex">The null-based index of the row which contains the property (output).</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="rowIndex"/> contains valid data.
        /// </returns>
        public bool TryGetRowIndexOfPropertyName(string propertyName, out int rowIndex, IExcelDataAdvice dataAdvice = null)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }
            if (m_ExcelCellValue is String)
            {
                string cellValue = (string)m_ExcelCellValue;

                if (propertyName.ToIDString() == cellValue.ToIDString())
                {
                    if (dataAdvice != null)
                    {
                        m_Range.CreateDropdownList(0, 0, dataAdvice.AsExcelDropDownListString());
                    }
                    m_GuidedExcelDataQuery.SetDataAdvice(0, 0, dataAdvice);
                    m_GuidedExcelDataQuery.SetData(0, 0, cellValue);

                    rowIndex = 0;
                    return(true);
                }
            }
            m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName);
            rowIndex = -1;
            return(false);
        }
コード例 #2
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (output).</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if ((rowIndex < m_RowCount) && (rowIndex >= 0) && (columnIndex < m_ColumnCount) && (columnIndex >= 0))
            {
                m_SetOfUsedPropertyIndices.Add(rowIndex);

                if (dataAdvice != null)
                {
                    m_Range.CreateDropdownList(rowIndex, columnIndex, dataAdvice.AsExcelDropDownListString());
                }
                m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                if (ExcelDataConverter.IsEmptyCell(m_Data[rowIndex, columnIndex]) == true)
                {
                    value = default(T);
                    m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                    return(ExcelCellValueState.EmptyOrMissingExcelCell);
                }
                else if (ExcelDataConverter.TryGetCellValue <T>(m_Data[rowIndex, columnIndex], out value) == true)
                {
                    m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                    return(ExcelCellValueState.ProperValue);
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #3
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (output).</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if (typeof(T).IsEnum)
            {
                throw new ArgumentException("The type " + typeof(T).ToString() + " represents a enumeration which is not allowed.", "T");
            }
            if ((rowIndex >= 0) && (rowIndex < m_RowCount))
            {
                if (columnIndex == 0)
                {
                    if (dataAdvice != null)
                    {
                        m_PropertyNames.CreateDropdownList(0, rowIndex, dataAdvice.AsExcelDropDownListString());
                    }
                    m_SetOfUsedPropertyIndices.Add(rowIndex);
                    m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                    if (ExcelDataConverter.IsEmptyCell(m_PropertyNameArray[0, rowIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_PropertyNameArray[0, rowIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
                else if ((columnIndex >= 1) && (columnIndex < m_ColumnCount))
                {
                    if (dataAdvice != null)
                    {
                        m_PropertyValues.CreateDropdownList(columnIndex - 1, rowIndex, dataAdvice.AsExcelDropDownListString());
                    }
                    m_SetOfUsedPropertyIndices.Add(rowIndex);
                    m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                    if (ExcelDataConverter.IsEmptyCell(m_PropertyValueArray[columnIndex - 1, rowIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_PropertyValueArray[columnIndex - 1, rowIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #4
0
        /// <summary>Gets the value of a specific Excel cell.
        /// </summary>
        /// <typeparam name="TEnum">The type of the output which is assumed to be a enumeration.</typeparam>
        /// <param name="inputCell">The input Excel cell.</param>
        /// <param name="value">The value of the Excel cell (output).</param>
        /// <param name="enumStringRepresentationUsage">The method how to compute the <see cref="System.String"/> representation.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="TEnum"/> does not represents a enumeration.</exception>
        private ExcelCellValueState TryGetValue <TEnum>(object inputCell, out TEnum value, EnumStringRepresentationUsage enumStringRepresentationUsage)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            object excelCellValue;

            if (inputCell == null)
            {
                value = default(TEnum);
                return(ExcelCellValueState.NoValidValue);
            }
            else if (inputCell is ExcelReference)
            {
                ExcelReference excelRange = (ExcelReference)inputCell;
                string         valueDropDownListAsString = EnumString <TEnum> .GetValues(enumStringRepresentationUsage).AsExcelDropDownListString();

                excelRange.CreateDropdownList(0, 0, valueDropDownListAsString);

                excelCellValue = excelRange.GetValue();
            }
            else
            {
                excelCellValue = inputCell;
            }

            if (ExcelDataConverter.IsEmptyCell(excelCellValue) == true)
            {
                value = default(TEnum);
                return(ExcelCellValueState.EmptyOrMissingExcelCell);
            }
            return((ExcelDataConverter.TryGetCellValue <TEnum>(excelCellValue, enumStringRepresentationUsage, out value) == true) ? ExcelCellValueState.ProperValue : ExcelCellValueState.NoValidValue);
        }
コード例 #5
0
        /// <summary>Gets the value of a specific Excel cell.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="inputCell">The input Excel cell.</param>
        /// <param name="value">The value of the Excel cell (output).</param>
        /// <param name="valueDropDownListAsString">The optional semicolon separated <see cref="System.String"/> representation of the
        /// possible outcomes with respect to <paramref name="value"/>, i.e. if not <c>null</c> a drop down list will be added to the corresponding Excel cell.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        private ExcelCellValueState TryGetValue <T>(object inputCell, out T value, string valueDropDownListAsString)
        {
            object excelCellValue;

            if (inputCell == null)
            {
                value = default(T);
                return(ExcelCellValueState.NoValidValue);
            }
            else if (inputCell is ExcelReference)
            {
                ExcelReference excelRange = (ExcelReference)inputCell;
                excelRange.CreateDropdownList(0, 0, valueDropDownListAsString);

                excelCellValue = excelRange.GetValue();
            }
            else
            {
                excelCellValue = inputCell;
            }

            if (ExcelDataConverter.IsEmptyCell(excelCellValue) == true)
            {
                value = default(T);
                return(ExcelCellValueState.EmptyOrMissingExcelCell);
            }
            return((ExcelDataConverter.TryGetCellValue <T>(excelCellValue, out value) == true) ? ExcelCellValueState.ProperValue : ExcelCellValueState.NoValidValue);
        }
コード例 #6
0
        /// <summary>Gets the value of a specific Excel cell with respect to specific row and column index.
        /// </summary>
        /// <typeparam name="T">The type of the output.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="value">The value (output).</param>
        /// <param name="dataAdvice">Data advice, i.e. a list of possible outcome, perhaps <c>null</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="T"/> represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <T>(out T value, int rowIndex, int columnIndex, IExcelDataAdvice dataAdvice = null)
        {
            if ((rowIndex < RowCount) && (rowIndex >= 0) && (columnIndex < ColumnCount) && (columnIndex >= 0))
            {
                if (dataAdvice != null)
                {
                    m_HeaderRange.CreateDropdownList(rowIndex, columnIndex, dataAdvice.AsExcelDropDownListString());
                }
                m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, columnIndex, dataAdvice);

                if (rowIndex < m_HeaderRange.RowLast - m_HeaderRange.RowFirst + 1)  // query the header
                {
                    if (ExcelDataConverter.IsEmptyCell(m_HeaderData[rowIndex, columnIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_HeaderData[rowIndex, columnIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
                else  // query below the header
                {
                    int adjRowIndex = rowIndex - (m_HeaderRange.RowLast - m_HeaderRange.RowFirst + 1);
                    if (ExcelDataConverter.IsEmptyCell(m_BelowHeaderData[adjRowIndex, columnIndex]) == true)
                    {
                        value = default(T);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(T));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <T>(m_BelowHeaderData[adjRowIndex, columnIndex], out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
            }
            value = default(T);
            return(ExcelCellValueState.NoValidValue);
        }
コード例 #7
0
        /// <summary>Gets the value of a specific property with respect to a null-based (row or column) index.
        /// </summary>
        /// <typeparam name="TEnum">The type of the output which is assumed to be a enumeration.</typeparam>
        /// <param name="rowIndex">The null-based index of the row.</param>
        /// <param name="columnIndex">The null-based index of the column.</param>
        /// <param name="enumStringRepresentationUsage">The method how to compute the <see cref="System.String"/> representation.</param>
        /// <param name="value">The value (output).</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        /// <exception cref="ArgumentException">Thrown, if <typeparamref name="TEnum"/> does not represents a enumeration.</exception>
        public ExcelCellValueState TryGetValue <TEnum>(EnumStringRepresentationUsage enumStringRepresentationUsage, out TEnum value, int rowIndex, int columnIndex)
            where TEnum : struct, IComparable, IConvertible, IFormattable
        {
            if ((rowIndex < RowCount) && (rowIndex >= 0) && (columnIndex < ColumnCount) && (columnIndex >= 0))
            {
                string valueDropDownListAsString = EnumString <TEnum> .GetValues(enumStringRepresentationUsage).AsExcelDropDownListString();

                if (rowIndex < m_HeaderRange.RowLast - m_HeaderRange.RowFirst + 1)  // query the header
                {
                    m_HeaderRange.CreateDropdownList(rowIndex, columnIndex, valueDropDownListAsString);
                    if (ExcelDataConverter.IsEmptyCell(m_HeaderData[rowIndex, columnIndex]) == true)
                    {
                        value = default(TEnum);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(TEnum));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <TEnum>(m_HeaderData[rowIndex, columnIndex], enumStringRepresentationUsage, out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
                else  // query below the header
                {
                    int adjRowIndex = rowIndex - (m_HeaderRange.RowLast - m_HeaderRange.RowFirst + 1);

                    m_BelowHeaderRange.CreateDropdownList(adjRowIndex, columnIndex, valueDropDownListAsString);
                    if (ExcelDataConverter.IsEmptyCell(m_BelowHeaderData[adjRowIndex, columnIndex]) == true)
                    {
                        value = default(TEnum);
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, typeof(TEnum));
                        return(ExcelCellValueState.EmptyOrMissingExcelCell);
                    }
                    else if (ExcelDataConverter.TryGetCellValue <TEnum>(m_BelowHeaderData[adjRowIndex, columnIndex], enumStringRepresentationUsage, out value) == true)
                    {
                        m_GuidedExcelDataQuery.SetData(rowIndex, columnIndex, value);
                        return(ExcelCellValueState.ProperValue);
                    }
                }
            }
            value = default(TEnum);
            return(ExcelCellValueState.NoValidValue);
        }