---
title: "POI导出excel"
author: "touch_mai"
date: "2010-02-21T17:04:32Z"
tags: [".net", "Excel", "Java", "工作"]
categories: ["编程语言"]
slug: "poi-excel"
draft: false
lastmod: "2010-03-07T17:42:28Z"
id: 599617
url: "https://touch-mai.iteye.com/blog/599617"
---

java中导出Excel有两个组件可以使用，一个是jxl，一个是POI，我这里用的是POI

注意：在excel2007版本之前 一个工作簿 最多 只能 拥有6万多条数据 以后版本 就没有这个问题了！

//导出excel方法
public String importE(){
//生成提示信息，
		this.getResponse().setContentType("application/vnd.ms-excel");
String codedFileName = java.net.URLEncoder.encode("中文", "UTF-8");//进行转码，使其支持中文文件名
		this.getResponse().addHeader("Content-Disposition","attachment;   filename="+codedFileName );    

			HSSFWorkbook workbook = new HSSFWorkbook(); //产生工作簿对象
			HSSFSheet sheet = workbook.createSheet(); //产生工作表对象
				HSSFRow row = sheet.createRow((short)0);//创建一行
				HSSFCell cell = row.createCell((short) 0);//创建一列
				cell.setCellType(HSSFCell.CELL_TYPE_STRING);
				cell.setCellValue("测试成功");
			FileOutputStream fOut;
			try {
				fOut = this.getResponse.getOutputStream();				workbook.write(fOut);
				fOut.flush();
				fOut.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			System.out.println("文件生成...");
	
			
			return NONE;
		}