Is it possible to save the same spreadsheet twice. I would like to be able to save the spreadsheet to disk and stream it to the browser. Right now I’m trying to call the save method twice
Excel.Save(“Test.xls”, SaveType.OpenInBrowser, FileFormatType.Default, Me.Response)
The spreadsheet gets saved to disk and a spreadsheet gets streamed to the browser but the spreadsheet that opens in the browser does not contain any information
Thanks in advance for any hints or tips.
When you save the file to disk, Excel object is re-initialized.
You can try this:
1. Save to memory stream.
2. Write to disk.
3. Write to browser.
The following is the sample code:
Dim stream as MemoryStream = new MemoryStream()
Dim data() as Byte
data = stream.ToArray()
'Write to disk
Dim fs as FileStream = new FileStream(“Test.xls”, FileMode.Create, FileAcess.Write)
fs.Write(data, 0, data.Length)
'Write to browser
Response.ContentType = "application/vnd.ms-excel"
response.AddHeader( “content-disposition”,“inline; filename=Test.xls”)
I understand the process you’ve described and I appreciate the sample code but I’m having a little trouble. I’m using version 188.8.131.52 so perhaps I need to upgrade, but in your sample code you have
When I try to use that in my code I get an error "value of the type ‘System.IO.MemoryStream’ cannot be converted to ‘String’."
I do have an option to either use Excel.Save(“test.xls”, FileFormatType.Default, stream) or there’s Excel.SaveToStream but I can’t seem to get either of those options working either.
I think I may rethink my approach and just save the spreadsheet to disk and then email it to the user.
Thanks for your prompt reply!
- You may have to upgrade to the latest version to use my code.
2. In v184.108.40.206, Excel.Save(stream, FileFormatType.Default) cannot work. But you can try:
Dim stream as MemoryStream stream = Excel.SaveToStream(FileFormatType.Default)
What’s the problem when you run the above code?