2using System.Collections.Generic;
5using NPOI.SS.UserModel;
12 public static IRow
row;
18 public static bool IsNull(ICell cell)
20 if (cell !=
null && cell.CellType != CellType.Blank)
22 return cell.CellType == CellType.Unknown;
34 if (!
int.TryParse(str, out var result))
36 if (
float.TryParse(str, out var result2))
40 ReportIllFormat<int>(
id);
45 public static int GetInt(
int col, IRow _row)
60 _ =>
bool.TryParse(str, out result) && result,
64 public static bool GetBool(
int col, IRow _row)
77 if (!
double.TryParse(str, out var result))
79 ReportIllFormat<double>(
id);
91 if (!
float.TryParse(str, out var result))
93 ReportIllFormat<float>(
id);
103 return Array.Empty<
float>();
105 string[] array = str.Split(
',');
106 float[] array2 =
new float[array.Length];
107 for (
int i = 0; i < array.Length; i++)
109 if (!
float.TryParse(array[i], out array2[i]))
111 ReportIllFormat<float>(
id);
123 return Array.Empty<
int>();
125 string[] array = str.Split(
',');
126 int[] array2 =
new int[array.Length];
127 for (
int i = 0; i < array.Length; i++)
129 if (!
int.TryParse(array[i], out array2[i]))
131 if (
float.TryParse(array[i], out var result))
133 array2[i] = (int)result;
136 ReportIllFormat<int>(
id);
148 return str.Split(
',');
150 return Array.Empty<
string>();
164 public static string GetStr(
int id,
bool useDefault =
false)
171 return GetStr(
id, useDefault:
true);
175 ICell cell =
row.GetCell(
id);
180 return GetStr(
id, useDefault:
true);
184 cell.SetCellType(CellType.String);
185 if (cell.StringCellValue ==
"")
189 return GetStr(
id, useDefault:
true);
193 return cell.StringCellValue;
201 text = (char)(
id % 26 + 65) + text;
210 StringBuilder stringBuilder =
new StringBuilder();
211 string name = typeof(T).Name;
212 ICell cell =
row?.Cells.TryGet(
id, returnNull:
true);
214 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.");
215 stringBuilder.AppendLine(
"#source ill-format file: " +
path);
216 object[] array =
new object[5];
218 array[0] = ((obj2 !=
null) ?
new int?(obj2.RowNum + 1) :
null);
223 stringBuilder.Append(
string.Format(
"row#{0}, cell#{1}/#{2}, expected:'{3}', read:'{4}'", array));
224 stringBuilder.AppendLine(value);
225 Debug.LogWarning(stringBuilder);
228 public static string GetRowHeaderDiff(IReadOnlyDictionary<string, int> mapping, IReadOnlyDictionary<string, int> header)
230 StringBuilder stringBuilder =
new StringBuilder();
231 List<KeyValuePair<string, int>> list = mapping.OrderBy((KeyValuePair<string, int> c) => c.Value).ToList();
232 int num = list.Max((KeyValuePair<string, int> c) => c.Key.Length);
233 foreach (KeyValuePair<string, int>
item in list)
235 item.Deconstruct(out var key, out var value);
239 bool num2 = header.TryGetValue(text, out value2);
240 string text2 = ((num2 && value2 != index) ?
$"maybe {value2 + 1,2}/{ToLetterId(value2)} {text}" :
"");
245 string text3 = header.FirstOrDefault((KeyValuePair<string, int> c) => c.Value == index).
Key ??
"<missing>";
246 text3 = text3.PadRight(num + 3);
247 string text4 = text.PadRight(num);
248 stringBuilder.AppendLine(
$"{index + 1,2}/{ToLetterId(index),2}: {text4} -> {text3} {text2}");
250 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 float[] GetFloatArray(int id)
static string GetString(int col, IRow _row)
static string[] GetStringArray(int id)