/// <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"); } string idPropertyName = propertyName.ToIDString(); for (int j = 0; j < m_RowCount; j++) { if (m_Data[j, 0] is String) { string cellName = (string)m_Data[j, 0]; if (cellName.ToIDString() == idPropertyName) { rowIndex = j; if (dataAdvice != null) { ExcelLowLevel.CreateDropdownList(m_Range, rowIndex, 0, dataAdvice.AsExcelDropDownListString()); } m_SetOfUsedPropertyIndices.Add(rowIndex); m_GuidedExcelDataQuery.SetData(rowIndex, 0, cellName); m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, 0, dataAdvice); return(true); } } } m_UnusedOptionalPropertyNames.Add(propertyName); m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName); rowIndex = -1; return(false); }
/// <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); }
/// <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"); } string idPropertyName = propertyName.ToIDString(); for (rowIndex = 0; rowIndex < m_RowCount; rowIndex++) { string tablePropertyName = m_PropertyNameArray[0, rowIndex] as string; if ((tablePropertyName != null) && (tablePropertyName.Length > 0)) { tablePropertyName = tablePropertyName.ToIDString(); if (tablePropertyName == idPropertyName) { m_SetOfUsedPropertyIndices.Add(rowIndex); m_GuidedExcelDataQuery.SetData(rowIndex, 0, propertyName); m_GuidedExcelDataQuery.SetDataAdvice(rowIndex, 0, dataAdvice); return(true); } } } m_UnusedOptionalPropertyNames.Add(propertyName); m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName); rowIndex = -1; return(false); }
/// <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"); } string thisPropertyName; if (TryGetValue <string>(m_PropertyName, out thisPropertyName, (dataAdvice != null) ? dataAdvice.AsExcelDropDownListString() : null) == ExcelCellValueState.ProperValue) { if (propertyName.ToIDString() == thisPropertyName.ToIDString()) { m_GuidedExcelDataQuery.SetData(0, 0, propertyName); m_GuidedExcelDataQuery.SetDataAdvice(0, 0, dataAdvice); rowIndex = 0; return(true); } } m_GuidedExcelDataQuery.AddUnusedPropertyName(propertyName); rowIndex = -1; return(false); }
/// <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); }