Elin Decompiled Documentation EA 23.316 Nightly
Loading...
Searching...
No Matches
ExcelParser Class Reference

Static Public Member Functions

static bool IsNull (ICell cell)
 
static int GetInt (int id)
 
static int GetInt (int col, IRow _row)
 
static bool GetBool (int id)
 
static bool GetBool (int col, IRow _row)
 
static double GetDouble (int id)
 
static float GetFloat (int id)
 
static float[] GetFloatArray (int id)
 
static int[] GetIntArray (int id)
 
static string[] GetStringArray (int id)
 
static string GetString (int id)
 
static string GetString (int col, IRow _row)
 
static string GetStr (int id, bool useDefault=false)
 
static string ToLetterId (int id)
 
static void ReportIllFormat< T > (int id)
 
static string GetRowHeaderDiff (IReadOnlyDictionary< string, int > mapping, IReadOnlyDictionary< string, int > header)
 
static void ClearStaticRows ()
 

Static Public Attributes

static string path
 
static IRow row
 
static IRow rowDefault
 
static IRow rowHeader
 
static bool allowTrimming
 

Detailed Description

Definition at line 8 of file ExcelParser.cs.

Member Function Documentation

◆ ClearStaticRows()

static void ExcelParser.ClearStaticRows ( )
inlinestatic

Definition at line 264 of file ExcelParser.cs.

265 {
266 row = null;
267 rowDefault = null;
268 rowHeader = null;
269 allowTrimming = false;
270 }
static IRow rowDefault
Definition: ExcelParser.cs:14
static IRow row
Definition: ExcelParser.cs:12
static bool allowTrimming
Definition: ExcelParser.cs:18
static IRow rowHeader
Definition: ExcelParser.cs:16

References allowTrimming, row, rowDefault, and rowHeader.

◆ GetBool() [1/2]

static bool ExcelParser.GetBool ( int  col,
IRow  _row 
)
inlinestatic

Definition at line 66 of file ExcelParser.cs.

67 {
68 row = _row;
69 return GetBool(col);
70 }
static bool GetBool(int id)
Definition: ExcelParser.cs:53

References GetBool(), and row.

◆ GetBool() [2/2]

static bool ExcelParser.GetBool ( int  id)
inlinestatic

Definition at line 53 of file ExcelParser.cs.

54 {
55 string str = GetStr(id);
56 bool result;
57 return str switch
58 {
59 null => false,
60 "1" => true,
61 "0" => false,
62 _ => bool.TryParse(str, out result) && result,
63 };
64 }
static string GetStr(int id, bool useDefault=false)
Definition: ExcelParser.cs:171

References GetStr().

Referenced by GetBool(), SourceData< T, T2 >.GetBool(), and TextConv.Item.Item().

◆ GetDouble()

static double ExcelParser.GetDouble ( int  id)
inlinestatic

Definition at line 72 of file ExcelParser.cs.

73 {
74 string str = GetStr(id);
75 if (str.IsEmpty())
76 {
77 return 0.0;
78 }
79 if (!double.TryParse(str, out var result))
80 {
81 ReportIllFormat<double>(id);
82 }
83 return result;
84 }

References GetStr().

Referenced by SourceData< T, T2 >.GetDouble().

◆ GetFloat()

static float ExcelParser.GetFloat ( int  id)
inlinestatic

Definition at line 86 of file ExcelParser.cs.

87 {
88 string str = GetStr(id);
89 if (str.IsEmpty())
90 {
91 return 0f;
92 }
93 if (!float.TryParse(str, out var result))
94 {
95 ReportIllFormat<float>(id);
96 }
97 return result;
98 }

References GetStr().

Referenced by SourceData< T, T2 >.GetFloat().

◆ GetFloatArray()

static float[] ExcelParser.GetFloatArray ( int  id)
inlinestatic

Definition at line 100 of file ExcelParser.cs.

101 {
102 string str = GetStr(id);
103 if (str.IsEmpty())
104 {
105 return Array.Empty<float>();
106 }
107 string[] array = str.Split(',');
108 float[] array2 = new float[array.Length];
109 for (int i = 0; i < array.Length; i++)
110 {
111 if (!float.TryParse(array[i], out array2[i]))
112 {
113 ReportIllFormat<float>(id);
114 array2[i] = 0f;
115 }
116 }
117 return array2;
118 }

References GetStr().

Referenced by SourceData< T, T2 >.GetFloatArray().

◆ GetInt() [1/2]

