首先,说下应用场景 就是,把页面呈现的Table 导出到Excel中。其中使用的原理是 前台使用ajax调用aspx后台,传递过去参数值,导出。使用的组件是NPOI。

  前台调用:

<script type="text/javascript">
        function toExcel() {
            post("../TableToExcel.aspx", { act: 'tabletoexcel', html: $('#excelTable').html() });
        }
        function post(URL, PARAMS) {
            var temp = document.createElement("form");
            temp.action = URL;
            temp.method = "post";
            temp.style.display = "none";
            for (var x in PARAMS) {
                var opt = document.createElement("textarea");
                opt.name = x;
                opt.value = PARAMS[x];
                temp.appendChild(opt);
            }
            document.body.appendChild(temp);
            temp.submit();
            return temp;
        }
    </script>
View Code

相关文章: