In Java, how to use HSSFSheet to create an excel template to create a column of two rows of data?

how to use HSSFSheet to create an excel, with one row and two columns as shown in the figure?
3FA869B9-7071-4714-80A2-AC63734AD0BA.jpg
clipboard.png

Mar.25,2021

try merging cells.


I don't know if the following code is what you want. It's part of the code that exports the tables of the database to excel's creation excel

.
    
     // 
    HSSFRow titleRow = hssfSheet.createRow(0);
    for(int  i = 0 ; i < columnCount ; iPP){
        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(columnRowPP); // 
            for(int i = 0; i < columnCount; iPP){   // 
                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();
    }
Menu