我写了一个html文件:test.html
<body>
<a href="CreateExcel.ashx">下载Excel表格</a>
</body>
CreateExcel.ashx文件为:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS;
using NPOI.Util;
using System.Text
namespace ASP.Net中级.EX
{
/// <summary>
/// CreateExcel 的摘要说明
/// </summary>
public class CreateExcel : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/x-excel";
string filename = context.Server.UrlEncode("用户信息表.xls");
context.Response.AddHeader("Content-Disposition",
"attachment;filename="+filename);
//创建excel表格
HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet = workBook.CreateSheet("userInformation");
for(int i=0;i<10;i++)
{
HSSFRow row = sheet.CreateRow(i);
row.CreateCell(0, HSSFCell.CELL_TYPE_STRING).
SetCellValue(i.ToString()+"你好");
}
workBook.Write(context.Response.OutputStream);
}
public bool IsReusable
{
get
{
return false;
}
}
public bool EnableViewState { get; set; }
}
}
为什么我在test.htm中点击下载后的excel文档打开过后什么都没有呢?如图
急求解!
<body>
<a href="CreateExcel.ashx">下载Excel表格</a>
</body>
CreateExcel.ashx文件为:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using NPOI;
using NPOI.HPSF;
using NPOI.HSSF;
using NPOI.HSSF.UserModel;
using NPOI.POIFS;
using NPOI.Util;
using System.Text
namespace ASP.Net中级.EX
{
/// <summary>
/// CreateExcel 的摘要说明
/// </summary>
public class CreateExcel : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/x-excel";
string filename = context.Server.UrlEncode("用户信息表.xls");
context.Response.AddHeader("Content-Disposition",
"attachment;filename="+filename);
//创建excel表格
HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet = workBook.CreateSheet("userInformation");
for(int i=0;i<10;i++)
{
HSSFRow row = sheet.CreateRow(i);
row.CreateCell(0, HSSFCell.CELL_TYPE_STRING).
SetCellValue(i.ToString()+"你好");
}
workBook.Write(context.Response.OutputStream);
}
public bool IsReusable
{
get
{
return false;
}
}
public bool EnableViewState { get; set; }
}
}
为什么我在test.htm中点击下载后的excel文档打开过后什么都没有呢?如图
急求解!