I have been struggling with this for a while now. I have a paged grid, so instead of exporting directly, I create a temporary grid, setting header, filter and sorting the same way as the real grid, grabbing the data through a .NET connector. The data seem to be loaded okay, I have the right number of columns and right number of rows when I get the onXLE event, and the XML is well formed, I tested it on one of the online validators. After that I call
myGrid.toExcel("http://localhost/Utility/Handlers/Generate.ashx");
Problem is the returning stream is only 588 bytes long… I tried using
“http://dhtmlxgrid.appspot.com/export/excel”
instead, I don’t even get a returning file from that address. I can call that address using my original grid with 50 rows and it creates a file ok. The data only have 583 rows, so it is not an extremely large file.
Should the code somehow be waiting for the file to be generated, if so how to do that?
The handler looks like this:
<%@ WebHandler Language="C#" CodeBehind="Generate.ashx.cs" Class="Utility.Handlers.Generator" %>
using System.Web;
using DHTMLX.Export.Excel;
namespace Utility.Handlers
{
public class Generator : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
var writer = new ExcelWriter();
context.Response.ContentType = writer.ContentType;
context.Response.HeaderEncoding = System.Text.Encoding.UTF8;
context.Response.AppendHeader("Content-Disposition", "attachment;filename=grid.xlsx");
context.Response.AppendHeader("Cache-Control", "max-age=0");
var xml = context.Request.Form["grid_xml"];
xml = context.Server.UrlDecode(xml);
var stream = writer.Generate(xml);
stream.WriteTo(context.Response.OutputStream);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}