2using System.Collections.Generic;
5using NPOI.SS.UserModel;
12 public static IRow
row;
20 public static bool IsNull(ICell cell)
22 if (cell !=
null && cell.CellType != CellType.Blank)
24 return cell.CellType == CellType.Unknown;
36 if (!
int.TryParse(str, out var result))
38 if (
float.TryParse(str, out var result2))
42 ReportIllFormat<int>(
id);
47 public static int GetInt(
int col, IRow _row)
62 _ =>
bool.TryParse(str, out result) && result,
66 public static bool GetBool(
int col, IRow _row)
79 if (!
double.TryParse(str, out var result))
81 ReportIllFormat<double>(
id);
93 if (!
float.TryParse(str, out var result))
95 ReportIllFormat<float>(
id);
105 return Array.Empty<
float>();
107 string[] array = str.Split(
',');
108 float[] array2 =
new float[array.Length];
109 for (
int i = 0; i < array.Length; i++)
111 if (!
float.TryParse(array[i], out array2[i]))
113 ReportIllFormat<float>(
id);
125 return Array.Empty<
int>();
127 string[] array = str.Split(
',');
128 int[] array2 =
new int[array.Length];
129 for (
int i = 0; i < array.Length; i++)
131 if (!
int.TryParse(array[i], out array2[i]))
133 if (
float.TryParse(array[i], out var result))
135 array2[i] = (int)result;
138 ReportIllFormat<int>(
id);
152 return str.Split(
',');
154 return (from c in str.Split(
',')
155 select c.Trim()).ToArray();
157 return Array.Empty<
string>();
171 public static string GetStr(
int id,
bool useDefault =
false)
178 return GetStr(
id, useDefault:
true);
182 ICell cell =
row.GetCell(
id);
187 return GetStr(
id, useDefault:
true);
191 if (cell.CellType != CellType.String)
193 cell.SetCellType(CellType.String);
195 if (cell.StringCellValue ==
"")
199 return GetStr(
id, useDefault:
true);
205 return cell.StringCellValue;
207 return cell.StringCellValue.Trim();
215 text = (char)(
id % 26 + 65) + text;
224 StringBuilder stringBuilder =
new StringBuilder();
225 string name = typeof(T).Name;
226 ICell cell =
row?.Cells.TryGet(
id, returnNull:
true);
228 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.");
229 stringBuilder.AppendLine(
"#source ill-format file: " +
path);
230 object[] array =
new object[5];
232 array[0] = ((obj2 !=
null) ?
new int?(obj2.RowNum + 1) : ((
int?)
null));
237 stringBuilder.Append(
string.Format(
"row#{0}, cell#{1}/#{2}, expected:'{3}', read:'{4}'", array));
238 stringBuilder.AppendLine(value);
239 Debug.LogWarning(stringBuilder);
242 public static string GetRowHeaderDiff(IReadOnlyDictionary<string, int> mapping, IReadOnlyDictionary<string, int> header)
244 StringBuilder stringBuilder =
new StringBuilder();
245 List<KeyValuePair<string, int>> list = mapping.OrderBy((KeyValuePair<string, int> c) => c.Value).ToList();
246 int num = list.Max((KeyValuePair<string, int> c) => c.Key.Length);
247 foreach (KeyValuePair<string, int>
item in list)
249 item.Deconstruct(out var key, out var value);
253 bool num2 = header.TryGetValue(text, out value2);
254 string text2 = ((num2 && value2 != index) ?
$"maybe {value2 + 1,2}/{ToLetterId(value2)} {text}" :
"");
259 string text3 = header.FirstOrDefault((KeyValuePair<string, int> c) => c.Value == index).
Key ??
"<missing>";
260 text3 = text3.PadRight(num + 3);
261 string text4 = text.PadRight(num);
262 stringBuilder.AppendLine(
$"{index + 1,2}/{ToLetterId(index),2}: {text4} -> {text3} {text2}");
264 return stringBuilder.ToString();
static void ClearStaticRows()
static bool GetBool(int id)
static void ReportIllFormat< T >(int id)
static string GetRowHeaderDiff(IReadOnlyDictionary< string, int > mapping, IReadOnlyDictionary< string, int > header)
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 bool allowTrimming
static float[] GetFloatArray(int id)
static string GetString(int col, IRow _row)
static string[] GetStringArray(int id)