I am currently creating a different website with a different way of saving Excel file. It is also working. Problem is, it only saves to server in a static filename. It does not allow the user to choose a path in which to save the file client-side.
So the difference is, in the first website, I only have one sheet so I used HTMLTextWriter. The code snippet is below.
Response.Clear() Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileName) Response.Charset = "" Response.ContentType = "application/vnd.xls" Dim sw As New StringWriter() Dim htmltw As New HtmlTextWriter(sw) Dim gvw As New GridView() gvw.DataSource = ds.Tables(0) gvw.DataBind() gvw.RenderControl(htmltw) Response.Write(Convert.ToString(sw)) Response.End()
In the other website, I have four sheets in one workbook. So I used the ExcelWorkbook for saving. Here, on save, I already need to declare the filename. I do not have the option to Open, Save, Cancel just like in the first method in which a dialog box opens for attachments.
xlsWorkbook.SaveAs(strFileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); xlsWorkbook.Close(true, Type.Missing, Type.Missing);
I didn't post the whole code since it's too long and complex but this part right here is the part for saving the workbook. Is there a way I can save this workbook as an attachment just like in my first method so that the dialog box in which the user can save the file in client-side will appear?