views:

1023

answers:

3

I've got a silverlight 2 app with a Datagrid and a button for exporting it to Excel by making a trip back to the server.

I can create an HTML string representing the datagrid. I'd like to attach this string to an html element, setting MIME type=application/vnd.ms-excel and have a prompt show up asking if I'd like to open or save the xls file.

After all if ASP can do this ...

<% The main feature of this technique is that %>  
<% you have to change Content type to ms-excel.%>

Response.ContentType = "application/vnd.ms-excel"
<TABLE>  
<TR><TD>2</TD></TR>  
<TR><TD>3</TD></TR>  
<TR><TD>=SUM(A1:A2)</TD></TR>  
</TABLE>

... it seems like I should be able to do something similar from within Silverlight, pushing it onto the HTML DOM.

Any suggestions greatly appreciated!

+1  A: 

Nope that isn't going to happen. You are going to need to get the browser to fetch something from the server that your SL has posted.

You can only write HTML to a browser hosted document when the browser has created the document as a HTML DOM. Hence you can't convince the browser that the stream of text you are writing is another document type like an Excel spreadsheet.

AnthonyWJones
Thanks. I see what you're saying, was hoping there's an undocumented feature. Maybe they could overload HtmlPage.PopupWindow to have it accept an html string inline, at least with IE since they own it. I guess lawyers might cry foul though.Conceptually similar to what this guy's wanting ...http://bytes.com/groups/javascript/93938-create-excel-spreadsheet-javascript
Kirk Kuykendall
+1  A: 

You can always copy the content of the datagrid to the users clipboard using javascript (just create a 'copy to clipboard' button) and then allow them to paste it into their own spreadsheet (just did this for a client, and they were pretty happy with the solution.) I can post code if you need.

Jason Watts
A: 

Here's a nice approach that worked for me http://forums.silverlight.net/forums/p/179321/404357.aspx

Fedor