public void Write(object target, string excelFileName, string templateFileName) { if (target == null) { throw new ArgumentNullException("target"); } using (ExcelManager em = new ExcelManager()) { em.Open(templateFileName); Write(em, target); em.SaveAs(excelFileName); } }
public void Read(object destination, string excelFileName) { if (destination == null) { throw new ArgumentNullException("destination"); } using (ExcelManager em = new ExcelManager()) { em.Open(excelFileName); HandleCommonClassAttributes(em, destination); // Check attributes of Properties in class Type objType = destination.GetType(); foreach (PropertyInfo propInfo in objType.GetProperties()) { object[] attributes = propInfo.GetCustomAttributes(true); if (attributes == null) { continue; } foreach (Attribute att in attributes) { HandleCommonPropertiesAttributes(em, destination, att, propInfo); // Read Specific Attributes: // [FromCell] FromCellAttribute fromCell = att as FromCellAttribute; if (fromCell != null) { object value = em.GetValue(fromCell.CellAddress, fromCell.Category); propInfo.SetValue(destination, value, null); } // [FromRange] FromRangeAttribute fromRange = att as FromRangeAttribute; if (fromRange != null) { ArrayList values = em.GetRangeValues(fromRange.StartCellAddress, fromRange.EndCellAddress, fromRange.Category); propInfo.SetValue(destination, values, null); } } } } }