用java做出两行三列的表格_Java中,使用HSSFSheet创建excel模板如何创建一列两行的数据?...
不知道下面這段代碼是不是你想要的 ,這是把數(shù)據(jù)庫(kù)的表導(dǎo)出到excel的創(chuàng)建excel的一部分代碼
// 創(chuàng)建標(biāo)題
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)));
}
// 創(chuàng)建正文樣式
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);
// 創(chuàng)建正文
try {
// 在 excel 中所在的行數(shù)
int columnRow = 1;
while(resultSet.next()){
HSSFRow bodyRow = hssfSheet.createRow(columnRow++); // 創(chuàng)建行對(duì)象
for(int i = 0; i < columnCount; i++){ // 設(shè)置行對(duì)象中的每一個(gè)單元格的值
HSSFCell bodyCell = bodyRow.createCell(i);
bodyCell.setCellStyle(bodyCellStyle);
bodyCell.setCellValue(new
HSSFRichTextString(resultSet.getString(columnNames.get(i))));
}
}
OutputStream writer = new FileOutputStream(path);
hssfWorkbook.write(writer);
} catch (SQLException e) {
isSuccess = false;
e.printStackTrace();
} catch (IOException e) {
isSuccess = false;
e.printStackTrace();
}
總結(jié)
以上是生活随笔為你收集整理的用java做出两行三列的表格_Java中,使用HSSFSheet创建excel模板如何创建一列两行的数据?...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java 气泡聊天消息_CSS3 巧妙实
- 下一篇: Java循环添加文件_java – 使