static int ExcelParser.GetInt ( int  col,
IRow  _row 
)
inlinestatic

Definition at line 47 of file ExcelParser.cs.

48 {
49 row = _row;
50 return GetInt(col);
51 }
static int GetInt(int id)
Definition: ExcelParser.cs:29

References GetInt(), and row.

◆ GetInt() [2/2]

static int ExcelParser.GetInt ( int  id)
inlinestatic

Definition at line 29 of file ExcelParser.cs.

30 {
31 string str = GetStr(id);
32 if (str.IsEmpty())
33 {
34 return 0;
35 }
36 if (!int.TryParse(str, out var result))
37 {
38 if (float.TryParse(str, out var result2))
39 {
40 return (int)result2;
41 }
42 ReportIllFormat<int>(id);
43 }
44 return result;
45 }

References GetStr().

Referenced by TextConv.BuildMap(), GetInt(), and SourceData< T, T2 >.GetInt().

◆ GetIntArray()

static int[] ExcelParser.GetIntArray ( int  id)
inlinestatic

Definition at line 120 of file ExcelParser.cs.

121 {
122 string str = GetStr(id);
123 if (str.IsEmpty())
124 {
125 return Array.Empty<int>();
126 }
127 string[] array = str.Split(',');
128 int[] array2 = new int[array.Length];
129 for (int i = 0; i < array.Length; i++)
130 {
131 if (!int.TryParse(array[i], out array2[i]))
132 {
133 if (float.TryParse(array[i], out var result))
134 {
135 array2[i] = (int)result;
136 continue;
137 }
138 ReportIllFormat<int>(id);
139 array2[i] = 0;
140 }
141 }
142 return array2;
143 }

References GetStr().

Referenced by SourceData< T, T2 >.GetIntArray().

◆ GetRowHeaderDiff()

static string ExcelParser.GetRowHeaderDiff ( IReadOnlyDictionary< string, int >  mapping,
IReadOnlyDictionary< string, int >  header 
)
inlinestatic

Definition at line 239 of file ExcelParser.cs.

240 {
241 StringBuilder stringBuilder = new StringBuilder();
242 List<KeyValuePair<string, int>> list = mapping.OrderBy((KeyValuePair<string, int> c) => c.Value).ToList();
243 int num = list.Max((KeyValuePair<string, int> c) => c.Key.Length);
244 foreach (KeyValuePair<string, int> item in list)
245 {
246 item.Deconstruct(out var key, out var value);
247 string text = key;
248 int index = value;
249 int value2;
250 bool num2 = header.TryGetValue(text, out value2);
251 string text2 = ((num2 && value2 != index) ? $"maybe {value2 + 1,2}/{ToLetterId(value2)} {text}" : "");
252 if (!num2)
253 {
254 text2 = "<missing>";
255 }
256 string text3 = header.FirstOrDefault((KeyValuePair<string, int> c) => c.Value == index).Key ?? "<missing>";
257 text3 = text3.PadRight(num + 3);
258 string text4 = text.PadRight(num);
259 stringBuilder.AppendLine($"{index + 1,2}/{ToLetterId(index),2}: {text4} -> {text3} {text2}");
260 }
261 return stringBuilder.ToString();
262 }
$
Definition: ExcelParser.cs:239

References $, item, and Key.

Referenced by SourceData< T, T2 >.ImportData().

◆ GetStr()

static string ExcelParser.GetStr ( int  id,
bool  useDefault = false 
)
inlinestatic

Definition at line 171 of file ExcelParser.cs.

172 {
173 IRow row = (useDefault ? rowDefault : ExcelParser.row);
174 if (row == null)
175 {
176 if (!useDefault)
177 {
178 return GetStr(id, useDefault: true);
179 }
180 return null;
181 }
182 ICell cell = row.GetCell(id);
183 if (IsNull(cell))
184 {
185 if (!useDefault)
186 {
187 return GetStr(id, useDefault: true);
188 }
189 return null;
190 }
191 cell.SetCellType(CellType.String);
192 if (cell.StringCellValue == "")
193 {
194 if (!useDefault)
195 {
196 return GetStr(id, useDefault: true);
197 }
198 return null;
199 }
200 if (!allowTrimming)
201 {
202 return cell.StringCellValue;
203 }
204 return cell.StringCellValue.Trim();
205 }
static bool IsNull(ICell cell)
Definition: ExcelParser.cs:20

References allowTrimming, GetStr(), IsNull(), row, and rowDefault.

