using OfficeOpenXml; using MemoryPack; namespace ExcelConfig { public partial class GeoDescCategory { public override void Serialization(ExcelPackage p) { ExcelWorksheet worksheet = p.Workbook.Worksheets.First(); // 获取最大行数 int maxRow = worksheet.Dimension.End.Row; // 从第6行开始遍历 for (int row = 6; row <= maxRow; row++) { var data = new GeoDesc(worksheet.Cells, row); Dict[data.Id] = data; } } public override byte[] GetData() { return MemoryPackSerializer.Serialize(typeof(Dictionary), Dict); } } public partial class GeoDesc { public GeoDesc(ExcelRange cells, int row) { Id = (int)ExcelExporter.ConvertValue(cells[row, 3].Text.Trim(), typeof(int)); BigClass = (String)ExcelExporter.ConvertValue(cells[row, 4].Text.Trim(), typeof(String)); SmallClass = (String)ExcelExporter.ConvertValue(cells[row, 5].Text.Trim(), typeof(String)); GeoName = (String)ExcelExporter.ConvertValue(cells[row, 6].Text.Trim(), typeof(String)); CivEnum = (String)ExcelExporter.ConvertValue(cells[row, 7].Text.Trim(), typeof(String)); NearbyCity = (String[])ExcelExporter.ConvertValue(cells[row, 8].Text.Trim(), typeof(String[])); GeoDescStr = (String)ExcelExporter.ConvertValue(cells[row, 9].Text.Trim(), typeof(String)); } } }