使用 smartxls dll 我无法更改打开时的默认名称
我在我的 asp.net 项目中使用 c# 来使用 smartxls。我有以下代码:
var excel = new SmartXLS.WorkBook();
string projPath = AppDomain.CurrentDomain.BaseDirectory;
excel.readXLSX(projPath + @"ExcelTemplates\" + template);
excel.ImportDataTable(....)
Response.ContentType = "application/vnd.ms-excel";
excel.write(Context.REsponse.OutputStream);
这似乎工作正常,我的数据直接在我的 aspx 页面上的页面链接上打开,但打开后,它会自动将文件命名为 default.xls,我不知道如何更改此设置姓名。我尝试了 excel.setSheetName 以及 excel.DefinedName,但是打开 Excel 工作表时都没有更改该名称,它始终是 default.xls。 有谁知道如何用我上面的代码设置这个名称? 我知道如果我将其直接保存到写入中的 C:\filename 之类的路径,我可以重命名,但我需要它具有特定的名称,并在单击按钮或链接时自动为客户端打开。
谢谢
I am using smartxls in my asp.net project with c#. I have the following code:
var excel = new SmartXLS.WorkBook();
string projPath = AppDomain.CurrentDomain.BaseDirectory;
excel.readXLSX(projPath + @"ExcelTemplates\" + template);
excel.ImportDataTable(....)
Response.ContentType = "application/vnd.ms-excel";
excel.write(Context.REsponse.OutputStream);
This appears to work fine, my data is opened up directly on a page link on my aspx page, but upon opening, it is automatically naming the file to default.xls, I cannot figure out how to change this name. I tried excel.setSheetName as well as excel.DefinedName, but neither is changing that name of excel sheet when it opens, it is always default.xls.
Does anyone know how to set this name with my code above?
I know I can rename if I save it directly to a path like C:\filename in the write, but I need it to have specific name and open automatically for the client on a button or link click.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要明确指定文件名。
Response.ContentType = "application/vnd.ms-excel";
//添加这一行
Response.Addheader "Content-Disposition", "attachment;Filename=" &
youfileName& ".xls"
excel.write(Context.REsponse.OutputStream);
You need specify the file name explictly.
Response.ContentType = "application/vnd.ms-excel";
//add this line
Response.Addheader "Content-Disposition", "attachment;Filename=" &
youfileName& ".xls"
excel.write(Context.REsponse.OutputStream);