jaragunde commented on code in PR #843: URL: https://github.com/apache/poi/pull/843#discussion_r2206610843
########## poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTable.java: ########## @@ -306,6 +306,80 @@ public int getNumberOfRows() { return ctTbl.sizeOfTrArray(); } + /** + * Get the indentation value in 20ths of a point (twips). + * + * <p>This element specifies the indentation which shall be added before the leading edge of + * the current table in the document (the left edge in a left-to-right table, and the right + * edge in a right-to-left table).</p> + * <p>If the table alignment is not left/start, this property shall be ignored.</p> + * + * @see boolean isSetIndent() + * @return indentation value as an integer (20ths of a point) + */ + public int getIndent() { + CTTblPr tblPr = getTblPr(); Review Comment: Done ########## poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFTable.java: ########## @@ -586,4 +584,66 @@ void testSetGetTableAlignment() throws IOException { assertNull(tbl.getTableAlignment()); } } + + @Test + public void testGetTableIndent() throws Exception { + // open an empty document + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("table-indent.docx")) { + + XWPFTable table1 = doc.getTableArray(0); + // Indent not present in the document + assertFalse(table1.isSetIndent()); + assertEquals(0, table1.getIndent()); + + XWPFTable table2 = doc.getTableArray(1); + // Valid indent value with type dxa + assertTrue(table2.isSetIndent()); + assertEquals(732, table2.getIndent()); + + XWPFTable table3 = doc.getTableArray(2); + // Indent is of type "nil" + assertTrue(table3.isSetIndent()); + assertEquals(0, table3.getIndent()); + + XWPFTable table4 = doc.getTableArray(3); + // Indent is of type "pct" which should be ignored + assertFalse(table4.isSetIndent()); + assertEquals(0, table4.getIndent()); + + XWPFTable table5 = doc.getTableArray(4); + // Indent is of type "auto" which should be ignored + assertFalse(table5.isSetIndent()); + assertEquals(0, table5.getIndent()); + + XWPFTable table6 = doc.getTableArray(5); + // Valid indent value with empty type (defaults to dxa) + assertTrue(table6.isSetIndent()); + assertEquals(732, table6.getIndent()); + + XWPFTable table7 = doc.getTableArray(6); + // Valid indent value, negative values are allowed + assertTrue(table7.isSetIndent()); + assertEquals(-500, table7.getIndent()); + } + } + + @Test + void testSetGetTableIndent() throws IOException { + try (XWPFDocument doc = new XWPFDocument()) { + XWPFTable tbl = doc.createTable(1, 1); + assertFalse(tbl.isSetIndent()); + tbl.setIndent(100); + assertTrue(tbl.isSetIndent()); + assertEquals(100, tbl.getIndent()); + tbl.setIndent(0); + assertTrue(tbl.isSetIndent()); + assertEquals(0, tbl.getIndent()); + tbl.setIndent(-100); + assertTrue(tbl.isSetIndent()); + assertEquals(-100, tbl.getIndent()); + tbl.removeIndent(); + assertFalse(tbl.isSetIndent()); + assertEquals(0, tbl.getIndent()); + } + } Review Comment: And done! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org