I'm unable to read cell border attributes from existing document. The
purpose is to be able to insert new rows by cloning the cell attributes
(including border) so the newly inserted rows is styled similarly.
The following is what has been tried, the documentation does state that
some of the methods are for internal use, so there might be another method
to get at the attributes, the following is just test code:
public void logTableColours(List<XWPFTable> tables) {
for (XWPFTable table : tables) {
System.out.println("TABLE");
List<XWPFTableRow> rows = table.getRows();
for (XWPFTableRow row : rows) {
System.out.println("ROW");
List<XWPFTableCell> tableCells = row.getTableCells();
for (XWPFTableCell cell : tableCells) {
System.out.println("CELL");
CTTc ctTc = cell.getCTTc();
CTTcPr tcPr = ctTc.addNewTcPr();
CTTcBorders tcBorders = tcPr.addNewTcBorders();
CTBorder bottom = tcBorders.getBottom();
CTBorder left = tcBorders.getLeft();
CTBorder top = tcBorders.getTop();
CTBorder right = tcBorders.getRight();
logTableCellBorder(bottom);
logTableCellBorder(left);
logTableCellBorder(top);
logTableCellBorder(right);
}
}
}
}
public void logTableCellBorder(CTBorder tcBorder) {
if(tcBorder == null){
System.out.println("tcBorder is null");
return;//THIS ALWAYS RETURNS
}
//todo: see what tcBorder.dump() does
Object color = tcBorder.getColor();//causes NPE!
if (color != null) {
System.out.println("colour:" + new
JSONSerializer().serialize(color));
}
STOnOff.Enum frame = tcBorder.getFrame(); //causes NPE!
System.out.println("frame: " + frame);
STOnOff.Enum shadow = tcBorder.getShadow(); //causes NPE
System.out.println("shadow: " + shadow);
BigInteger space = tcBorder.getSpace();//causes NPE
System.out.println("space: " + space);
BigInteger sz = tcBorder.getSz();//causes NPE
System.out.println("sz: " + sz);
//Object themeColor;
//TODO: Find the proper include for the following...
//org.openxmlformats.schemas.wordprocessingml.x2006.main.STThemeColor.Enum
themeColor = tcBorder.getThemeColor();
//System.out.println("themeColor: " + tcBorder.);
byte[] themeShade = tcBorder.getThemeShade();
System.out.println("themeShade: " + Arrays.toString(themeShade));
byte[] themeTint = tcBorder.getThemeTint();
System.out.println("themeTint: " + Arrays.toString(themeTint));
STBorder.Enum val = tcBorder.getVal();
System.out.println("val: " + val);
}
}
----------------------------------
Any help at getting that the attributes in the CTBorder would be great. In
the above code CTBorder is always null...