日期:2014-05-20  浏览次数:20743 次

POI如何合并EXCEL单元格后,并在合并后的单元格上写上BACK
RT

------解决方案--------------------
HSSFRow
看看API
可以合并的
------解决方案--------------------
public class MergCell {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet( "new sheet ");

HSSFRow row = sheet.createRow((short) 1);
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue( "This is a test of merging ");

for(int i = 0; i < 10; i++){
sheet.addMergedRegion(new Region(i,(short)1,i,(short)2));
}

HSSFSheet sheet1 = wb.createSheet( "row sheet ");
sheet1.setSelected(true);


// Write the output to a file
try {
FileOutputStream fileOut = new FileOutputStream( "workbook.xls ");
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();
}

}