Bug 63624 - XWPFTableCell.setText() returns empty when no paragraph is created
Summary: XWPFTableCell.setText() returns empty when no paragraph is created
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-02 03:03 UTC by canbingzt
Modified: 2019-11-18 07:48 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description canbingzt 2019-08-02 03:03:19 UTC
If the cell has no paragraph, call XWPFTableCell.setText() , then call XWPFTableCell.getText(), the result is empty.
Comment 1 Dominik Stadler 2019-11-17 12:19:55 UTC
Can you provide some self-sufficient source code which reproduces this problem so it is easier for others to take a look?
Comment 2 canbingzt 2019-11-18 01:36:58 UTC
(In reply to Dominik Stadler from comment #1)
> Can you provide some self-sufficient source code which reproduces this
> problem so it is easier for others to take a look?

XWPFDocument doc = new XWPFDocument();
XWPFTable table = doc.createTable(1, 1);
XWPFTableRow row = table.getRow(0);
XWPFTableCell cell = row.getCell(0);

String expected = "this must not be empty";
cell.setText(expected);
String actual = cell.getText(); //actual is empty
Assert.assertEquals(expected, actual);


//under code work well
XWPFParagraph p;
if (cell.getParagraphs() == null || cell.getParagraphs().size() == 0) {
    p = cell.addParagraph();
} else {
    p = cell.getParagraphArray(0);
}
p.createRun().setText(text, 0);