Java对poi操作生成Excel表

package com.ddy.java_test;


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


import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;


/**
 * 
 * 名称: PoiTest 
 * 描述: TODO
 * 类型: JAVA
 * 最近修改时间: 2013年12月10日 下午3:31:30
 * @since  2013年12月10日
 * @author daidongyang
 */
public class PoiTest {
@SuppressWarnings("deprecation")
public static void main(String[] args) {

//初始化一个workbook
HSSFWorkbook wb = new HSSFWorkbook();

//初始化表格样式
HSSFCellStyle style = wb.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//左右居中
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//上下居中

//创建工作表
HSSFSheet sheet = wb.createSheet();
//设定单元格默认宽度
sheet.setDefaultColumnWidth(10);
//高度没有找到方法?????

//创建行一
  HSSFRow Row = sheet.createRow(0);
  //创建行一的列一
  HSSFCell cell1 = Row.createCell(0);
  HSSFCell cell2 = Row.createCell(1);
  //添加style
cell1.setCellStyle(style);
cell2.setCellStyle(style);

cell1.setCellValue("成绩常用指标统计结果");//插入Value

//合并单元格--横向
sheet.addMergedRegion(new Region(0,(short)0, 0, (short)1));

//竖向合并:sheet.addMergedRegion(new Region(0,(short)0, 6, (short)0));
try {
FileOutputStream fileOut = new FileOutputStream("c:\\结果.xls ");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
System.out.println("导出成功!");
}


}

你可能感兴趣的:(java,poi,java,excel)