/// <summary> /// Creates Excel file based on T and saves it to specified path. /// </summary> public void Export <T>(IEnumerable <T> collection, List <string> columnNames, string path) { if (IsCollectionNullOrEmpty(collection) || AreColumnNamesNullOrEmpty(columnNames) || string.IsNullOrEmpty(path)) { throw new ArgumentException("One of the arguments is null or empty."); } FileInfo fileInfo = CreateFileInfo(path); using (IExcelFile excelFile = _excelCreator.Create(collection, sheetName, columnNames)) { excelFile.Save(fileInfo); } }
/// <summary> /// Returns list of T based on *.xlsx worksheet. /// </summary> public IEnumerable <T> Import(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentException("Path cannot be null or empty"); } IEnumerable <T> collectionToReturn = new List <T>(); using (FileStream fileStream = _fileStreamWrapper.Init(path, FileMode.Open)) using (IExcelFile excelFile = _excelCreator.Create(fileStream)) { collectionToReturn = new List <T>(excelFile.ConvertToObjects <T>()); } return(collectionToReturn); }
public FileResult Excel() { var document = excelCreator.Create(); return(this.File(document, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "excel-test.xlsx")); }