Exportar para Execel
Bom dia, preciso de um help, estou tentando exportar .xls em c#, engraçado que via localhost(Visual Studio) exportar, porém quando publico no servidor não exportar, segue o script:
c#
public static bool CreateExcelDocumentAsStream(DataSet ds, string filename, System.Web.HttpResponse Response)
{
try
{
System.IO.MemoryStream stream = new System.IO.MemoryStream();
using (SpreadsheetDocument document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true))
{
WriteExcelFile(ds, document);
}
stream.Flush();
stream.Position = 0;
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
// NOTE: If you get an "HttpCacheability does not exist" error on the following line, make sure you have
// manually added System.Web to this project's References.
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
Response.AddHeader("Content-Length", filename.Length.ToString());
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
byte[] data1 = new byte[stream.Length];
stream.Read(data1, 0, data1.Length);
//stream.Close();
//Response.WriteFile(filename);
Response.BinaryWrite(data1);
stream.Close();
Response.Flush();
Response.Close();
Response.End();
return true;
}catch (Exception ex)
{
Trace.WriteLine("Failed, exception thrown: " + ex.Message);
return false;
}
}
Alimenta form em JS
**JS**
function postAndRedirect(url, postData) {
var postFormStr = '<form method="POST" action=' + url + ' >\n';
for (var key in postData) {if (postData.hasOwnProperty(key)) {
postFormStr += '<input type="hidden" name=' + key + ' value=' + postData[key] + '></input>';
}
}
postFormStr += '</form>';
var formElement = $(postFormStr);
$('body').append(formElement);
$(formElement).submit();
}
Carrega o Object porem não alimenta o form, alguém pode me ajudar? Obrigado!Discussão (3)
Carregando comentários...