poi中 
// 定义单元格为字符串类型
// 创建新的Excel 工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
//在Excel工作簿中建一工作表
HSSFSheet sheet = null;
String sheetName = excel.getSheetName();
if(sheetName!=null)sheet=workbook.createSheet(sheetName);
else sheet=workbook.createSheet();
//列表头宽度
int[] width = excel.getWidth();

//设置表头字体
HSSFFont font_title = workbook.createFont();
font_title.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font_title.setFontHeight((short) 600);
//设置格式
HSSFCellStyle cellStyleTitle= workbook.createCellStyle();
cellStyleTitle.setFont(font_title);
cellStyleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//在索引0的位置创建行(第一行)
HSSFRow rowTitle = sheet.createRow((short)0);
rowTitle.setHeight((short) 750);
//合并标题单元格
sheet.addMergedRegion(new Region(0,(short) 0, 0,(short)(width.length-1)));
if (sheetName!=null){
//在索引0的位置创建单元格(左上端)
HSSFCell cell = rowTitle.createCell((short)0);
// 定义单元格为字符串类型
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//设置单元格的格式
cell.setCellStyle(cellStyleTitle);
// 在单元格中写入表头信息
cell.setCellValue(sheetName); 
} //设置表头字体
HSSFFont font_h = workbook.createFont();
font_h.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//设置格式
HSSFCellStyle cellStyle= workbook.createCellStyle();
cellStyle.setFont(font_h);
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyle.setBorderLeft((short) 1);
cellStyle.setBorderRight((short) 1);
cellStyle.setBorderTop((short) 1);
cellStyle.setBorderBottom((short) 1);

//在索引0的位置创建行(第2行)
HSSFRow row = sheet.createRow((short)1);

ArrayList header = excel.getHeader();
if(header!=null){
for(int i=0;i<header.size();i++){
//在索引0的位置创建单元格(左上端)
HSSFCell cell = row.createCell((short)i);
// 定义单元格为字符串类型
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
//设置解码方式
//cell.set.setEncoding((short)1);
//设置单元格的格式
cell.setCellStyle(cellStyle);

// 在单元格中写入表头信息
cell.setCellValue((String)header.get(i));  
    }
}
if (width.length!=0){
for (int i=0;i<width.length;i++)
sheet.setColumnWidth(i, width[i]);
}
//设置格式
HSSFCellStyle cellStyle1= workbook.createCellStyle();
cellStyle1.setBorderLeft((short) 1);
cellStyle1.setBorderRight((short) 1);
cellStyle1.setBorderTop((short) 1);
cellStyle1.setBorderBottom((short) 1);
            ArrayList cdata = excel.getData();
            for (int i=0;i<cdata.size();i++){
            //从第3行开始
            HSSFRow row1 = sheet.createRow(i+2);
            ArrayList rdata =(ArrayList)cdata.get(i);
            //打印一行数据
            for (int j=0;j<rdata.size();j++){
                  HSSFCell cell = row1.createCell( (short)j);
                  cell.setCellStyle(cellStyle1);
                  cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                  //设置字符编码方式
//                  cell.setEncoding((short)1);                  
                  Object o = rdata.get(j);                  
                  //造型,使写入到表中的数值型对象恢复为数值型,
                  //这样就可以进行运算了
                  if(o instanceof BigDecimal){
                      BigDecimal b=(BigDecimal)o;
                      cell.setCellValue(b.doubleValue());
                  }
                  else if(o instanceof Integer){
                         Integer it =(Integer)o;
                         cell.setCellValue(it.intValue());
                         
                  }
                  else if(o instanceof Long){
                      Long l =(Long)o;
                      cell.setCellValue(l.intValue());
                      
                  }
                  else if(o instanceof Double){
                      Double d =(Double)o;
                      cell.setCellValue(d.doubleValue());
                  }
                  else if(o instanceof Float){
                      Float f = (Float)o;
                      cell.setCellValue(f.floatValue());
                  }
                  else{
                      cell.setCellValue(o+"");
                  }                  
              }
             }
         return workbook;