poi写出excel

用的 poi-3.6 的jar包
package com.demo;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;



public class Test
{
	public static void main(String[] args)
	{
		
		try
		{
			Workbook wb = new HSSFWorkbook();
			FileOutputStream fileOut = new FileOutputStream("测试表.xls");
			//wb.write(fileOut);
			//fileOut.close();
			
			Sheet sheet1 = wb.createSheet("shit1");
			Sheet sheet2 = wb.createSheet("shit2");
			
			/*Row row1 = sheet1.createRow(0);
			Row row2 = sheet1.createRow(3);
			Cell cell1 = row1.createCell(0);
			Cell cell2 = row1.createCell(2);
			cell1.setCellValue("cell1的值");
			cell2.setCellValue("cell2的值");*/
			
			
			Row row = null;
			for(int i=0; i<5; i++)
			{
				row = sheet1.createRow(i);
				row.createCell(0).setCellValue("这什么");
				row.createCell(1).setCellValue("那什么");
				row.createCell(2).setCellValue("到底什么");
				row.createCell(3).setCellValue("什么什么");
			}
			//上面的例子说明,可以重复使用同一个row变量。
			
			
			wb.write(fileOut);
			fileOut.close();
			
			
		}
		catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}
}

你可能感兴趣的:(Excel)