public void toExecTest() { //string connectionstring = "Data Source=172.29.181.161;Initial Catalog=mobileSurvey;User ID=sa;Password=skdltmfltjcl"; //DbContextOptions<mobileSurveyContext> options = new DbContextOptions<mobileSurveyContext>(); //options.UseSqlServer(connectionstring); var context = new com.study.core.model.mobileSurveyContext( ); var surveys = context.TblSurvey.ToList(); var totable = new ToExcelWithOfficeOpenXml(); Assert.IsNotNull(surveys); var stream = totable.convertToExcel <TblSurvey>(surveys); Assert.IsNotNull(stream); string sourcefile = @"i:\toexceltest1.xlsx"; System.IO.File.WriteAllBytes(sourcefile, stream.ToArray()); Assert.IsTrue(System.IO.File.Exists(sourcefile)); }
public IActionResult DownLoad(string query) { var toexcel = new ToExcelWithOfficeOpenXml(); var lists = getSurveys(query); MemoryStream stream = toexcel.convertToExcel <TblSurvey>(lists.ToList()); string fileName = "data.xlsx"; string fileType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; stream.Position = 0; return(File(stream, fileType, fileName)); }