JAVA利用poi如何向excel已合并的单元格中写入内容?

2024-12-29 14:02:11
推荐回答(1个)
回答1:

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");

HSSFRow row = sheet.createRow((short) 1);
HSSFCell cell = row.createCell((short) 1);

HSSFRichTextString content = new HSSFRichTextString("This is a test of message");
cell.setCellValue(content);

sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));

FileOutputStream fileOut = new FileOutputStream("d:/Demo_02_05.xls");
wb.write(fileOut);
fileOut.close();