Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
ExcelParser.cs
Go to the documentation of this file.
1using System;
2using NPOI.SS.UserModel;
3
4public class ExcelParser
5{
6 public static IRow row;
7
8 public static IRow rowDefault;
9
10 public static bool IsNull(ICell cell)
11 {
12 if (cell != null && cell.CellType != CellType.Blank)
13 {
14 return cell.CellType == CellType.Unknown;
15 }
16 return true;
17 }
18
19 public static int GetInt(int id)
20 {
21 if (int.TryParse(GetStr(id), out var result))
22 {
23 return result;
24 }
25 return 0;
26 }
27
28 public static int GetInt(int col, IRow _row)
29 {
30 row = _row;
31 return GetInt(col);
32 }
33
34 public static bool GetBool(int id)
35 {
36 string str = GetStr(id);
37 return str switch
38 {
39 "0" => false,
40 "1" => true,
41 null => false,
42 _ => bool.Parse(str),
43 };
44 }
45
46 public static bool GetBool(int col, IRow _row)
47 {
48 row = _row;
49 return GetBool(col);
50 }
51
52 public static double GetDouble(int id)
53 {
54 string str = GetStr(id);
55 if (str != null)
56 {
57 return double.Parse(str);
58 }
59 return 0.0;
60 }
61
62 public static float GetFloat(int id)
63 {
64 string str = GetStr(id);
65 if (str != null)
66 {
67 return float.Parse(str);
68 }
69 return 0f;
70 }
71
72 public static float[] GetFloatArray(int id)
73 {
74 string str = GetStr(id);
75 if (str != null)
76 {
77 return Array.ConvertAll(str.Split(','), float.Parse);
78 }
79 return new float[0];
80 }
81
82 public static int[] GetIntArray(int id)
83 {
84 string str = GetStr(id);
85 if (str != null)
86 {
87 return Array.ConvertAll(str.Split(','), int.Parse);
88 }
89 return new int[0];
90 }
91
92 public static string[] GetStringArray(int id)
93 {
94 string str = GetStr(id);
95 if (str != null)
96 {
97 return str.Split(',');
98 }
99 return new string[0];
100 }
101
102 public static string GetString(int id)
103 {
104 return GetStr(id) ?? "";
105 }
106
107 public static string GetString(int col, IRow _row)
108 {
109 row = _row;
110 return GetStr(col);
111 }
112
113 public static string GetStr(int id, bool useDefault = false)
114 {
115 IRow row = (useDefault ? rowDefault : ExcelParser.row);
116 if (row == null)
117 {
118 if (!useDefault)
119 {
120 return GetStr(id, useDefault: true);
121 }
122 return null;
123 }
124 ICell cell = row.GetCell(id);
125 if (IsNull(cell))
126 {
127 if (!useDefault)
128 {
129 return GetStr(id, useDefault: true);
130 }
131 return null;
132 }
133 cell.SetCellType(CellType.String);
134 if (cell.StringCellValue == "")
135 {
136 if (!useDefault)
137 {
138 return GetStr(id, useDefault: true);
139 }
140 return null;
141 }
142 return cell.StringCellValue;
143 }
144}
static bool GetBool(int id)
Definition: ExcelParser.cs:34
static IRow rowDefault
Definition: ExcelParser.cs:8
static bool GetBool(int col, IRow _row)
Definition: ExcelParser.cs:46
static int GetInt(int id)
Definition: ExcelParser.cs:19
static IRow row
Definition: ExcelParser.cs:6
static bool IsNull(ICell cell)
Definition: ExcelParser.cs:10
static string GetString(int id)
Definition: ExcelParser.cs:102
static int[] GetIntArray(int id)
Definition: ExcelParser.cs:82
static int GetInt(int col, IRow _row)
Definition: ExcelParser.cs:28
static float GetFloat(int id)
Definition: ExcelParser.cs:62
static double GetDouble(int id)
Definition: ExcelParser.cs:52
static string GetStr(int id, bool useDefault=false)
Definition: ExcelParser.cs:113
static float[] GetFloatArray(int id)
Definition: ExcelParser.cs:72
static string GetString(int col, IRow _row)
Definition: ExcelParser.cs:107
static string[] GetStringArray(int id)
Definition: ExcelParser.cs:92