Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to create a sandboxed webpart to export data from another webpart within the webpart page to excel.

I tried using the Excel ActiveXObject in a client side script but it requires this META tag to be added -

<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="application/vnd.ms-excel">

How can I get this script to work? Alternatively are there any other solutions?

Note that it is enough if the solution works only in IE but I cannot change the security settings.

share|improve this question

1 Answer 1

The metadata mentioned is merely to specify what kind of content the stream has, it is also used when trying to download a file, by example, more here http://www.w3schools.com/tags/att_meta_http_equiv.asp.

Use it in the HEAD section of your page, as in:

<head>
<meta http-equiv="Content-Type" content="application/vnd.ms-excel">
<meta http-equiv="Content-disposition": attachment; filename="file.xls">
</head>

In code however you use it as such

 HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader(
        "content-disposition", string.Format("attachment; filename={0}", fileName));
        HttpContext.Current.Response.ContentType = "application/ms-excel";
        HttpContext.Current.Response.Write("<head><meta http-equiv=Content-Type content=:" + '"' + "text/html; charset=utf-8" + '"' + "></head>");

//BUILD YOUR STRING HERE

HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();

Not sure about alternative just yet, i shall investigate on that direction.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.