Fix and update JavaDoc entries, and correct areas with wildy inconsistent whitespace / style to the surrounding code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1492804 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2013-06-13 18:34:54 +00:00
parent 5863a82a6e
commit ab19d2e09c
4 changed files with 661 additions and 682 deletions

View File

@ -41,121 +41,118 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
/** /**
* Looks after the collection of Footnotes for a document * Looks after the collection of Footnotes for a document
*
* @author Mike McEuen (mceuen@hp.com)
*/ */
public class XWPFFootnotes extends POIXMLDocumentPart { public class XWPFFootnotes extends POIXMLDocumentPart {
private List<XWPFFootnote> listFootnote = new ArrayList<XWPFFootnote>(); private List<XWPFFootnote> listFootnote = new ArrayList<XWPFFootnote>();
private CTFootnotes ctFootnotes; private CTFootnotes ctFootnotes;
protected XWPFDocument document; protected XWPFDocument document;
/** /**
* Construct XWPFFootnotes from a package part * Construct XWPFFootnotes from a package part
* *
* @param part the package part holding the data of the footnotes, * @param part the package part holding the data of the footnotes,
* @param rel the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" * @param rel the package relationship of type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"
*/ */
public XWPFFootnotes(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{ public XWPFFootnotes(PackagePart part, PackageRelationship rel) throws IOException, OpenXML4JException{
super(part, rel); super(part, rel);
}
/**
* Construct XWPFFootnotes from scratch for a new document.
*/
public XWPFFootnotes() {
}
/**
* Read document
*/
@Override
protected void onDocumentRead () throws IOException {
FootnotesDocument notesDoc;
try {
InputStream is = getPackagePart().getInputStream();
notesDoc = FootnotesDocument.Factory.parse(is);
ctFootnotes = notesDoc.getFootnotes();
} catch (XmlException e) {
throw new POIXMLException();
} }
/** //get any Footnote
* Construct XWPFFootnotes from scratch for a new document. for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
*/ listFootnote.add(new XWPFFootnote(note, this));
public XWPFFootnotes() {
} }
}
/** @Override
* Read document protected void commit() throws IOException {
*/ XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
@Override xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
protected void onDocumentRead () throws IOException { Map<String,String> map = new HashMap<String,String>();
FootnotesDocument notesDoc; map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
try { map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
InputStream is = getPackagePart().getInputStream(); xmlOptions.setSaveSuggestedPrefixes(map);
notesDoc = FootnotesDocument.Factory.parse(is); PackagePart part = getPackagePart();
ctFootnotes = notesDoc.getFootnotes(); OutputStream out = part.getOutputStream();
} catch (XmlException e) { ctFootnotes.save(out, xmlOptions);
throw new POIXMLException(); out.close();
} }
//get any Footnote
for(CTFtnEdn note : ctFootnotes.getFootnoteList()) {
listFootnote.add(new XWPFFootnote(note, this));
}
}
@Override
protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
Map<String,String> map = new HashMap<String,String>();
map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
xmlOptions.setSaveSuggestedPrefixes(map);
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
ctFootnotes.save(out, xmlOptions);
out.close();
}
public List<XWPFFootnote> getFootnotesList() { public List<XWPFFootnote> getFootnotesList() {
return listFootnote; return listFootnote;
} }
public XWPFFootnote getFootnoteById(int id) { public XWPFFootnote getFootnoteById(int id) {
for(XWPFFootnote note : listFootnote) { for(XWPFFootnote note : listFootnote) {
if(note.getCTFtnEdn().getId().intValue() == id) if(note.getCTFtnEdn().getId().intValue() == id)
return note; return note;
}
return null;
}
/**
* Sets the ctFootnotes
* @param footnotes
*/
public void setFootnotes(CTFootnotes footnotes) {
ctFootnotes = footnotes;
} }
return null;
}
/** /**
* add an XWPFFootnote to the document * Sets the ctFootnotes
* @param footnote * @param footnotes
* @throws IOException */
*/ public void setFootnotes(CTFootnotes footnotes) {
public void addFootnote(XWPFFootnote footnote){ ctFootnotes = footnotes;
listFootnote.add(footnote); }
ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
}
/** /**
* add a footnote to the document * add an XWPFFootnote to the document
* @param note * @param footnote
* @throws IOException * @throws IOException
*/ */
public XWPFFootnote addFootnote(CTFtnEdn note){ public void addFootnote(XWPFFootnote footnote){
CTFtnEdn newNote = ctFootnotes.addNewFootnote(); listFootnote.add(footnote);
newNote.set(note); ctFootnotes.addNewFootnote().set(footnote.getCTFtnEdn());
XWPFFootnote xNote = new XWPFFootnote(newNote, this); }
listFootnote.add(xNote);
return xNote;
}
public void setXWPFDocument(XWPFDocument doc) { /**
document = doc; * add a footnote to the document
} * @param note
* @throws IOException
*/
public XWPFFootnote addFootnote(CTFtnEdn note){
CTFtnEdn newNote = ctFootnotes.addNewFootnote();
newNote.set(note);
XWPFFootnote xNote = new XWPFFootnote(newNote, this);
listFootnote.add(xNote);
return xNote;
}
/** public void setXWPFDocument(XWPFDocument doc) {
* @see org.apache.poi.xwpf.usermodel.IBody#getPart() document = doc;
*/ }
public XWPFDocument getXWPFDocument() {
if ( document != null) {
return document;
} else {
return (XWPFDocument)getParent();
}
}
}//end class
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/
public XWPFDocument getXWPFDocument() {
if ( document != null) {
return document;
} else {
return (XWPFDocument)getParent();
}
}
}

