| | |
| | | using NPOI.HSSF.UserModel; |
| | | using HMI.Core; |
| | | using HMI.Core.Util; |
| | | using NPOI.HSSF.UserModel; |
| | | using NPOI.SS.UserModel; |
| | | using NPOI.XSSF.UserModel; |
| | | using System; |
| | |
| | | IRow row1 = SheetOne.CreateRow(0); |
| | | for (int i = 0; i < properties.Count; i++) |
| | | { |
| | | row1.CreateCell(i).SetCellValue((attrs[i]).Name); |
| | | row1.CreateCell(i).SetCellValue(LangUtil.Get((attrs[i]).Name)); |
| | | } |
| | | |
| | | for (int i = 0; i < datas.Count(); i++) |
| | |
| | | IRow rowTemp = SheetOne.CreateRow(i + 1); |
| | | for (int j = 0; j < properties.Count; j++) |
| | | { |
| | | var value = properties[j].GetValue(datas[i]); |
| | | var attr = attrs[j]; |
| | | var value = attr.IgnoreExport ? "" : properties[j].GetValue(datas[i]); |
| | | rowTemp.CreateCell(j).SetCellValue(value.ToString()); |
| | | } |
| | | } |
| | |
| | | Dictionary<string, PropertyInfo> dict = new Dictionary<string, PropertyInfo>(); |
| | | for (int i = 0; i < attrs.Count; i++) |
| | | { |
| | | dict.Add(attrs[i].Name, properties[i]); |
| | | dict.Add(LangUtil.Get(attrs[i].Name), properties[i]); |
| | | } |
| | | using (FileStream fileStream1 = new FileStream(sourcePath, FileMode.Open, FileAccess.Read)) |
| | | { |
| | |
| | | string title = titleRow.GetCell(j).StringCellValue; |
| | | if (dict.ContainsKey(title)) |
| | | { |
| | | CellType ct = row.GetCell(j).CellType; |
| | | var cell = row.GetCell(j); |
| | | if (cell == null || cell.CellType == CellType.Blank) |
| | | continue; |
| | | CellType ct = cell.CellType; |
| | | object value = null; |
| | | if (ct == CellType.String) |
| | | value = row.GetCell(j).StringCellValue; |
| | |
| | | value = row.GetCell(j).BooleanCellValue; |
| | | |
| | | var prop = dict[title]; |
| | | if (prop.PropertyType is string) |
| | | if (prop.PropertyType == typeof(string)) |
| | | { |
| | | value = Convert.ToString(value); |
| | | } |
| | | else if (prop.PropertyType is double || prop.PropertyType is double?) |
| | | else if (prop.PropertyType == typeof(double) || prop.PropertyType == typeof(double?)) |
| | | { |
| | | value = Convert.ToDouble(value); |
| | | } |
| | | else if (prop.PropertyType is int || prop.PropertyType is int?) |
| | | else if (prop.PropertyType == typeof(int) || prop.PropertyType == typeof(int?)) |
| | | { |
| | | value = Convert.ToInt16(value); |
| | | } |
| | | else if (prop.PropertyType is bool || prop.PropertyType is bool?) |
| | | else if (prop.PropertyType == typeof(bool) || prop.PropertyType == typeof(bool?)) |
| | | { |
| | | value = Convert.ToBoolean(value); |
| | | } |
| | | |
| | | else if (prop.PropertyType.IsEnum) |
| | | { |
| | | value = Enum.Parse(prop.PropertyType, value.ToString()); |
| | | } |
| | | prop.SetValue(obj, value); |
| | | isEmpty = false; |
| | | } |