use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class XWPFFootnote method insertNewTbl.
/**
* @param cursor
* @return the inserted table
* @see org.apache.poi.xwpf.usermodel.IBody#insertNewTbl(XmlCursor cursor)
*/
public XWPFTable insertNewTbl(XmlCursor cursor) {
if (isCursorInFtn(cursor)) {
String uri = CTTbl.type.getName().getNamespaceURI();
String localPart = "tbl";
cursor.beginElement(localPart, uri);
cursor.toParent();
CTTbl t = (CTTbl) cursor.getObject();
XWPFTable newT = new XWPFTable(t, this);
cursor.removeXmlContents();
XmlObject o = null;
while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
o = cursor.getObject();
}
if (!(o instanceof CTTbl)) {
tables.add(0, newT);
} else {
int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
tables.add(pos, newT);
}
int i = 0;
cursor = t.newCursor();
while (cursor.toPrevSibling()) {
o = cursor.getObject();
if (o instanceof CTP || o instanceof CTTbl)
i++;
}
bodyElements.add(i, newT);
XmlCursor c2 = t.newCursor();
cursor.toCursor(c2);
cursor.toEndToken();
c2.dispose();
return newT;
}
return null;
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class XWPFFootnote method init.
private void init() {
XmlCursor cursor = ctFtnEdn.newCursor();
//copied from XWPFDocument...should centralize this code
//to avoid duplication
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
}
cursor.dispose();
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class XWPFHeader method onDocumentRead.
/**
* reads the document
*
* @throws IOException
*/
@Override
protected void onDocumentRead() throws IOException {
super.onDocumentRead();
HdrDocument hdrDocument = null;
InputStream is = null;
try {
is = getPackagePart().getInputStream();
hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
headerFooter = hdrDocument.getHdr();
// parse the document with cursor and add
// the XmlObject to its lists
XmlCursor cursor = headerFooter.newCursor();
cursor.selectPath("./*");
while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject();
if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, this);
paragraphs.add(p);
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
tables.add(t);
bodyElements.add(t);
}
if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
bodyElements.add(c);
}
}
cursor.dispose();
} catch (XmlException e) {
throw new POIXMLException(e);
} finally {
if (is != null) {
is.close();
}
}
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testSetGetHBorders.
public void testSetGetHBorders() {
// instantiate the following classes so they'll get picked up by
// the XmlBean process and added to the jar file. they are required
// for the following XWPFTable methods.
CTTblBorders cttb = CTTblBorders.Factory.newInstance();
assertNotNull(cttb);
STBorder stb = STBorder.Factory.newInstance();
assertNotNull(stb);
// create a table
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
XWPFTable table = new XWPFTable(ctTable, doc);
// set inside horizontal border
table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
// get inside horizontal border components
int s = table.getInsideHBorderSize();
assertEquals(4, s);
int sp = table.getInsideHBorderSpace();
assertEquals(0, sp);
String clr = table.getInsideHBorderColor();
assertEquals("FF0000", clr);
XWPFBorderType bt = table.getInsideHBorderType();
assertEquals(XWPFBorderType.SINGLE, bt);
}
use of org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl in project poi by apache.
the class TestXWPFTable method testSetGetWidth.
public void testSetGetWidth() {
XWPFDocument doc = new XWPFDocument();
CTTbl table = CTTbl.Factory.newInstance();
table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
XWPFTable xtab = new XWPFTable(table, doc);
assertEquals(1000, xtab.getWidth());
xtab.setWidth(100);
assertEquals(100, table.getTblPr().getTblW().getW().intValue());
}
Aggregations