Пример #1
0
        public Object GetRowFromValue(Xls.TableCodes tableCode, String colName, Object value)
        {
            if (value == null || String.IsNullOrEmpty(colName))
            {
                return(null);
            }

            ExcelFile excelTable = GetExcelTableFromCode(tableCode);

            if (excelTable == null)
            {
                return(null);
            }

            ObjectDelegator tableDelegate = DataFileDelegators[excelTable.StringId];

            ObjectDelegator.FieldDelegate fieldDelegate = tableDelegate.GetFieldDelegate(colName);
            if (fieldDelegate == null)
            {
                return(null);
            }

            foreach (Object row in excelTable.Rows)
            {
                if (value.Equals(fieldDelegate.GetValue(row)))
                {
                    return(row);
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Gets the RowIndex of a row containing a string, using the column name to search by.
        /// Returns -2 on error, -1 on not found
        /// </summary>
        /// <param name="stringId">An Excel Table StringId.</param>
        /// <param name="value">The value to search for.</param>
        /// <param name="colName">The column name to check.</param>
        /// <returns>Row index string found in column colName. (-2=error, -1=not found)</returns>
        public int GetExcelRowIndexFromStringId(String stringId, String value, String colName)
        {
            if (DataFiles == null || String.IsNullOrEmpty(stringId) || DataFiles.ContainsKey(stringId) == false)
            {
                return(-2);
            }

            ExcelFile excelTable = DataFiles[stringId] as ExcelFile;

            if (excelTable == null)
            {
                return(-2);
            }

            ObjectDelegator excelDelegator = DataFileDelegators[stringId];

            ObjectDelegator.FieldDelegate fieldDelegate = excelDelegator.GetFieldDelegate(colName);
            if (fieldDelegate == null)
            {
                return(-2);
            }

            bool isStringField = (fieldDelegate.FieldType == typeof(String));
            int  rowIndex      = -1;

            foreach (Object row in excelTable.Rows)
            {
                rowIndex++;

                if (isStringField)
                {
                    if ((String)fieldDelegate.GetValue(row) == value)
                    {
                        return(rowIndex);
                    }
                }
                else
                {
                    int offset = (int)fieldDelegate.GetValue(row);
                    if (excelTable.ReadStringTable(offset) == value)
                    {
                        return(rowIndex);
                    }
                }
            }

            return(-1);
        }
Пример #3
0
        /// <summary>
        /// Obtains a String value from an excel table using a StringId, column name, and row index.
        /// Returns null on fail
        /// </summary>
        /// <param name="stringId">An Excel Table StringId.</param>
        /// <param name="rowIndex">The row index to obtain the value from.</param>
        /// <param name="colName">The column name to check.</param>
        /// <returns></returns>
        public String GetExcelStringFromStringId(String stringId, int rowIndex, String colName)
        {
            if (DataFiles == null || String.IsNullOrEmpty(stringId) || DataFiles.ContainsKey(stringId) == false)
            {
                return(null);
            }

            ExcelFile excelTable = DataFiles[stringId] as ExcelFile;

            if (excelTable == null)
            {
                return(null);
            }
            if (rowIndex < 0 || rowIndex >= excelTable.Rows.Count)
            {
                return(null);
            }

            ObjectDelegator excelDelegator = DataFileDelegators[stringId];

            ObjectDelegator.FieldDelegate fieldDelegate = excelDelegator.GetFieldDelegate(colName);
            if (fieldDelegate == null)
            {
                return(null);
            }

            bool   isStringField = (fieldDelegate.FieldType == typeof(String));
            Object row           = excelTable.Rows[rowIndex];

            if (isStringField)
            {
                return((String)fieldDelegate.GetValue(row));
            }

            int    offset    = (int)fieldDelegate.GetValue(row);
            String stringVal = excelTable.ReadStringTable(offset);

            return(stringVal);
        }
Пример #4
0
        private String _GetExcelStringFromExcelFile(ExcelFile excelTable, int rowIndex, int colIndex)
        {
            if (excelTable == null || rowIndex >= excelTable.Rows.Count)
            {
                return(null);
            }

            ObjectDelegator tableDelegator = DataFileDelegators[excelTable.StringId];

            ObjectDelegator.FieldDelegate fieldDelegate = tableDelegator.GetPublicFieldDelegate(colIndex);

            bool   isStringField = (fieldDelegate.FieldType == typeof(String));
            Object row           = excelTable.Rows[rowIndex];

            if (isStringField)
            {
                return((String)fieldDelegate.GetValue(row));
            }

            int    offset    = (int)fieldDelegate.GetValue(row);
            String stringVal = excelTable.ReadStringTable(offset);

            return(stringVal);
        }
Пример #5
0
 public XmlCookedElement(XmlCookedAttribute xmlAttribute, ObjectDelegator.FieldDelegate fieldDelegate)
 {
     XmlAttribute  = xmlAttribute;
     FieldDelegate = fieldDelegate;
 }