--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.xwpf.usermodel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Sets alignment values allowed for Tables and Table Rows
+ */
+public enum TableRowAlign {
+
+ LEFT(1),
+ CENTER(2),
+ RIGHT(3);
+
+ private static Map<Integer, TableRowAlign> imap = new HashMap<>();
+
+ static {
+ for (TableRowAlign p : values()) {
+ imap.put(p.getValue(), p);
+ }
+ }
+
+ private final int value;
+
+ private TableRowAlign(int val) {
+ value = val;
+ }
+
+ public static TableRowAlign valueOf(int type) {
+ TableRowAlign err = imap.get(type);
+ if (err == null) throw new IllegalArgumentException("Unknown table row alignment: " + type);
+ return err;
+ }
+
+ public int getValue() {
+ return value;
+ }
+}
import org.apache.poi.util.Removal;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTString;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
/**
: null;
}
+ /**
+ * Returns the current table alignment or NULL
+ *
+ * @return Table Alignment as a {@link TableRowAlign} enum
+ */
+ public TableRowAlign getTableAlignment() {
+ CTTblPr tPr = getTblPr(false);
+ return tPr == null ? null
+ : tPr.isSetJc() ? TableRowAlign.valueOf(tPr.getJc().getVal().intValue())
+ : null;
+ }
+
+ /**
+ * Set table alignment to specified {@link TableRowAlign}
+ *
+ * @param ha {@link TableRowAlign} to set
+ */
+ public void setTableAlignment(TableRowAlign tra) {
+ CTTblPr tPr = getTblPr(true);
+ CTJc jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
+ jc.setVal(STJc.Enum.forInt(tra.getValue()));
+ }
+
+ /**
+ * Removes the table alignment attribute from a table
+ */
+ public void removeTableAlignment() {
+ CTTblPr tPr = getTblPr(false);
+ if (tPr != null && tPr.isSetJc()) {
+ tPr.unsetJc();
+ }
+ }
+
private void addColumn(XWPFTableRow tabRow, int sizeCol) {
if (sizeCol > 0) {
for (int i = 0; i < sizeCol; i++) {
THIN_THICK_MEDIUM_GAP, THICK_THIN_MEDIUM_GAP, THIN_THICK_THIN_MEDIUM_GAP,
THIN_THICK_LARGE_GAP, THICK_THIN_LARGE_GAP, THIN_THICK_THIN_LARGE_GAP,
WAVE, DOUBLE_WAVE, DASH_SMALL_GAP, DASH_DOT_STROKED, THREE_D_EMBOSS, THREE_D_ENGRAVE,
- OUTSET, INSET
+ OUTSET, INSET;
}
}
==================================================================== */
package org.apache.poi.xwpf.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.math.BigInteger;
import java.util.List;
-import junit.framework.TestCase;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType;
+import org.junit.Test;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+
/**
* Tests for XWPF Tables
*/
-public class TestXWPFTable extends TestCase {
- @Override
- protected void setUp() {
- /*
- XWPFDocument doc = new XWPFDocument();
- p = doc.createParagraph();
-
- this.ctRun = CTR.Factory.newInstance();
- */
- }
+public class TestXWPFTable {
+ @Test
public void testConstructor() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
}
}
+ @Test
public void testTblGrid() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
}
}
+ @Test
public void testGetText() {
XWPFDocument doc = new XWPFDocument();
CTTbl table = CTTbl.Factory.newInstance();
}
}
-
+ @Test
public void testCreateRow() {
XWPFDocument doc = new XWPFDocument();
}
}
-
+ @Test
public void testSetGetWidth() {
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetHeight() {
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetMargins() {
// instantiate the following class so it'll get picked up by
// the XmlBean process and added to the jar file. it's required
}
}
+ @Test
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
}
}
+ @Test
public void testSetGetVBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetTopBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetBottomBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetLeftBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetRightBorders() {
// create a table
XWPFDocument doc = new XWPFDocument();
}
}
+ @Test
public void testSetGetRowBandSize() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
}
}
+ @Test
public void testSetGetColBandSize() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
}
}
+ @Test
public void testCreateTable() throws Exception {
// open an empty document
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
fail("Unable to close doc");
}
}
+
+ @Test
+ public void testSetGetTableAlignment() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFTable tbl = doc.createTable(1, 1);
+ tbl.setTableAlignment(TableRowAlign.LEFT);
+ assertEquals(TableRowAlign.LEFT, tbl.getTableAlignment());
+ tbl.setTableAlignment(TableRowAlign.CENTER);
+ assertEquals(TableRowAlign.CENTER, tbl.getTableAlignment());
+ tbl.setTableAlignment(TableRowAlign.RIGHT);
+ assertEquals(TableRowAlign.RIGHT, tbl.getTableAlignment());
+ tbl.removeTableAlignment();
+ assertNull(tbl.getTableAlignment());
+ try {
+ doc.close();
+ } catch (IOException e) {
+ fail("Unable to close doc");
+ }
+ }
}
\ No newline at end of file