jsp提供excel下载

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="application/x-msexcel"%>
<%@ page import="java.text.*" %>
<%@ page import="java.text.DecimalFormat" %>
<%@ page import="java.io.*"%>
<%@ page import="org.apache.poi.hssf.usermodel.*"%>
<%@ page import="javax.servlet.ServletOutputStream"%>
<html>
<head>
    <title>企业所得税月(季)度预缴纳税申报表(A类)导出</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
</head>
  <body>
 <%
 
  FileInputStream input = new FileInputStream("C:/test.xls");
  HSSFWorkbook workbook = new HSSFWorkbook(input);
  HSSFSheet sheet = workbook.getSheetAt(0);
  HSSFRow row = sheet.getRow(2);
  HSSFCell cell = row.getCell((short)1);
  cell.setCellValue("dfsd");
  row = sheet.getRow(3);
  cell = row.getCell((short)1);
  cell.setCellValue("1111111");
  row = sheet.getRow(4);
  cell = row.getCell((short)1);
  cell.setEncoding(HSSFCell.ENCODING_UTF_16);//设置字符集
  cell.setCellValue("中文");
  ServletOutputStream output= null;
  response.reset();//不加的话可能会乱码
  response.setContentType("application/x-msexcel;charset=UTF-8");
  String fileName = "test";  
     String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");  
     response.setHeader("content-disposition", "attachment; filename=/""+codedFileName+".xls");
  try{
  output = response.getOutputStream();
  workbook.write(output);
  output.flush();
  }catch(Exception e){
   
  }finally{
   input.close();
   output.close();
  }
 %>
  </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hjay0715

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值