|
|
 |
| Visual Studio Tools for Office Be sure to specify which version you are working with. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Studio Tools for Office section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

October 15th, 2009, 02:21 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 342
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Datagrid.RenderControl creates excel spreadsheet in invalid format?
I am using this code to turn a datagrid's contents into an excel spreadsheet:
Response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dgExcelOutput As New DataGrid
dgExcelOutput.DataSource = r_dvReport
dgExcelOutput.DataBind()
dgExcelOutput.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString)
Response.End()
It worked fine with Office 2003 . Upon upgrading to Office 2007 it's displaying this message:
The file you are trying to open, "test.xls" is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
Answering YES opens the spreadsheet just fine. It does not appear to me to be corrupted in any way.
Changing the ContentType and file extesion as some sites suggest:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("Content-Disposition", "attachment;Filename=test.xlsl")
Returns the same message even though the file extension is now "xlsl" (and the rest of the file name specified in Response.Addheader appears to be ignored):
The file you are trying to open, "frmExcel.xlsl" is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
So, what is necessary to suppress this *&^%$ message box?
Last edited by Ron Howerton : October 15th, 2009 at 02:23 PM.
Reason: Changed Title
|

October 15th, 2009, 11:03 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 Posts
|
|
Most of these warning messages in Excel can be suppressed by setting the Displayalerts to false
Application.DisplayAlerts = False
Not sure if it will work for you
Cheers
Shasur
|

October 16th, 2009, 10:46 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Denver, CO, USA.
Posts: 342
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sashur,
Thanks for your response! I would be happy just to prevent the box from being displayed, but there doesn't seem to be anywhere I can insert the suggested code. I can't reference Excel on the server because I want it to open on the client. But the result of the code in question is a file download dialog box on the client, not a web page. The only reference to Excel is in the server code specifying the Response.ContentType and the extension of the file name if it is specified. IOW, I can't seem to tell Excel to suppress messages before it opens because it's being opened by the file download dialog box, not via script, and I therefore cannot pass it parms first. But I'd be happy to be proven wrong about that if somebody can suggest how I might do so!
Otherwise, it appears that I need to resolve the apparent conflict between the Response.ContentType and extension of the file name specified (which, incidentally, defaults to .XLS when not specified). The .XLSX extension Excel 2007 wants to save does not appear to be associated with either "application/vnd.ms-excel" (the original ContentType that worked with Excel 2003) or
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", which I have found referenced on several sites as needed by Excel 2007. I've tried playing with combinations of file extensions and ContentType with no success. I did discover that the ContentType is ignored when .DOC file extension is specified; it will open Word, not Excel despite the ContentType indicated. So Excel apparently cares about the file format where Word does not. .HTM opens a new browser page, again regardless of whether ContentType is indicated.
I'm beginning to wonder whether overlaying MS Office 2003 with 2007 is the cause of the problem? In any case, our users are just going to have to live with another annoying message box. This is a minor hassle compared to other issues.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |