[英]Cell values not getting set for newly added rows : using apache poi
I have a table in a ppt slide. 我在ppt幻灯片中有一张桌子。 Data to the table will be read from an ArrayList
(Each object in the ArrayList
will contain one row data) of String[]
. 数据表中将从被读取ArrayList
(每个中的对象ArrayList
将包含一个行数据)的String[]
If the number of rows in the table is less than the size of the ArrayList
, new rows will be added to match the size of the ArrayList
. 如果表中的行数小于ArrayList
的大小,则将添加新行以匹配ArrayList
的大小。
Problem here is data is getting set for already existing rows but not for the newly added rows. 这里的问题是为现有的行设置数据,而不是为新添加的行设置数据。 Please find the code snippet below. 请在下面找到代码段。
Any help/suggestion is much appreciated. 任何帮助/建议,我们将不胜感激。 Thanks in advance. 提前致谢。
XSLFTable table = (XSLFTable) shape;
int noOfDataRows=table.getNumberOfRows()-1;
if(noOfDataRows<ap.size()) {
for(int rws=0;rws<(ap.size()- noOfDataRows);rws++) {
System.out.println(" Adding row");
table.addRow();
}
}
List<XSLFTableRow> rows = table.getRows();
for (int i = 0; i < ap.size(); i++) {
String[] awaitprop={'1','2','3','4','5','6','7','8'};
XSLFTableRow row=rows.get(i+1);
List<XSLFTableCell> cells=row.getCells();
for(int j=0;j<cells.size();j++) {
XSLFTableCell cell=cells.get(j);
cell.clearText();
XSLFTextParagraph paragraph=cell.addNewTextParagraph();
paragraph.setTextAlign(TextAlign.CENTER);
XSLFTextRun textRun=paragraph.addNewTextRun();
textRun.setFontFamily("Calibri");
textRun.setFontSize(11);
textRun.setText(awaitprop[j]);
}
}
With reference to following tutorial , at first you should create cell(s) in the new row, I guess. 我想参考以下教程 ,首先应该在新行中创建单元格。 Then you can put a content there. 然后,您可以在其中放置内容。
XSLFTableRow headerRow = table.addRow();
for(int i = 0; i < 3; i++) {
XSLFTableCell th = headerRow.addCell();
XSLFTextParagraph p = th.addNewTextParagraph();
XSLFTextRun r = p.addNewTextRun();
r.setText("Text");
}
I hope it helps! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.