首页 新闻 会员 周边 捐助

紧急求助,Ajax调用NPOI组建导出无反应

0
悬赏园豆:30 [待解决问题]
急切请教一个问题 我是用NPOI组件 用来进行EXCEL导出操作 代码如下

问题: 我如果直接使用ASP.NET按钮控件调用 OnExcelOut 可以弹出导出的Excel文件没问题
问题是在我使用 JS的Ajax调用 OnExcelOut 方法的时候 就没有反映了。 着急中有大师帮忙解决一下吗?

using
System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Reflection; using System.IO; using NPOI.SS.UserModel; using NPOI.HSSF.UserModel; using NPOI.HPSF; namespace TRAIL.DbSalary.Example.View.Ajax { public partial class ExcelOutPut : System.Web.UI.Page { HSSFWorkbook hssfworkbook; protected void Page_Load(object sender, EventArgs e) { OnExcelOut(); } //主要就是这部分代码 public void OnExcelOut() {
          //***********************************
string filename = "test.xls";
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename));
            Response.Clear();

            InitializeWorkbook();
            GenerateData();
            Response.BinaryWrite(WriteToStream().GetBuffer());
            Response.End();
          //*********************************** }
private MemoryStream WriteToStream() { //Write the stream data of workbook to the root directory MemoryStream file = new MemoryStream(); hssfworkbook.Write(file); return file; } void GenerateData() { ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1"); sheet1.CreateRow(0).CreateCell(0).SetCellValue("This is a Sample"); int x = 1; for (int i = 1; i <= 15; i++) { IRow row = sheet1.CreateRow(i); for (int j = 0; j < 15; j++) { row.CreateCell(j).SetCellValue(x++); } } } void InitializeWorkbook() { hssfworkbook = new HSSFWorkbook(); ////create a entry of DocumentSummaryInformation DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation(); dsi.Company = "NPOI Team"; hssfworkbook.DocumentSummaryInformation = dsi; ////create a entry of SummaryInformation SummaryInformation si = PropertySetFactory.CreateSummaryInformation(); si.Subject = "NPOI SDK Example"; hssfworkbook.SummaryInformation = si; } } }
_大师兄_的主页 _大师兄_ | 初学一级 | 园豆:174
提问于:2012-10-26 14:38
< >
分享
所有回答(4)
0
 //主要就是这部分代码
hssfworkbook .Write(Response.OutputStream);

Response.Write(Response.OutputStream);

冉ran | 园豆:204 (菜鸟二级) | 2012-10-26 14:49
 Response.Clear();

            InitializeWorkbook();
            GenerateData();
            Response.BinaryWrite(WriteToStream().GetBuffer());
            Response.End();

(这部分替换掉)看行不。。。
支持(0) 反对(0) 冉ran | 园豆:204 (菜鸟二级) | 2012-10-26 14:52

@冉ran:

hssfworkbook .Write(Response.OutputStream);

感谢你的回答  不过这部分是NPOI的代码  还不能随便换掉。

支持(0) 反对(0) _大师兄_ | 园豆:174 (初学一级) | 2012-10-26 15:08
0

不能用ajax做下载,用location.href=xxx就行了

向往-SONG | 园豆:4853 (老鸟四级) | 2012-10-26 14:59

但是我有一个源码是可以进行调用的 也能正常进行弹出下载提示的。

支持(0) 反对(0) _大师兄_ | 园豆:174 (初学一级) | 2012-10-26 15:06

@_大师兄_: 贴一下 你的源码 看看

支持(0) 反对(0) sym_cn | 园豆:798 (小虾三级) | 2012-10-26 15:37
0

用ajax  应该是没触发到  Page_Load 事件,你跟断点看看..

jingjunfeng | 园豆:873 (小虾三级) | 2012-10-26 15:40

最好还是断点吧

支持(0) 反对(0) chenping2008 | 园豆:9836 (大侠五级) | 2012-10-26 22:29
0

不知前端代码是怎么样的?

网事 | 园豆:238 (菜鸟二级) | 2012-10-27 17:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册