不知道下面这段代码是不是你想要的 ,这是把数据库的表导出到excel的创建excel的一部分代码
// 创建标题
HSSFRow titleRow = hssfSheet.createRow(0);
for(int i = 0 ; i < columnCount ; i++){
HSSFCell headCell = titleRow.createCell(i);
headCell.setCellStyle(headCellStyle);
headCell.setCellValue(new HSSFRichTextString(columnNames.get(i)));
}
// 创建正文样式
HSSFCellStyle bodyCellStyle = hssfWorkbook.createCellStyle();
HSSFFont bodyFont = hssfWorkbook.createFont();
bodyFont.setColor(Font.COLOR_NORMAL);
bodyFont.setBold(false);
bodyFont.setFontName("宋体");
bodyFont.setFontHeight((short) 250);
bodyCellStyle.setFont(bodyFont);
// 创建正文
try {
// 在 excel 中所在的行数
int columnRow = 1;
while(resultSet.next()){
HSSFRow bodyRow = hssfSheet.createRow(columnRow+