3 Replies - 10153 Views - Last Post: 28 September 2012 - 04:49 AM

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 408
  • Joined: 04-January 11

Saving Excel File

Posted 25 September 2012 - 03:09 AM

I have created a website before that saves Excel file and it was a success.

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.

Method 1
   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.

Method 2
   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?

Is This A Good Question/Topic? 0
  • +

Replies To: Saving Excel File

#2 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 408
  • Joined: 04-January 11

Re: Saving Excel File

Posted 26 September 2012 - 01:50 AM

I have spent almost 2 days on this problem but still nothing works. I want to save my workbook just like in Method 2 but instead of saving it to the server, I want to prompt the user for open and save so that he can save the file to his client computer just like in Method 1.

I have researched that this can be done by installing the GemBoxSoftware but problem is I don't have administrator privileges to do so.

So I thought that maybe I could save the file to the server then transfer it to the client computer by prompting the user for saving, then delete it from server afterwards. I am in the dark of how to proceed though. I hope somebody could help.

This post has been edited by November-06: 26 September 2012 - 01:51 AM

Was This Post Helpful? 0
  • +
  • -

#3 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 408
  • Joined: 04-January 11

Re: Saving Excel File

Posted 28 September 2012 - 03:11 AM

I removed the .SaveAs for the workbook, removed the button from the update panel, I didn't code anything to save it, just placed some sheets to the workbook, but when I clicked the button, a save as dialog box appeared enabling user to save client side. And I am happy about this for the mean time.

If the user choose save, everything works fine. If he chooses to cancel, another popup appears asking "do you wan't do save changes to Sheet1.xls". I would be happy with what is happening save for the fact that the last popup is still prompting after the user already cancelled.
Was This Post Helpful? 0
  • +
  • -

#4 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 408
  • Joined: 04-January 11

Re: Saving Excel File

Posted 28 September 2012 - 04:49 AM

It was working as I said in the previous post but when I published it in the server, there is the javascript error Expected ')' which I am not sure where to locate.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1