@Test
public void test8() throws IOException{
Workbook wb = new HSSFWorkbook();
CellRangeAddress cra = new CellRangeAddress(0,0,0,2);//合拼单元格
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);//单元格内文字水平位置
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//单元格内文字垂直位置
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);//画板
cellStyle.setFillForegroundColor(HSSFColor.RED.index);//前景色
cellStyle.setFillBackgroundColor(HSSFColor.BLUE.index);//背景色
Sheet sheet = wb.createSheet("hello");//创建工作表
sheet.addMergedRegion(cra);//设置合并的单元格
Row row = sheet.createRow(0);
font.setBoldweight(font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 16);
font.setColor(HSSFColor.BLACK.index);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue("hello world!");
FileOutputStream fos = new FileOutputStream("D://java/1.xls");
wb.write(fos);
fos.close();
wb.close();
}
public void test8() throws IOException{
Workbook wb = new HSSFWorkbook();
CellRangeAddress cra = new CellRangeAddress(0,0,0,2);//合拼单元格
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);//单元格内文字水平位置
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//单元格内文字垂直位置
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);//画板
cellStyle.setFillForegroundColor(HSSFColor.RED.index);//前景色
cellStyle.setFillBackgroundColor(HSSFColor.BLUE.index);//背景色
Sheet sheet = wb.createSheet("hello");//创建工作表
sheet.addMergedRegion(cra);//设置合并的单元格
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
//设置字体
font.setBoldweight(font.BOLDWEIGHT_BOLD);
font.setFontHeightInPoints((short) 16);
font.setColor(HSSFColor.BLACK.index);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue("hello world!");
FileOutputStream fos = new FileOutputStream("D://java/1.xls");
wb.write(fos);
fos.close();
wb.close();
}