3using NPOI.SS.UserModel;
8 public static string path;
10 public static IRow
row;
14 public static bool IsNull(ICell cell)
16 if (cell !=
null && cell.CellType != CellType.Blank)
18 return cell.CellType == CellType.Unknown;
30 if (!
int.TryParse(str, out var result))
32 ReportIllFormat<int>(
id);
37 public static int GetInt(
int col, IRow _row)
52 _ =>
bool.TryParse(str, out result) && result,
56 public static bool GetBool(
int col, IRow _row)
69 if (!
double.TryParse(str, out var result))
71 ReportIllFormat<double>(
id);
83 if (!
float.TryParse(str, out var result))
85 ReportIllFormat<float>(
id);
95 return Array.Empty<
float>();
97 string[] array = str.Split(
',');
98 float[] array2 =
new float[array.Length];
99 for (
int i = 0; i < array.Length; i++)
101 if (!
float.TryParse(array[i], out array2[i]))
103 ReportIllFormat<float>(
id);
115 return Array.Empty<
int>();
117 string[] array = str.Split(
',');
118 int[] array2 =
new int[array.Length];
119 for (
int i = 0; i < array.Length; i++)
121 if (!
int.TryParse(array[i], out array2[i]))
123 ReportIllFormat<int>(
id);
135 return str.Split(
',');
137 return Array.Empty<
string>();
151 public static string GetStr(
int id,
bool useDefault =
false)
158 return GetStr(
id, useDefault:
true);
162 ICell cell =
row.GetCell(
id);
167 return GetStr(
id, useDefault:
true);
171 cell.SetCellType(CellType.String);
172 if (cell.StringCellValue ==
"")
176 return GetStr(
id, useDefault:
true);
180 return cell.StringCellValue;
188 text = (char)(
id % 26 + 65) + text;
197 StringBuilder stringBuilder =
new StringBuilder();
198 string name = typeof(T).Name;
199 ICell cell =
row?.Cells.TryGet(
id, returnNull:
true);
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];
205 array[0] = ((obj2 !=
null) ?
new int?(obj2.RowNum + 1) :
null);
210 stringBuilder.Append(
string.Format(
"row#{0}, cell'{1}'/'{2}', expected:'{3}', read:'{4}'", array));
211 stringBuilder.AppendLine(value);
212 Debug.LogError(stringBuilder);
static bool GetBool(int id)
static void ReportIllFormat< T >(int id)
static string ToLetterId(int id)
static bool GetBool(int col, IRow _row)
static int GetInt(int id)
static bool IsNull(ICell cell)
static string GetString(int id)
static int[] GetIntArray(int id)
static int GetInt(int col, IRow _row)
static float GetFloat(int id)
static double GetDouble(int id)
static string GetStr(int id, bool useDefault=false)
static float[] GetFloatArray(int id)
static string GetString(int col, IRow _row)
static string[] GetStringArray(int id)