您需要以适当的格式编写宏嵌入文件,例如我读取.xltm文件并使用其MIME类型.xltm进行写入 . 看下面的功能
public ActionResult DownloadXLTMFile()
{
try
{
//Get your macro enabled file after manipulation
MemoryStream excelMS = .....
//Using Resposne Stream to Make File Available for User to Download;
Response.Clear();
Response.ContentType = "application/vnd.ms-excel.template.macroEnabled.12";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "YourFileName.xltm"));
Response.BinaryWrite(excelMS.ToArray());
Response.End();
}
catch (Exception Ex)
{ }
finally
{}
return View();
}
你可以找到合适的MIME类型here