.NET FrameWork
返回对象
HttpResponseMessage
测试
List<ImportExcel_Model> students = new List<ImportExcel_Model>
{
new ImportExcel_Model{ name="夫子",email="15153989759@qq.com",mobile_phone="15053989759" },
new ImportExcel_Model{ name="余帘",email="15153989759@qq.com",mobile_phone="151539459759" },
new ImportExcel_Model{ name="李慢慢",email="15153989759@qq.com",mobile_phone="15153989459" },
};
var mapper = new Mapper();
MemoryStream stream = new MemoryStream();
mapper.Save(stream, students, "sheet1", overwrite: true, xlsx: true);
return new HttpResponseMessage { Content = new ByteArrayContent(stream.ToArray()) };
Core
返回对象
ActionResult
实现
List<ImportExcel_Model> students = new List<ImportExcel_Model>
{
new ImportExcel_Model{ name="夫子",email="15153989759@qq.com",mobile_phone="15150989759" },
new ImportExcel_Model{ name="余帘",email="15153989759@qq.com",mobile_phone="15152989759" },
new ImportExcel_Model{ name="李慢慢",email="15153989759@qq.com",mobile_phone="15153989739" },
};
var mapper = new Mapper();
MemoryStream stream = new MemoryStream();
mapper.Save(stream, students, "sheet1", overwrite: true, xlsx: true);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Demo.xlsx");