I need to have a table with the cells on the first and second row merged.
Something like this:
Image of table (I can't post pics) http://i.stack.imgur.com/dAO6j.png
I have been reviewing all the questions related to this topic and I have found some answers for applying grid span to the cells, but I couldn't find a real solution.
Here is the code I have from examples obtained from google and from this site:
XWPFDocument document = new XWPFDocument();
XWPFTable table = document.createTable(7, 2);
fillTable(table);
XWPFTableCell cellRow1 = table.getRow(0).getCell(0);
XWPFTableCell cellRow2 = table.getRow(1).getCell(0);
cellRow1.getCTTc().addNewTcPr();
cellRow1.getCTTc().getTcPr().addNewGridSpan();
cellRow1.getCTTc().getTcPr().getGridSpan().setVal(BigInteger.valueOf(2L));
cellRow2.getCTTc().addNewTcPr();
cellRow2.getCTTc().getTcPr().addNewGridSpan();
cellRow2.getCTTc().getTcPr().getGridSpan().setVal(BigInteger.valueOf(2L));
FileOutputStream out = new FileOutputStream("Table.docx");
doc.write(out);
out.close();
What I get from this code is the following:
I tried to remove the "extra" cells with table.getRow(0).removeCell(1);
but it didn't work, am I doing something wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…