<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
<%@ page contentType="application/vnd.ms-excel" language="java" import="java.util.*,com.shangyu.action.WriteExcel" pageEncoding="GBK"%><%
response.setHeader("Content-Disposition","attachment;filename=test123.xls");//指定下载的文件名
response.setContentType("application/vnd.ms-excel");
WriteExcel we=new WriteExcel();
we.getExcel("111.xls",response.getOutputStream());
%>
package com.shangyu.action;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
public class WriteExcel
{
public void getExcel(String sheetName,OutputStream output)
{
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet1=wb.createSheet("sheet1");
HSSFRow row=sheet1.createRow((short)0);
HSSFCell cell=row.createCell((short)0);
cell.setCellValue(1);
row.createCell((short)1).setCellValue(2);
row.createCell((short)2).setCellValue(3);
row.createCell((short)3).setCellValue("中文字符");
row=sheet1.createRow((short)1);
cell=row.createCell((short)0);
cell.setCellValue(1);
row.createCell((short)1).setCellValue(2);
row.createCell((short)2).setCellValue(3);
row.createCell((short)3).setCellValue("中文字符");
//FileOutputStream fileout=new FileOutputStream("workbook.xls");
try {
output.flush();
wb.write(output);
output.close();
} catch (IOException e) {
e.printStackTrace();
System.out.println( "Output is closed ");
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有