C# mvc读取模板并修改上传到web
后台:
public FileResult GetXls() { FileStream fs = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/数据挖掘模版.xlsx"), FileMode.Open, FileAccess.ReadWrite); XSSFWorkbook book = new XSSFWorkbook(fs); //添加一个sheet ISheet sheet1 = book.GetSheetAt(0); //获取list数据 //给sheet1添加第一行的头部标题 IRow row1 = sheet1.CreateRow(10); row1.CreateCell(0).SetCellValue("电脑号"); row1.CreateCell(1).SetCellValue("姓名"); //将数据逐步写入sheet1各个行 // 写入到客户端 MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, "application/vnd.ms-excel", "test.xlsx"); }
前台:
@Html.ActionLink("统计", "GetXls", null, new { @class = "easyui-linkbutton" })