Я пытаюсь объединить ячейки в сгенерированной таблице, чтобы иметь эффект, отображаемый на изображении. i.sstatic.net/nstjhmrp.png " /> < /p>
Как я могу объединить ячейки для этой цели в приложении Java, которое использует Apache POI для генерации файла .docx? Пробовал разные комбинации, но не получили ожидаемого эффекта.
Как только ячейки объединяются при добавлении длительного текста, он должен охватывать все объединенные ячейки, не используя одну область ячейки.
текущий выход
исходный блок
// Add Reservation Details Header
XWPFParagraph reservationDetailsHeader = document.createParagraph();
XWPFRun reservationDetailsRun = reservationDetailsHeader.createRun();
reservationDetailsRun.setText("Reservation Details");
reservationDetailsRun.setFontFamily("DejaVu Serif");
reservationDetailsRun.setFontSize(12);
reservationDetailsRun.setBold(true);
// Add a line space below the header
addLineSpace(document);
// Create a new table for Reservation Details
XWPFTable reservationDetailsTable = document.createTable();
// First row with four columns
XWPFTableRow reservationRow1 = reservationDetailsTable.getRow(0);
reservationRow1.getCell(0).setText("Check-In Date:");
reservationRow1.getCell(1).setText("2024-12-20"); // Sample date
reservationRow1.getCell(2).setText("No Of Nights :");
reservationRow1.getCell(3).setText("1");
// Second row with four columns
XWPFTableRow reservationRow2 = reservationDetailsTable.createRow();
reservationRow2.getCell(0).setText("Check-Out Date:");
reservationRow2.getCell(1).setText("2024-12-22"); // Sample date
reservationRow2.getCell(2).setText("No Of Rooms :");
reservationRow2.getCell(3).setText("1");
// Third row with 2 columns
XWPFTableRow reservationRow3 = reservationDetailsTable.createRow();
reservationRow3.getCell(0).setText("Room Type Per Rate:");
reservationRow3.getCell(4).getCTTc().addNewTcPr().addNewGridSpan().setVal(BigInteger.valueOf(5));
reservationRow3.getCell(3).getCTTc().addNewTcPr().addNewGridSpan().setVal(BigInteger.valueOf(4));
reservationRow3.getCell(2).getCTTc().addNewTcPr().addNewGridSpan().setVal(BigInteger.valueOf(3));
reservationRow3.getCell(1).getCTTc().addNewTcPr().addNewGridSpan().setVal(BigInteger.valueOf(2));
reservationRow3.getCell(1).setText("Traditional Room (max occ. 2) - 1 King/Static");
зависимости
org.apache.poi
poi-ooxml
5.2.5
org.apache.poi
poi-ooxml-schemas
4.1.2
org.apache.xmlbeans
xmlbeans
5.1.1
org.apache.logging.log4j
log4j-core
2.20.0
Подробнее здесь: https://stackoverflow.com/questions/792 ... apache-poi