View File

@ -39,24 +39,11 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
/** /**
* Sketch of XWPFTable class. Only table's text is being hold. * <p>Sketch of XWPFTable class. Only table's text is being hold.</p>
* <p/> * <p>Specifies the contents of a table present in the document. A table is a set
* Specifies the contents of a table present in the document. A table is a set * of paragraphs (and other block-level content) arranged in rows and columns.</p>
* of paragraphs (and other block-level content) arranged in rows and columns.
*
* @author Yury Batrakov (batrakov at gmail.com)
* @author Gregg Morris (gregg dot morris at gmail dot com) - added
* setStyleID()
* getRowBandSize(), setRowBandSize()
* getColBandSize(), setColBandSize()
* getInsideHBorderType(), getInsideHBorderSize(), getInsideHBorderSpace(), getInsideHBorderColor()
* getInsideVBorderType(), getInsideVBorderSize(), getInsideVBorderSpace(), getInsideVBorderColor()
* setInsideHBorder(), setInsideVBorder()
* getCellMarginTop(), getCellMarginLeft(), getCellMarginBottom(), getCellMarginRight()
* setCellMargins()
*/ */
public class XWPFTable implements IBodyElement{ public class XWPFTable implements IBodyElement {
protected StringBuffer text = new StringBuffer(); protected StringBuffer text = new StringBuffer();
private CTTbl ctTbl; private CTTbl ctTbl;
protected List<XWPFTableRow> tableRows; protected List<XWPFTableRow> tableRows;
@ -157,10 +144,10 @@ public class XWPFTable implements IBodyElement{
borders.addNewTop().setVal(STBorder.SINGLE); borders.addNewTop().setVal(STBorder.SINGLE);
/* /*
* CTTblGrid tblgrid=table.addNewTblGrid(); * CTTblGrid tblgrid=table.addNewTblGrid();
* tblgrid.addNewGridCol().setW(new BigInteger("2000")); * tblgrid.addNewGridCol().setW(new BigInteger("2000"));
*/ */
getRows(); getRows();
} }
/** /**
@ -227,8 +214,7 @@ public class XWPFTable implements IBodyElement{
*/ */
public void setWidth(int width) { public void setWidth(int width) {
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr CTTblWidth tblWidth = tblPr.isSetTblW() ? tblPr.getTblW() : tblPr.addNewTblW();
.addNewTblW();
tblWidth.setW(new BigInteger("" + width)); tblWidth.setW(new BigInteger("" + width));
} }
@ -291,167 +277,167 @@ public class XWPFTable implements IBodyElement{
} }
public XWPFBorderType getInsideHBorderType() { public XWPFBorderType getInsideHBorderType() {
XWPFBorderType bt = null; XWPFBorderType bt = null;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideH()) { if (ctb.isSetInsideH()) {
CTBorder border = ctb.getInsideH(); CTBorder border = ctb.getInsideH();
bt = stBorderTypeMap.get(border.getVal().intValue()); bt = stBorderTypeMap.get(border.getVal().intValue());
} }
} }
return bt; return bt;
} }
public int getInsideHBorderSize() { public int getInsideHBorderSize() {
int size = -1; int size = -1;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideH()) { if (ctb.isSetInsideH()) {
CTBorder border = ctb.getInsideH(); CTBorder border = ctb.getInsideH();
size = border.getSz().intValue(); size = border.getSz().intValue();
} }
} }
return size; return size;
} }
public int getInsideHBorderSpace() { public int getInsideHBorderSpace() {
int space = -1; int space = -1;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideH()) { if (ctb.isSetInsideH()) {
CTBorder border = ctb.getInsideH(); CTBorder border = ctb.getInsideH();
space = border.getSpace().intValue(); space = border.getSpace().intValue();
} }
} }
return space; return space;
} }
public String getInsideHBorderColor() { public String getInsideHBorderColor() {
String color = null; String color = null;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideH()) { if (ctb.isSetInsideH()) {
CTBorder border = ctb.getInsideH(); CTBorder border = ctb.getInsideH();
color = border.xgetColor().getStringValue(); color = border.xgetColor().getStringValue();
} }
} }
return color; return color;
} }
public XWPFBorderType getInsideVBorderType() { public XWPFBorderType getInsideVBorderType() {
XWPFBorderType bt = null; XWPFBorderType bt = null;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideV()) { if (ctb.isSetInsideV()) {
CTBorder border = ctb.getInsideV(); CTBorder border = ctb.getInsideV();
bt = stBorderTypeMap.get(border.getVal().intValue()); bt = stBorderTypeMap.get(border.getVal().intValue());
} }
} }
return bt; return bt;
} }
public int getInsideVBorderSize() { public int getInsideVBorderSize() {
int size = -1; int size = -1;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideV()) { if (ctb.isSetInsideV()) {
CTBorder border = ctb.getInsideV(); CTBorder border = ctb.getInsideV();
size = border.getSz().intValue(); size = border.getSz().intValue();
} }
} }
return size; return size;
} }
public int getInsideVBorderSpace() { public int getInsideVBorderSpace() {
int space = -1; int space = -1;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideV()) { if (ctb.isSetInsideV()) {
CTBorder border = ctb.getInsideV(); CTBorder border = ctb.getInsideV();
space = border.getSpace().intValue(); space = border.getSpace().intValue();
} }
} }
return space; return space;
} }
public String getInsideVBorderColor() { public String getInsideVBorderColor() {
String color = null; String color = null;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblBorders()) { if (tblPr.isSetTblBorders()) {
CTTblBorders ctb = tblPr.getTblBorders(); CTTblBorders ctb = tblPr.getTblBorders();
if (ctb.isSetInsideV()) { if (ctb.isSetInsideV()) {
CTBorder border = ctb.getInsideV(); CTBorder border = ctb.getInsideV();
color = border.xgetColor().getStringValue(); color = border.xgetColor().getStringValue();
} }
} }
return color; return color;
} }
public int getRowBandSize() { public int getRowBandSize() {
int size = 0; int size = 0;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblStyleRowBandSize()) { if (tblPr.isSetTblStyleRowBandSize()) {
CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize(); CTDecimalNumber rowSize = tblPr.getTblStyleRowBandSize();
size = rowSize.getVal().intValue(); size = rowSize.getVal().intValue();
} }
return size; return size;
} }
public void setRowBandSize(int size) { public void setRowBandSize(int size) {
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize(); CTDecimalNumber rowSize = tblPr.isSetTblStyleRowBandSize() ? tblPr.getTblStyleRowBandSize() : tblPr.addNewTblStyleRowBandSize();
rowSize.setVal(BigInteger.valueOf(size)); rowSize.setVal(BigInteger.valueOf(size));
} }
public int getColBandSize() { public int getColBandSize() {
int size = 0; int size = 0;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
if (tblPr.isSetTblStyleColBandSize()) { if (tblPr.isSetTblStyleColBandSize()) {
CTDecimalNumber colSize = tblPr.getTblStyleColBandSize(); CTDecimalNumber colSize = tblPr.getTblStyleColBandSize();
size = colSize.getVal().intValue(); size = colSize.getVal().intValue();
} }
return size; return size;
} }
public void setColBandSize(int size) { public void setColBandSize(int size) {
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize(); CTDecimalNumber colSize = tblPr.isSetTblStyleColBandSize() ? tblPr.getTblStyleColBandSize() : tblPr.addNewTblStyleColBandSize();
colSize.setVal(BigInteger.valueOf(size)); colSize.setVal(BigInteger.valueOf(size));
} }
public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders(); CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH(); CTBorder b = ctb.isSetInsideH() ? ctb.getInsideH() : ctb.addNewInsideH();
b.setVal(xwpfBorderTypeMap.get(type)); b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size)); b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space)); b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor); b.setColor(rgbColor);
} }
public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders(); CTTblBorders ctb = tblPr.isSetTblBorders() ? tblPr.getTblBorders() : tblPr.addNewTblBorders();
CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV(); CTBorder b = ctb.isSetInsideV() ? ctb.getInsideV() : ctb.addNewInsideV();
b.setVal(xwpfBorderTypeMap.get(type)); b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size)); b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space)); b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor); b.setColor(rgbColor);
} }
public int getCellMarginTop() { public int getCellMarginTop() {
@ -494,141 +480,141 @@ public class XWPFTable implements IBodyElement{
} }
public int getCellMarginRight() { public int getCellMarginRight() {
int margin = 0; int margin = 0;
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTTblCellMar tcm = tblPr.getTblCellMar(); CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) { if (tcm != null) {
CTTblWidth tw = tcm.getRight(); CTTblWidth tw = tcm.getRight();
if (tw != null) { if (tw != null) {
margin = tw.getW().intValue(); margin = tw.getW().intValue();
} }
} }
return margin; return margin;
} }
public void setCellMargins(int top, int left, int bottom, int right) { public void setCellMargins(int top, int left, int bottom, int right) {
CTTblPr tblPr = getTrPr(); CTTblPr tblPr = getTrPr();
CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar(); CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft(); CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft();
tw.setType(STTblWidth.DXA); tw.setType(STTblWidth.DXA);
tw.setW(BigInteger.valueOf(left)); tw.setW(BigInteger.valueOf(left));
tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop(); tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop();
tw.setType(STTblWidth.DXA); tw.setType(STTblWidth.DXA);
tw.setW(BigInteger.valueOf(top)); tw.setW(BigInteger.valueOf(top));
tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom(); tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom();
tw.setType(STTblWidth.DXA); tw.setType(STTblWidth.DXA);
tw.setW(BigInteger.valueOf(bottom)); tw.setW(BigInteger.valueOf(bottom));
tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight(); tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight();
tw.setType(STTblWidth.DXA); tw.setType(STTblWidth.DXA);
tw.setW(BigInteger.valueOf(right)); tw.setW(BigInteger.valueOf(right));
} }
/** /**
* add a new Row to the table * add a new Row to the table
* *
* @param row the row which should be added * @param row the row which should be added
*/ */
public void addRow(XWPFTableRow row){ public void addRow(XWPFTableRow row){
ctTbl.addNewTr(); ctTbl.addNewTr();
ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow()); ctTbl.setTrArray(getNumberOfRows()-1, row.getCtRow());
tableRows.add(row); tableRows.add(row);
} }
/** /**
* add a new Row to the table * add a new Row to the table
* at position pos * at position pos
* @param row the row which should be added * @param row the row which should be added
*/ */
public boolean addRow(XWPFTableRow row, int pos){ public boolean addRow(XWPFTableRow row, int pos){
if(pos >= 0 && pos <= tableRows.size()){ if(pos >= 0 && pos <= tableRows.size()){
ctTbl.insertNewTr(pos); ctTbl.insertNewTr(pos);
ctTbl.setTrArray(pos,row.getCtRow()); ctTbl.setTrArray(pos,row.getCtRow());
tableRows.add(pos, row); tableRows.add(pos, row);
return true; return true;
} }
return false; return false;
} }
/** /**
* inserts a new tablerow * inserts a new tablerow
* @param pos * @param pos
* @return the inserted row * @return the inserted row
*/ */
public XWPFTableRow insertNewTableRow(int pos){ public XWPFTableRow insertNewTableRow(int pos){
if(pos >= 0 && pos <= tableRows.size()){ if(pos >= 0 && pos <= tableRows.size()){
CTRow row = ctTbl.insertNewTr(pos); CTRow row = ctTbl.insertNewTr(pos);
XWPFTableRow tableRow = new XWPFTableRow(row, this); XWPFTableRow tableRow = new XWPFTableRow(row, this);
tableRows.add(pos, tableRow); tableRows.add(pos, tableRow);
return tableRow; return tableRow;
} }
return null; return null;
} }
/**
* Remove a row at position pos from the table
* @param pos position the Row in the Table
*/
public boolean removeRow(int pos) throws IndexOutOfBoundsException {
if (pos >= 0 && pos < tableRows.size()) {
if (ctTbl.sizeOfTrArray() > 0) {
ctTbl.removeTr(pos);
}
tableRows.remove(pos);
return true;
}
return false;
}
public List<XWPFTableRow> getRows() {
return tableRows;
}
/** /**
* returns the type of the BodyElement Table * Remove a row at position pos from the table
* @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType() * @param pos position the Row in the Table
*/ */
public BodyElementType getElementType() { public boolean removeRow(int pos) throws IndexOutOfBoundsException {
return BodyElementType.TABLE; if (pos >= 0 && pos < tableRows.size()) {
} if (ctTbl.sizeOfTrArray() > 0) {
ctTbl.removeTr(pos);
}
tableRows.remove(pos);
return true;
}
return false;
}
public IBody getBody() public List<XWPFTableRow> getRows() {
{ return tableRows;
return part; }
}
/**
* returns the part of the bodyElement
* @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/
public POIXMLDocumentPart getPart() {
if(part != null){
return part.getPart();
}
return null;
}
/** /**
* returns the partType of the bodyPart which owns the bodyElement * returns the type of the BodyElement Table
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType() * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
*/ */
public BodyType getPartType() { public BodyElementType getElementType() {
return part.getPartType(); return BodyElementType.TABLE;
} }
/** public IBody getBody()
* returns the XWPFRow which belongs to the CTRow row {
* if this row is not existing in the table null will be returned return part;
*/ }
public XWPFTableRow getRow(CTRow row) {
for(int i=0; i<getRows().size(); i++){ /**
if(getRows().get(i).getCtRow()== row) return getRow(i); * returns the part of the bodyElement
} * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
return null; */
} public POIXMLDocumentPart getPart() {
}// end class if(part != null){
return part.getPart();
}
return null;
}
/**
* returns the partType of the bodyPart which owns the bodyElement
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
public BodyType getPartType() {
return part.getPartType();
}
/**
* returns the XWPFRow which belongs to the CTRow row
* if this row is not existing in the table null will be returned
*/
public XWPFTableRow getRow(CTRow row) {
for(int i=0; i<getRows().size(); i++){
if(getRows().get(i).getCtRow()== row) return getRow(i);
}
return null;
}
}