Referenced by GetBool(), GetDouble(), GetFloat(), GetFloatArray(), GetInt(), GetIntArray(), GetStr(), SourceData< T, T2 >.GetStr(), GetString(), and GetStringArray().

◆ GetString() [1/2]

static string ExcelParser.GetString ( int  col,
IRow  _row 
)
inlinestatic

Definition at line 165 of file ExcelParser.cs.

166 {
167 row = _row;
168 return GetStr(col);
169 }

References GetStr(), and row.

◆ GetString() [2/2]

static string ExcelParser.GetString ( int  id)
inlinestatic

Definition at line 160 of file ExcelParser.cs.

161 {
162 return GetStr(id) ?? "";
163 }

References GetStr().

Referenced by SourceData< T, T2 >.GetString(), and ExcelData.Override().

◆ GetStringArray()

static string[] ExcelParser.GetStringArray ( int  id)
inlinestatic

Definition at line 145 of file ExcelParser.cs.

146 {
147 string str = GetStr(id);
148 if (str != null)
149 {
150 if (!allowTrimming)
151 {
152 return str.Split(',');
153 }
154 return (from c in str.Split(',')
155 select c.Trim()).ToArray();
156 }
157 return Array.Empty<string>();
158 }

References allowTrimming, and GetStr().

Referenced by SourceData< T, T2 >.GetStringArray().

◆ IsNull()

static bool ExcelParser.IsNull ( ICell  cell)
inlinestatic

Definition at line 20 of file ExcelParser.cs.

21 {
22 if (cell != null && cell.CellType != CellType.Blank)
23 {
24 return cell.CellType == CellType.Unknown;
25 }
26 return true;
27 }

Referenced by GetStr().

◆ ReportIllFormat< T >()

static void ExcelParser.ReportIllFormat< T > ( int  id)
inlinestatic

Definition at line 219 of file ExcelParser.cs.

220 {
221 StringBuilder stringBuilder = new StringBuilder();
222 string name = typeof(T).Name;
223 ICell cell = row?.Cells.TryGet(id, returnNull: true);
224 IRow obj = row;
225 string value = ((obj != null && obj.RowNum >= 3) ? $", default:'{rowDefault?.Cells.TryGet(id, returnNull: true)}'" : ", SourceData begins at the 4th row. 3rd row is the default value row.");
226 stringBuilder.AppendLine("#source ill-format file: " + path);
227 object[] array = new object[5];
228 IRow obj2 = row;
229 array[0] = ((obj2 != null) ? new int?(obj2.RowNum + 1) : null);
230 array[1] = id + 1;
231 array[2] = ToLetterId(id);
232 array[3] = name;
233 array[4] = cell;
234 stringBuilder.Append(string.Format("row#{0}, cell#{1}/#{2}, expected:'{3}', read:'{4}'", array));
235 stringBuilder.AppendLine(value);
236 Debug.LogWarning(stringBuilder);
237 }
static string ToLetterId(int id)
Definition: ExcelParser.cs:207
static string path
Definition: ExcelParser.cs:10

References $, Debug, path, row, and ToLetterId().

◆ ToLetterId()

static string ExcelParser.ToLetterId ( int  id)
inlinestatic

Definition at line 207 of file ExcelParser.cs.

208 {
209 string text = "";
210 while (id >= 0)
211 {
212 text = (char)(id % 26 + 65) + text;
213 id /= 26;
214 id--;
215 }
216 return text;
217 }

Referenced by ReportIllFormat< T >().

Member Data Documentation

◆ allowTrimming

bool ExcelParser.allowTrimming
static

Definition at line 18 of file ExcelParser.cs.

Referenced by ClearStaticRows(), GetStr(), and GetStringArray().

◆ path

string ExcelParser.path
static

Definition at line 10 of file ExcelParser.cs.

Referenced by ReportIllFormat< T >().

◆ row

IRow ExcelParser.row
static

Definition at line 12 of file ExcelParser.cs.

Referenced by ClearStaticRows(), GetBool(), GetInt(), GetStr(), GetString(), and ReportIllFormat< T >().

◆ rowDefault

IRow ExcelParser.rowDefault
static

Definition at line 14 of file ExcelParser.cs.

Referenced by ClearStaticRows(), and GetStr().

◆ rowHeader

IRow ExcelParser.rowHeader
static

Definition at line 16 of file ExcelParser.cs.

Referenced by ClearStaticRows().


The documentation for this class was generated from the following file: