public void DeserializeTo(object model, ExcelPackage package) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (ReflectionHelper.GetIsCollection(model.GetType(), out var itemType, false)) { var rawCollection = XlsCollectionDeserializerCore.DeserializeCollection(itemType, XlsSheetSerializerCore.GetDefaultWorksheet(package), () => Activator.CreateInstance(itemType), 0, 0, m_settings); ReflectionHelper.PopulateCollection(rawCollection, model); return; } if (!XlsWorkbookDeserializerCore.DeserializeWorkbook(model, package.Workbook, m_settings)) { XlsSheetDeserializerCore.Deserialize(model, XlsSheetSerializerCore.GetDefaultWorksheet(package), m_settings); } }
public void Test() { var wbModel = TwoSheetsWorkbook.Setup(); var deserialized = new TwoSheetsWorkbook(); ExcelPackageSaveAndLoad.WorkbookTest(wb => { XlsWorkbookSerializerCore.SerializeWorkbook(wbModel, wb, new XlsxSerializerSettings()); }, wb => { XlsWorkbookDeserializerCore.DeserializeWorkbook(deserialized, wb, new XlsxSerializerSettings()); }, "workbook1.xlsx"); Assert.Equal(JsonConvert.SerializeObject(wbModel), JsonConvert.SerializeObject(deserialized)); }