View File

@ -37,11 +37,8 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
/** /**
* XWPFTableCell class. * Represents a Cell within a {@link XWPFTable}. The
* * Cell is the thing that holds the actual content (paragraphs etc)
* @author Gregg Morris (gregg dot morris at gmail dot com) - added XWPFVertAlign enum,
* setColor(),
* setVerticalAlignment()
*/ */
public class XWPFTableCell implements IBody { public class XWPFTableCell implements IBody {
private final CTTc ctTc; private final CTTc ctTc;
@ -76,38 +73,38 @@ public class XWPFTableCell implements IBody {
* If a table cell does not include at least one block-level element, then this document shall be considered corrupt * If a table cell does not include at least one block-level element, then this document shall be considered corrupt
*/ */
public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) { public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) {
this.ctTc = cell; this.ctTc = cell;
this.part = part; this.part = part;
this.tableRow = tableRow; this.tableRow = tableRow;
// NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt. // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt.
if(cell.getPList().size()<1) if(cell.getPList().size()<1)
cell.addNewP(); cell.addNewP();
bodyElements = new ArrayList<IBodyElement>(); bodyElements = new ArrayList<IBodyElement>();
paragraphs = new ArrayList<XWPFParagraph>(); paragraphs = new ArrayList<XWPFParagraph>();
tables = new ArrayList<XWPFTable>(); tables = new ArrayList<XWPFTable>();
XmlCursor cursor = ctTc.newCursor(); XmlCursor cursor = ctTc.newCursor();
cursor.selectPath("./*"); cursor.selectPath("./*");
while (cursor.toNextSelection()) { while (cursor.toNextSelection()) {
XmlObject o = cursor.getObject(); XmlObject o = cursor.getObject();
if (o instanceof CTP) { if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP)o, this); XWPFParagraph p = new XWPFParagraph((CTP)o, this);
paragraphs.add(p); paragraphs.add(p);
bodyElements.add(p); bodyElements.add(p);
} }
if (o instanceof CTTbl) { if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl)o, this); XWPFTable t = new XWPFTable((CTTbl)o, this);
tables.add(t); tables.add(t);
bodyElements.add(t); bodyElements.add(t);
} }
} }
cursor.dispose(); cursor.dispose();
} }
@Internal @Internal
public CTTc getCTTc() { public CTTc getCTTc() {
return ctTc; return ctTc;
} }
/** /**
@ -168,12 +165,12 @@ public class XWPFTableCell implements IBody {
* XWPFParagraph with the correspondig CTP p * XWPFParagraph with the correspondig CTP p
*/ */
public XWPFParagraph getParagraph(CTP p){ public XWPFParagraph getParagraph(CTP p){
for (XWPFParagraph paragraph : paragraphs) { for (XWPFParagraph paragraph : paragraphs) {
if(p.equals(paragraph.getCTP())){ if(p.equals(paragraph.getCTP())){
return paragraph; return paragraph;
} }
} }
return null; return null;
} }
public void setText(String text) { public void setText(String text) {
@ -204,15 +201,15 @@ public class XWPFTableCell implements IBody {
* @return RGB string of cell color * @return RGB string of cell color
*/ */
public String getColor() { public String getColor() {
String color = null; String color = null;
CTTcPr tcpr = ctTc.getTcPr(); CTTcPr tcpr = ctTc.getTcPr();
if (tcpr != null) { if (tcpr != null) {
CTShd ctshd = tcpr.getShd(); CTShd ctshd = tcpr.getShd();
if (ctshd != null) { if (ctshd != null) {
color = ctshd.xgetFill().getStringValue(); color = ctshd.xgetFill().getStringValue();
} }
} }
return color; return color;
} }
/** /**
@ -230,13 +227,13 @@ public class XWPFTableCell implements IBody {
* @return the cell alignment enum value * @return the cell alignment enum value
*/ */
public XWPFVertAlign getVerticalAlignment() { public XWPFVertAlign getVerticalAlignment() {
XWPFVertAlign vAlign = null; XWPFVertAlign vAlign = null;
CTTcPr tcpr = ctTc.getTcPr(); CTTcPr tcpr = ctTc.getTcPr();
if (ctTc != null) { if (ctTc != null) {
CTVerticalJc va = tcpr.getVAlign(); CTVerticalJc va = tcpr.getVAlign();
vAlign = stVertAlignTypeMap.get(va.getVal().intValue()); vAlign = stVertAlignTypeMap.get(va.getVal().intValue());
} }
return vAlign; return vAlign;
} }
/** /**
@ -245,97 +242,98 @@ public class XWPFTableCell implements IBody {
* @return the inserted paragraph * @return the inserted paragraph
*/ */
public XWPFParagraph insertNewParagraph(XmlCursor cursor){ public XWPFParagraph insertNewParagraph(XmlCursor cursor){
if(!isCursorInTableCell(cursor)) if(!isCursorInTableCell(cursor)) {
return null; return null;
}
String uri = CTP.type.getName().getNamespaceURI();
String localPart = "p"; String uri = CTP.type.getName().getNamespaceURI();
cursor.beginElement(localPart,uri); String localPart = "p";
cursor.toParent(); cursor.beginElement(localPart,uri);
CTP p = (CTP)cursor.getObject(); cursor.toParent();
XWPFParagraph newP = new XWPFParagraph(p, this); CTP p = (CTP)cursor.getObject();
XmlObject o = null; XWPFParagraph newP = new XWPFParagraph(p, this);
while(!(o instanceof CTP)&&(cursor.toPrevSibling())){ XmlObject o = null;
o = cursor.getObject(); while(!(o instanceof CTP)&&(cursor.toPrevSibling())){
} o = cursor.getObject();
if((!(o instanceof CTP)) || (CTP)o == p){ }
paragraphs.add(0, newP); if((!(o instanceof CTP)) || (CTP)o == p){
} paragraphs.add(0, newP);
else{ }
int pos = paragraphs.indexOf(getParagraph((CTP)o))+1; else{
paragraphs.add(pos,newP); int pos = paragraphs.indexOf(getParagraph((CTP)o))+1;
} paragraphs.add(pos,newP);
int i=0; }
cursor.toCursor(p.newCursor()); int i=0;
while(cursor.toPrevSibling()){ cursor.toCursor(p.newCursor());
o =cursor.getObject(); while(cursor.toPrevSibling()){
if(o instanceof CTP || o instanceof CTTbl) o =cursor.getObject();
i++; if(o instanceof CTP || o instanceof CTTbl)
} i++;
bodyElements.add(i, newP); }
cursor.toCursor(p.newCursor()); bodyElements.add(i, newP);
cursor.toEndToken(); cursor.toCursor(p.newCursor());
return newP; cursor.toEndToken();
return newP;
} }
public XWPFTable insertNewTbl(XmlCursor cursor) { public XWPFTable insertNewTbl(XmlCursor cursor) {
if(isCursorInTableCell(cursor)){ if(isCursorInTableCell(cursor)){
String uri = CTTbl.type.getName().getNamespaceURI(); String uri = CTTbl.type.getName().getNamespaceURI();
String localPart = "tbl"; String localPart = "tbl";
cursor.beginElement(localPart,uri); cursor.beginElement(localPart,uri);
cursor.toParent(); cursor.toParent();
CTTbl t = (CTTbl)cursor.getObject(); CTTbl t = (CTTbl)cursor.getObject();
XWPFTable newT = new XWPFTable(t, this); XWPFTable newT = new XWPFTable(t, this);
cursor.removeXmlContents(); cursor.removeXmlContents();
XmlObject o = null; XmlObject o = null;
while(!(o instanceof CTTbl)&&(cursor.toPrevSibling())){ while(!(o instanceof CTTbl)&&(cursor.toPrevSibling())){
o = cursor.getObject(); o = cursor.getObject();
} }
if(!(o instanceof CTTbl)){ if(!(o instanceof CTTbl)){
tables.add(0, newT); tables.add(0, newT);
} }
else{ else{
int pos = tables.indexOf(getTable((CTTbl)o))+1; int pos = tables.indexOf(getTable((CTTbl)o))+1;
tables.add(pos,newT); tables.add(pos,newT);
} }
int i=0; int i=0;
cursor = t.newCursor(); cursor = t.newCursor();
while(cursor.toPrevSibling()){ while(cursor.toPrevSibling()){
o =cursor.getObject(); o =cursor.getObject();
if(o instanceof CTP || o instanceof CTTbl) if(o instanceof CTP || o instanceof CTTbl)
i++; i++;
} }
bodyElements.add(i, newT); bodyElements.add(i, newT);
cursor = t.newCursor(); cursor = t.newCursor();
cursor.toEndToken(); cursor.toEndToken();
return newT; return newT;
}
return null;
}
/**
* verifies that cursor is on the right position
*/
private boolean isCursorInTableCell(XmlCursor cursor) {
XmlCursor verify = cursor.newCursor();
verify.toParent();
if(verify.getObject() == this.ctTc){
return true;
}
return false;
} }
return null;
}
/**
* verifies that cursor is on the right position
/** */
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int) private boolean isCursorInTableCell(XmlCursor cursor) {
*/ XmlCursor verify = cursor.newCursor();
public XWPFParagraph getParagraphArray(int pos) { verify.toParent();
if(pos > 0 && pos < paragraphs.size()){ if(verify.getObject() == this.ctTc){
return paragraphs.get(pos); return true;
}
return null;
} }
return false;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int)
*/
public XWPFParagraph getParagraphArray(int pos) {
if(pos > 0 && pos < paragraphs.size()){
return paragraphs.get(pos);
}
return null;
}
/** /**
* get the to which the TableCell belongs * get the to which the TableCell belongs
@ -346,101 +344,100 @@ public class XWPFTableCell implements IBody {
return tableRow.getTable().getPart(); return tableRow.getTable().getPart();
} }
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/
public BodyType getPartType() {
return BodyType.TABLECELL;
}
/**
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType() /**
*/ * get a table by its CTTbl-Object
public BodyType getPartType() { * @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)
return BodyType.TABLECELL; */
public XWPFTable getTable(CTTbl ctTable) {
for(int i=0; i<tables.size(); i++){
if(getTables().get(i).getCTTbl() == ctTable) return getTables().get(i);
} }
return null;
}
/** /**
* get a table by its CTTbl-Object * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int)
* @see org.apache.poi.xwpf.usermodel.IBody#getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) */
*/ public XWPFTable getTableArray(int pos) {
public XWPFTable getTable(CTTbl ctTable) { if(pos > 0 && pos < tables.size()){
for(int i=0; i<tables.size(); i++){ return tables.get(pos);
if(getTables().get(i).getCTTbl() == ctTable) return getTables().get(i);
}
return null;
} }
return null;
}
/** /**
* @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) * @see org.apache.poi.xwpf.usermodel.IBody#getTables()
*/ */
public XWPFTable getTableArray(int pos) { public List<XWPFTable> getTables() {
if(pos > 0 && pos < tables.size()){ return Collections.unmodifiableList(tables);
return tables.get(pos); }
}
return null;
/**
* inserts an existing XWPFTable to the arrays bodyElements and tables
* @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable)
*/
public void insertTable(int pos, XWPFTable table) {
bodyElements.add(pos, table);
int i;
for (i = 0; i < ctTc.getTblList().size(); i++) {
CTTbl tbl = ctTc.getTblArray(i);
if(tbl == table.getCTTbl()){
break;
}
} }
tables.add(i, table);
}
public String getText(){
/** StringBuffer text = new StringBuffer();
* @see org.apache.poi.xwpf.usermodel.IBody#getTables() for (XWPFParagraph p : paragraphs) {
*/ text.append(p.getText());
public List<XWPFTable> getTables() {
return Collections.unmodifiableList(tables);
} }
return text.toString();
}
/** /**
* inserts an existing XWPFTable to the arrays bodyElements and tables * get the TableCell which belongs to the TableCell
* @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable) */
*/ public XWPFTableCell getTableCell(CTTc cell) {
public void insertTable(int pos, XWPFTable table) { XmlCursor cursor = cell.newCursor();
bodyElements.add(pos, table); cursor.toParent();
int i; XmlObject o = cursor.getObject();
for (i = 0; i < ctTc.getTblList().size(); i++) { if(!(o instanceof CTRow)){
CTTbl tbl = ctTc.getTblArray(i); return null;
if(tbl == table.getCTTbl()){
break;
}
}
tables.add(i, table);
} }
CTRow row = (CTRow)o;
public String getText(){ cursor.toParent();
StringBuffer text = new StringBuffer(); o = cursor.getObject();
for (XWPFParagraph p : paragraphs) { cursor.dispose();
text.append(p.getText()); if(! (o instanceof CTTbl)){
} return null;
return text.toString();
} }
CTTbl tbl = (CTTbl) o;
XWPFTable table = getTable(tbl);
/** if(table == null){
* get the TableCell which belongs to the TableCell return null;
*/
public XWPFTableCell getTableCell(CTTc cell) {
XmlCursor cursor = cell.newCursor();
cursor.toParent();
XmlObject o = cursor.getObject();
if(!(o instanceof CTRow)){
return null;
}
CTRow row = (CTRow)o;
cursor.toParent();
o = cursor.getObject();
cursor.dispose();
if(! (o instanceof CTTbl)){
return null;
}
CTTbl tbl = (CTTbl) o;
XWPFTable table = getTable(tbl);
if(table == null){
return null;
}
XWPFTableRow tableRow = table.getRow(row);
if (tableRow == null) {
return null;
}
return tableRow.getTableCell(cell);
} }
XWPFTableRow tableRow = table.getRow(row);
if (tableRow == null) {
return null;
}
return tableRow.getTableCell(cell);
}
public XWPFDocument getXWPFDocument() { public XWPFDocument getXWPFDocument() {
return part.getXWPFDocument(); return part.getXWPFDocument();
} }
}// end class }

