Elin Decompiled Documentation EA 23.285 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 Public Attributes

static string path
 
static IRow row
 
static IRow rowDefault
 

Detailed Description

Definition at line 6 of file ExcelParser.cs.

Member Function Documentation

◆ GetBool() [1/2]

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

Definition at line 56 of file ExcelParser.cs.

57 {
58 row = _row;
59 return GetBool(col);
60 }
static bool GetBool(int id)
Definition: ExcelParser.cs:43
static IRow row
Definition: ExcelParser.cs:10

References GetBool(), and row.

◆ GetBool() [2/2]

static bool ExcelParser.GetBool ( int  id)
inlinestatic

Definition at line 43 of file ExcelParser.cs.

44 {
45 string str = GetStr(id);
46 bool result;
47 return str switch
48 {
49 null => false,
50 "1" => true,
51 "0" => false,
52 _ => bool.TryParse(str, out result) && result,
53 };
54 }
static string GetStr(int id, bool useDefault=false)
Definition: ExcelParser.cs:151

References GetStr().

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

◆ GetDouble()

static double ExcelParser.GetDouble ( int  id)
inlinestatic

Definition at line 62 of file ExcelParser.cs.

63 {
64 string str = GetStr(id);
65 if (str.IsEmpty())
66 {
67 return 0.0;
68 }
69 if (!double.TryParse(str, out var result))
70 {
71 ReportIllFormat<double>(id);
72 }
73 return result;
74 }

References GetStr().

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

◆ GetFloat()

static float ExcelParser.GetFloat ( int  id)
inlinestatic

Definition at line 76 of file ExcelParser.cs.

77 {
78 string str = GetStr(id);
79 if (str.IsEmpty())
80 {
81 return 0f;
82 }
83 if (!float.TryParse(str, out var result))
84 {
85 ReportIllFormat<float>(id);
86 }
87 return result;
88 }

References GetStr().

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

◆ GetFloatArray()

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

Definition at line 90 of file ExcelParser.cs.

91 {
92 string str = GetStr(id);
93 if (str.IsEmpty())
94 {
95 return Array.Empty<float>();
96 }
97 string[] array = str.Split(',');
98 float[] array2 = new float[array.Length];
99 for (int i = 0; i < array.Length; i++)
100 {
101 if (!float.TryParse(array[i], out array2[i]))
102 {
103 ReportIllFormat<float>(id);
104 array2[i] = 0f;
105 }
106 }
107 return array2;
108 }

References GetStr().

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

◆ GetInt() [1/2]

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

Definition at line 37 of file ExcelParser.cs.

38 {
39 row = _row;
40 return GetInt(col);
41 }
static int GetInt(int id)
Definition: ExcelParser.cs:23

References GetInt(), and row.

◆ GetInt() [2/2]

static int ExcelParser.GetInt ( int  id)
inlinestatic

Definition at line 23 of file ExcelParser.cs.

24 {
25 string str = GetStr(id);
26 if (str.IsEmpty())
27 {
28 return 0;
29 }
30 if (!int.TryParse(str, out var result))
31 {
32 ReportIllFormat<int>(id);
33 }
34 return result;
35 }

References GetStr().

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

◆ GetIntArray()

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

Definition at line 110 of file ExcelParser.cs.

111 {
112 string str = GetStr(id);
113 if (str.IsEmpty())
114 {
115 return Array.Empty<int>();
116 }
117 string[] array = str.Split(',');
118 int[] array2 = new int[array.Length];
119 for (int i = 0; i < array.Length; i++)
120 {
121 if (!int.TryParse(array[i], out array2[i]))
122 {
123 ReportIllFormat<int>(id);
124 array2[i] = 0;
125 }
126 }
127 return array2;
128 }

References GetStr().

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

◆ GetStr()

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

Definition at line 151 of file ExcelParser.cs.

152 {
153 IRow row = (useDefault ? rowDefault : ExcelParser.row);
154 if (row == null)
155 {
156 if (!useDefault)
157 {
158 return GetStr(id, useDefault: true);
159 }
160 return null;
161 }
162 ICell cell = row.GetCell(id);
163 if (IsNull(cell))
164 {
165 if (!useDefault)
166 {
167 return GetStr(id, useDefault: true);
168 }
169 return null;
170 }
171 cell.SetCellType(CellType.String);
172 if (cell.StringCellValue == "")
173 {
174 if (!useDefault)
175 {
176 return GetStr(id, useDefault: true);
177 }
178 return null;
179 }
180 return cell.StringCellValue;
181 }
static IRow rowDefault
Definition: ExcelParser.cs:12
static bool IsNull(ICell cell)
Definition: ExcelParser.cs:14

References 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 145 of file ExcelParser.cs.

146 {
147 row = _row;
148 return GetStr(col);
149 }

References GetStr(), and row.

◆ GetString() [2/2]

static string ExcelParser.GetString ( int  id)
inlinestatic

Definition at line 140 of file ExcelParser.cs.

141 {
142 return GetStr(id) ?? "";
143 }

References GetStr().

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

◆ GetStringArray()

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

Definition at line 130 of file ExcelParser.cs.

131 {
132 string str = GetStr(id);
133 if (str != null)
134 {
135 return str.Split(',');
136 }
137 return Array.Empty<string>();
138 }

References GetStr().

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

◆ IsNull()

static bool ExcelParser.IsNull ( ICell  cell)
inlinestatic

Definition at line 14 of file ExcelParser.cs.

15 {
16 if (cell != null && cell.CellType != CellType.Blank)
17 {
18 return cell.CellType == CellType.Unknown;
19 }
20 return true;
21 }

Referenced by GetStr().

◆ ReportIllFormat< T >()

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

Definition at line 195 of file ExcelParser.cs.

196 {
197 StringBuilder stringBuilder = new StringBuilder();
198 string name = typeof(T).Name;
199 ICell cell = row?.Cells.TryGet(id, returnNull: true);
200 IRow obj = row;
201 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.");
202 stringBuilder.AppendLine("$source ill-format file: " + path);
203 object[] array = new object[5];
204 IRow obj2 = row;
205 array[0] = ((obj2 != null) ? new int?(obj2.RowNum + 1) : null);
206 array[1] = id + 1;
207 array[2] = ToLetterId(id);
208 array[3] = name;
209 array[4] = cell;
210 stringBuilder.Append(string.Format("row#{0}, cell'{1}'/'{2}', expected:'{3}', read:'{4}'", array));
211 stringBuilder.AppendLine(value);
212 Debug.LogError(stringBuilder);
213 }
$
Definition: ModManager.cs:85
static string ToLetterId(int id)
Definition: ExcelParser.cs:183
static string path
Definition: ExcelParser.cs:8

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

◆ ToLetterId()

static string ExcelParser.ToLetterId ( int  id)
inlinestatic

Definition at line 183 of file ExcelParser.cs.

184 {
185 string text = "";
186 while (id >= 0)
187 {
188 text = (char)(id % 26 + 65) + text;
189 id /= 26;
190 id--;
191 }
192 return text;
193 }

Referenced by ReportIllFormat< T >().

Member Data Documentation

◆ path

string ExcelParser.path
static

Definition at line 8 of file ExcelParser.cs.

Referenced by ReportIllFormat< T >().

◆ row

IRow ExcelParser.row
static

Definition at line 10 of file ExcelParser.cs.

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

◆ rowDefault

IRow ExcelParser.rowDefault
static

Definition at line 12 of file ExcelParser.cs.

Referenced by GetStr().


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