1.4 POI简单写出Excel
代码部分:
package com.vintage.testpoi;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* POI入门 :简单写出excel数据
* @author VintageYu
*
*/
public class WriteExcelTest {
public static void write(OutputStream outputStream) throws IOException{
//初始一个workbook
HSSFWorkbook workbook = new HSSFWorkbook();
//创建一个表
HSSFSheet sheet = workbook.createSheet("firstSheet");
//创建行
HSSFRow row = sheet.createRow(0);
//创建单元格
HSSFCell cell = row.createCell(0);
cell.setCellValue(new HSSFRichTextString("hello POI"));
workbook.write(outputStream);
}
public static void main(String[] args) {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(new File("E:\\helloPOI.xls"));
write(outputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(outputStream != null){
try {