View File

@ -30,24 +30,24 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
/** /**
* @author gisellabronzetti * A row within an {@link XWPFTable}. Rows mostly just have
* @author gregg morris - added removeCell(), setCantSplitRow(), setRepeatHeader() * sizings and stylings, the interesting content lives inside
* the child {@link XWPFTableCell}s
*/ */
public class XWPFTableRow { public class XWPFTableRow {
private CTRow ctRow; private CTRow ctRow;
private XWPFTable table; private XWPFTable table;
private List<XWPFTableCell> tableCells; private List<XWPFTableCell> tableCells;
public XWPFTableRow(CTRow row, XWPFTable table) { public XWPFTableRow(CTRow row, XWPFTable table) {
this.table = table; this.table = table;
this.ctRow = row; this.ctRow = row;
getTableCells(); getTableCells();
} }
@Internal @Internal
public CTRow getCtRow() { public CTRow getCtRow() {
return ctRow; return ctRow;
} }
/** /**
@ -55,31 +55,31 @@ public class XWPFTableRow {
* @return the newly created XWPFTableCell * @return the newly created XWPFTableCell
*/ */
public XWPFTableCell createCell() { public XWPFTableCell createCell() {
XWPFTableCell tableCell = new XWPFTableCell(ctRow.addNewTc(), this, table.getBody()); XWPFTableCell tableCell = new XWPFTableCell(ctRow.addNewTc(), this, table.getBody());
tableCells.add(tableCell); tableCells.add(tableCell);
return tableCell; return tableCell;
} }
public XWPFTableCell getCell(int pos) { public XWPFTableCell getCell(int pos) {
if (pos >= 0 && pos < ctRow.sizeOfTcArray()) { if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
return getTableCells().get(pos); return getTableCells().get(pos);
} }
return null; return null;
} }
public void removeCell(int pos) { public void removeCell(int pos) {
if (pos >= 0 && pos < ctRow.sizeOfTcArray()) { if (pos >= 0 && pos < ctRow.sizeOfTcArray()) {
tableCells.remove(pos); tableCells.remove(pos);
} }
} }
/** /**
* adds a new TableCell at the end of this tableRow * adds a new TableCell at the end of this tableRow
*/ */
public XWPFTableCell addNewTableCell(){ public XWPFTableCell addNewTableCell(){
CTTc cell = ctRow.addNewTc(); CTTc cell = ctRow.addNewTc();
XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.getBody()); XWPFTableCell tableCell = new XWPFTableCell(cell, this, table.getBody());
tableCells.add(tableCell); tableCells.add(tableCell);
return tableCell; return tableCell;
} }
/** /**
@ -93,9 +93,9 @@ public class XWPFTableRow {
* @param height * @param height
*/ */
public void setHeight(int height) { public void setHeight(int height) {
CTTrPr properties = getTrPr(); CTTrPr properties = getTrPr();
CTHeight h = properties.sizeOfTrHeightArray() == 0 ? properties.addNewTrHeight() : properties.getTrHeightArray(0); CTHeight h = properties.sizeOfTrHeightArray() == 0 ? properties.addNewTrHeight() : properties.getTrHeightArray(0);
h.setVal(new BigInteger("" + height)); h.setVal(new BigInteger("" + height));
} }
/** /**
@ -109,101 +109,100 @@ public class XWPFTableRow {
* @return height * @return height
*/ */
public int getHeight() { public int getHeight() {
CTTrPr properties = getTrPr(); CTTrPr properties = getTrPr();
return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue(); return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
} }
private CTTrPr getTrPr() { private CTTrPr getTrPr() {
return (ctRow.isSetTrPr()) ? ctRow.getTrPr() : ctRow.addNewTrPr(); return (ctRow.isSetTrPr()) ? ctRow.getTrPr() : ctRow.addNewTrPr();
} }
public XWPFTable getTable(){ public XWPFTable getTable(){
return table; return table;
} }
/** /**
* create and return a list of all XWPFTableCell * create and return a list of all XWPFTableCell
* who belongs to this row * who belongs to this row
* @return a list of {@link XWPFTableCell} * @return a list of {@link XWPFTableCell}
*/ */
public List<XWPFTableCell> getTableCells(){ public List<XWPFTableCell> getTableCells(){
if(tableCells == null){ if(tableCells == null){
List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>(); List<XWPFTableCell> cells = new ArrayList<XWPFTableCell>();
for (CTTc tableCell : ctRow.getTcList()) { for (CTTc tableCell : ctRow.getTcList()) {
cells.add(new XWPFTableCell(tableCell, this, table.getBody())); cells.add(new XWPFTableCell(tableCell, this, table.getBody()));
} }
this.tableCells = cells; this.tableCells = cells;
} }
return tableCells; return tableCells;
} }
/** /**
* returns the XWPFTableCell which belongs to the CTTC cell * returns the XWPFTableCell which belongs to the CTTC cell
* if there is no XWPFTableCell which belongs to the parameter CTTc cell null will be returned * if there is no XWPFTableCell which belongs to the parameter CTTc cell null will be returned
*/ */
public XWPFTableCell getTableCell(CTTc cell) { public XWPFTableCell getTableCell(CTTc cell) {
for(int i=0; i<tableCells.size(); i++){ for(int i=0; i<tableCells.size(); i++){
if (tableCells.get(i).getCTTc() == cell) if (tableCells.get(i).getCTTc() == cell)
return tableCells.get(i); return tableCells.get(i);
}
return null;
} }
return null;
}
/** /**
* This attribute controls whether to allow table rows to split across pages. * This attribute controls whether to allow table rows to split across pages.
* The logic for this attribute is a little unusual: a true value means * The logic for this attribute is a little unusual: a true value means
* DON'T allow rows to split, false means allow rows to split. * DON'T allow rows to split, false means allow rows to split.
* @param split - if true, don't allow rows to be split. If false, allow * @param split - if true, don't allow rows to be split. If false, allow
* rows to be split. * rows to be split.
*/ */
public void setCantSplitRow(boolean split) { public void setCantSplitRow(boolean split) {
CTTrPr trpr = getTrPr(); CTTrPr trpr = getTrPr();
CTOnOff onoff = trpr.addNewCantSplit(); CTOnOff onoff = trpr.addNewCantSplit();
onoff.setVal(split ? STOnOff.ON : STOnOff.OFF); onoff.setVal(split ? STOnOff.ON : STOnOff.OFF);
}
/**
* Return true if the "can't split row" value is true. The logic for this
* attribute is a little unusual: a TRUE value means DON'T allow rows to
* split, FALSE means allow rows to split.
* @return true if rows can't be split, false otherwise.
*/
public boolean isCantSplitRow() {
boolean isCant = false;
CTTrPr trpr = getTrPr();
if (trpr.sizeOfCantSplitArray() > 0) {
CTOnOff onoff = trpr.getCantSplitList().get(0);
isCant = onoff.getVal().equals(STOnOff.ON);
} }
return isCant;
}
/** /**
* Return true if the "can't split row" value is true. The logic for this * This attribute controls whether to repeat a table's header row at the top
* attribute is a little unusual: a TRUE value means DON'T allow rows to * of a table split across pages.
* split, FALSE means allow rows to split. * @param repeat - if TRUE, repeat header row at the top of each page of table;
* @return true if rows can't be split, false otherwise. * if FALSE, don't repeat header row.
*/ */
public boolean isCantSplitRow() { public void setRepeatHeader(boolean repeat) {
boolean isCant = false; CTTrPr trpr = getTrPr();
CTTrPr trpr = getTrPr(); CTOnOff onoff = trpr.addNewTblHeader();
if (trpr.sizeOfCantSplitArray() > 0) { onoff.setVal(repeat ? STOnOff.ON : STOnOff.OFF);
CTOnOff onoff = trpr.getCantSplitList().get(0); }
isCant = onoff.getVal().equals(STOnOff.ON);
} /**
return isCant; * Return true if a table's header row should be repeated at the top of a
* table split across pages.
* @return true if table's header row should be repeated at the top of each
* page of table, false otherwise.
*/
public boolean isRepeatHeader() {
boolean repeat = false;
CTTrPr trpr = getTrPr();
if (trpr.sizeOfTblHeaderArray() > 0) {
CTOnOff rpt = trpr.getTblHeaderList().get(0);
repeat = rpt.getVal().equals(STOnOff.ON);
} }
return repeat;
/** }
* This attribute controls whether to repeat a table's header row at the top }
* of a table split across pages.
* @param repeat - if TRUE, repeat header row at the top of each page of table;
* if FALSE, don't repeat header row.
*/
public void setRepeatHeader(boolean repeat) {
CTTrPr trpr = getTrPr();
CTOnOff onoff = trpr.addNewTblHeader();
onoff.setVal(repeat ? STOnOff.ON : STOnOff.OFF);
}
/**
* Return true if a table's header row should be repeated at the top of a
* table split across pages.
* @return true if table's header row should be repeated at the top of each
* page of table, false otherwise.
*/
public boolean isRepeatHeader() {
boolean repeat = false;
CTTrPr trpr = getTrPr();
if (trpr.sizeOfTblHeaderArray() > 0) {
CTOnOff rpt = trpr.getTblHeaderList().get(0);
repeat = rpt.getVal().equals(STOnOff.ON);
}
return repeat;
}
}// end class