Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未为新添加的行设置单元格值:使用apache poi_Java_Apache Poi - Fatal编程技术网

Java 未为新添加的行设置单元格值:使用apache poi

Java 未为新添加的行设置单元格值:使用apache poi,java,apache-poi,Java,Apache Poi,我有一张ppt幻灯片中的桌子。表中的数据将从字符串[]的ArrayList(ArrayList中的每个对象将包含一行数据)中读取 如果表中的行数小于ArrayList的大小,将添加新行以匹配ArrayList的大小 这里的问题是数据是为已经存在的行设置的,而不是为新添加的行设置的。请在下面找到代码片段 非常感谢您的任何帮助/建议。提前谢谢 XSLFTable table = (XSLFTable) shape; int noOfDataRows=table.getNumberOfRows()-1

我有一张ppt幻灯片中的桌子。表中的数据将从
字符串[]
ArrayList
(ArrayList中的每个对象将包含一行数据)中读取

如果表中的行数小于
ArrayList
的大小,将添加新行以匹配
ArrayList
的大小

这里的问题是数据是为已经存在的行设置的,而不是为新添加的行设置的。请在下面找到代码片段

非常感谢您的任何帮助/建议。提前谢谢

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]);
    }   
}
xslttable table=(xslttable)形状;
int noOfDataRows=table.getNumberOfRows()-1;

如果(noOfDataRows参考以下内容,我想首先您应该在新行中创建单元格。然后您可以将内容放在那里

    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");
    }
xsltablerow headerRow=table.addRow();
对于(int i=0;i<3;i++){
xsltablecell th=headerRow.addCell();
xslftexttraphy p=th.addnewtexttraphy();
XSLFTextRun r=p.addNewTextRun();
r、 setText(“文本”);
}

我希望有帮助!

对于新行,您不需要添加一些单元格吗?