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 cell.SetCellType(CellType.String);
192 if (cell.StringCellValue ==
"")
196 return GetStr(
id, useDefault:
true);
202 return cell.StringCellValue;
204 return cell.StringCellValue.Trim();
212 text = (char)(
id % 26 + 65) + text;
221 StringBuilder stringBuilder =
new StringBuilder();
222 string name = typeof(T).Name;
223 ICell cell =
row?.Cells.TryGet(
id, returnNull:
true);
225 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.");
226 stringBuilder.AppendLine(
"#source ill-format file: " +
path);
227 object[] array =
new object[5];
229 array[0] = ((obj2 !=
null) ?
new int?(obj2.RowNum + 1) :
null);
234 stringBuilder.Append(
string.Format(
"row#{0}, cell#{1}/#{2}, expected:'{3}', read:'{4}'", array));
235 stringBuilder.AppendLine(value);
236 Debug.LogWarning(stringBuilder);
239 public static string GetRowHeaderDiff(IReadOnlyDictionary<string, int> mapping, IReadOnlyDictionary<string, int> header)
241 StringBuilder stringBuilder =
new StringBuilder();
242 List<KeyValuePair<string, int>> list = mapping.OrderBy((KeyValuePair<string, int> c) => c.Value).ToList();
243 int num = list.Max((KeyValuePair<string, int> c) => c.Key.Length);
244 foreach (KeyValuePair<string, int>
item in list)
246 item.Deconstruct(out var key, out var value);
250 bool num2 = header.TryGetValue(text, out value2);
251 string text2 = ((num2 && value2 != index) ?
$"maybe {value2 + 1,2}/{ToLetterId(value2)} {text}" :
"");
256 string text3 = header.FirstOrDefault((KeyValuePair<string, int> c) => c.Value == index).
Key ??
"<missing>";
257 text3 = text3.PadRight(num + 3);
258 string text4 = text.PadRight(num);
259 stringBuilder.AppendLine(
$"{index + 1,2}/{ToLetterId(index),2}: {text4} -> {text3} {text2}");
261 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)