/// <summary> /// Retrieves an Excel Table from its Code value. If it's not loaded, then it will be loaded and returned. /// </summary> /// <param name="code">The code of the Excel Table to retrieve.</param> /// <returns>The Excel Table as a DataTable, or null if not found.</returns> public ExcelFile GetExcelTableFromCode(Xls.TableCodes code) { if (DataFiles == null || DataFiles.ContainsKey(ExcelTablesStringId) == false || code == Xls.TableCodes.Null) { return(null); } if (_excelCodeToTable == null) { ExcelFile excelTables = (ExcelFile)DataFiles[ExcelTablesStringId]; _excelCodeToTable = new Dictionary <Xls.TableCodes, ExcelFile>(); foreach (ExcelTablesRow excelTablesRow in excelTables.Rows) { DataFile dataFile; if (DataFiles.TryGetValue(excelTablesRow.name, out dataFile)) { _excelCodeToTable[(Xls.TableCodes)excelTablesRow.code] = (ExcelFile)dataFile; } } } ExcelFile excelTable; return(_excelCodeToTable.TryGetValue(code, out excelTable) ? excelTable : null); }
internal void AddDataFile(DataFile df) { if (!DataFiles.ContainsKey(df.Name)) { DataFiles.Add(df.Name, df); } }
/// <summary> /// Obtains an int value from an excel table using a StringId, column name, and row index. /// Returns 0x4C494146 on fail (will output as '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 int GetExcelIntFromStringId(String stringId, int rowIndex, String colName) { if (DataFiles == null || String.IsNullOrEmpty(stringId) || DataFiles.ContainsKey(stringId) == false) { return(0x4C494146); } ExcelFile excelTable = DataFiles[stringId] as ExcelFile; if (excelTable == null) { return(0x4C494146); } if (rowIndex < 0 || rowIndex >= excelTable.Rows.Count) { return(0x4C494146); } ObjectDelegator excelDelegator = DataFileDelegators[stringId]; Object row = excelTable.Rows[rowIndex]; Object value = excelDelegator[colName](row); if (value is int) { return((int)value); } return((int)(short)value); }
public void AddDataFile(string fileName, string fileColmumn, Variable variable, string value) { //me fijo si ya exite el arcihvo if (!DataFiles.ContainsKey(fileName)) { DataFiles.Add(fileName, new DataFile(fileName)); } DataFiles[fileName].AddColumn(fileColmumn, variable, value); }
/// <summary> /// Checks if a data table has a specified column name. /// </summary> /// <param name="stringId">The StringId of the data table to check.</param> /// <param name="colName">The column name to check for.</param> /// <returns>True if the table has the column.</returns> public bool DataTableHasColumn(String stringId, String colName) { if (DataFiles == null || !DataFiles.ContainsKey(stringId)) { return(false); } ObjectDelegator objectDelegator = DataFileDelegators[stringId]; return(objectDelegator.ContainsGetFieldDelegate(colName)); }
public String GetExcelStringFromRowIndex(Xls.TableCodes code, int rowIndex, int colIndex = 0) { if (DataFiles == null || DataFiles.ContainsKey(ExcelTablesStringId) == false || rowIndex < 0) { return(null); } ExcelFile excelTable = GetExcelTableFromCode(code); String stringVal = _GetExcelStringFromExcelFile(excelTable, rowIndex, colIndex); return(stringVal); }
/// <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); }
public String GetExcelStringFromStringId(String stringId, int rowIndex, int colIndex = 0) { if (DataFiles == null || String.IsNullOrEmpty(stringId) || DataFiles.ContainsKey(stringId) == false) { return(null); } ExcelFile excelTable = DataFiles[stringId] as ExcelFile; if (excelTable == null) { return(null); } String stringVal = _GetExcelStringFromExcelFile(excelTable, rowIndex, colIndex); return(stringVal); }
public int GetExcelRowIndexFromStringId(String stringId, int value, String colName) { if (DataFiles == null || String.IsNullOrEmpty(stringId) || DataFiles.ContainsKey(stringId) == false) { return(-1); } ExcelFile excelFile = (ExcelFile)DataFiles[stringId]; ObjectDelegator excelDelegator = DataFileDelegators[stringId]; ObjectDelegator.FieldGetValueDelegate getValue = excelDelegator[colName]; int rowIndex = -1; bool foundRow = false; foreach (Object row in excelFile.Rows) { rowIndex++; int intVal; Object val = getValue(row); if (val is short) { intVal = (int)(short)val; } else { intVal = (int)val; } if (intVal != value) { continue; } foundRow = true; break; } return((foundRow) ? rowIndex : -1); }
/// <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); }