@global-format
The API Worksheet.GetPrintingPageBreaks(ImageOrPrintOptions options)
can get page breaks for each page, and the API Cell.GetHeightOfValue()
can evaluate text height in cell. You can try the following code to check if the text in the merged cell goes to next page.
Workbook wb = new Workbook("pagebreak-demo.xlsx");
Worksheet worksheet = wb.getWorksheets().get(0);
worksheet.getCells().insertRows(76, 20);
Cell commentCell = worksheet.getCells().get(75, 2);
commentCell.setHtmlString("Das<br>"
+ "ist000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000033333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444455555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777788888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999<br>"
+ "ein<br>" + "text<br>" + "mit<br>" + "vielen<br>" + "Zeilen<br>" + "die<br>" + "angezeigt<br>" + "sein<br>" + "wollen.<br>" + "Besonders<br>" + "dann<br>"
+ "wenn <br>" + "der <br>" + "Text<br>" + "auf<br>" + "mehrere<br>" + "Seiten<br>" + "verteilt<br>" + "wird<br>");
//evaluate text height in cell
int textHeight = commentCell.getHeightOfValue();
//get page breaks of the sheet.
CellArea[] cellAreas = worksheet.getPrintingPageBreaks(new ImageOrPrintOptions() { });
int endRowOfPage0 = cellAreas[0].EndRow;
double rowHeightInPage0 = 0;
//Your Merged Cell starts from Row 75(zero based)
for(int row = 75; row <= endRowOfPage0; row++)
{
rowHeightInPage0 += worksheet.getCells().getRowHeight(row);
}
//text in merged cell goes to next page
if(textHeight > rowHeightInPage0)
{
//do work to split text here
//But it seems that there is no good way to get the accurate position where the text needs to be split.
//...
}
wb.save("pagebreak-demo.out.xlsx", SaveFormat.XLSX);
wb.save("pagebreak-demo.out.pdf", new PdfSaveOptions());
But it seems that there is no good way to get the accurate position where the text needs to be split.