请问:导出Excel后不能弹出保存对话框

goodsun2 2008-07-16 01:09:25
string filepath = Server.MapPath("../excel/");
string filename = "BUG管理.xls";
string savefilename = getfilename(filename);
Excel.Application app = new Excel.Application();
Excel.WorkbookClass book;
book = (Excel.WorkbookClass)app.Workbooks.Open(filepath + filename);
Excel.Worksheet worksheet4 = (Excel.Worksheet)book.Worksheets[4];//声明sheet页对象
。。。。。
//保存文件到此路径
book.SaveCopyAs(filepath + savefilename);
book.Saved = true;
book.Close(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
app.Quit();
//打开文件
Response.Redirect("../excel/" + savefilename);


使用以上代码导出excel,本来会弹出一个"保存"对话框。但是我把"保存"对话框下的一个选项前的勾去掉了(忘了是什么),然后再导出excel时"保存"对话框
就不会弹出来了,而是直接在IE中打开导出的Excel,请问如何才能再弹出"保存"对话框??
...全文
329 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
suyiming 2008-07-16
  • 打赏
  • 举报
回复
string filepath = Server.MapPath("../excel/");
string filename = "BUG管理.xls";
string savefilename = getfilename(filename);
Excel.Application app = new Excel.Application();
Excel.WorkbookClass book;
book = (Excel.WorkbookClass)app.Workbooks.Open(filepath + filename);
Excel.Worksheet worksheet4 = (Excel.Worksheet)book.Worksheets[4];//声明sheet页对象
。。。。。
//保存文件到此路径
book.SaveCopyAs(filepath + savefilename);
book.Saved = true;
book.Close(System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
app.Quit();
//打开文件
Response.Redirect("../excel/" + savefilename);
Response.End();
mandula2007 2008-07-16
  • 打赏
  • 举报
回复
试试这个

book.SaveCopyAs(Server.MapPath(".") + "\\filename.xls");//保存Excel文件
book.Close(false,null,null);
book.Quit();
GC.Collect();

System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(".") + "\\filename.xls");
Response.Clear();
Response.Buffer= true;
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition","attachment;filename="+Server.UrlEncode(file.Name));
Response.AddHeader("Content-Length",file.Length.ToString());
Response.ContentType = "application/ms-excel";
Response.WriteFile(file.FullName);
Response.End();

62,205

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