在Excel中生成报告 [英] generating report in excel

查看:93
本文介绍了在Excel中生成报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从jquery调用此Web服务. objFF.FieldHtml包含要在Excel文件中显示的html表. objFF.FieldName是文件名.现在,当从客户端调用此Web服务时,它会给出错误,例如{由于代码已优化或本机框架位于调用堆栈的顶部,因此无法评估表达式.}.
这是我的网络服务

i am calling this webservice from jquery. objFF.FieldHtml contains html table to exoprt in excel file. objFF.FieldName is filename. now when call this web service from client side then it give an error such as {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}.
this is my webservice

[WebMethod]
    [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
    public void ExportToExcel(FormFieldsInfo objFF)
    {
        try
        {
            //FormBuilderDataProvider.ExportToExcel(objFF);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();

            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + objFF.FieldName + "_" + DateTime.Now.ToString("M_dd_yyyy_H_M_s") + ".xls");
            HttpContext.Current.Response.ContentType = "text/xls";
            HttpContext.Current.Response.Write(objFF.FieldHtml);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
            //HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }



这是我的jquery函数



this is my jquery function

GetFormReport: function(fileName) {

                    var html = '<table><tr><th>Name</th><th>Age</th></tr><tr><td>shyam</td><td>27</td></tr><tr><td>sujan</td><td>30</td></tr><tr><td>dhrub</td><td>25</td></tr></table>';

                    var tableContent = {
                        FormFieldsInfo: { FieldHtml: html, FieldName: fileName }
                    }
                    this.config.method = "ExportToExcel";
                    this.config.url = this.config.baseURL + this.config.method;
                    this.config.data = JSON2.stringify({ "objFF": tableContent.FormFieldsInfo });
                    this.config.ajaxCallMode = 4;
                    this.ajaxCall(this.config);
                }

推荐答案

下面是解决此问题的简短说明和解决方法,


当我们在完成页面实际操作之前,在代码中使用Response.Redirect或Server.Transfer或Response.End时,通常会发生此错误.

在这种情况下,您要做的是

代替Response.End,您必须使用HttpContext.Current.ApplicationInstance.CompleteRequest

并使用Response.Redirect ("Paganame.aspx", false);
代替Response.Redirect
并使用Server.Execute
代替Server.Transfer
如果解决了您的问题,请标记为解决方案并投票.谢谢
Below is a small explanation and resolution to resolve this issue,


This error normally occurs when we use Response.Redirect or Server.Transfer or Response.End in your code before completing the actual process the page was doing.

In this case what you have to do is

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest

and in place of Response.Redirect, use the Response.Redirect ("Paganame.aspx", false);

and in place of Server.Transfer, use the Server.Execute

Please mark as the solution and vote if this solves your problem. Thanks


这篇关于在Excel中生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