开发者

Using smartxls dll I cannot change the default name on open

开发者 https://www.devze.com 2023-01-24 20:33 出处:网络
I 开发者_开发问答am using smartxls in my asp.net project with c#.I have the following code: var excel = new SmartXLS.WorkBook();

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


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);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号