<!-- See https://www.ecma-international.org/publications/standards/Ecma-376.htm -->
<!-- "Copy these file(s), free of charge" -->
- <property name="ooxml.xsds.izip.1" value="${basedir}/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema.zip"/>
+ <property name="ooxml.xsds.izip.1" value="${basedir}/src/ooxml/resources/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip"/>
<property name="ooxml.xsds.src.dir" location="build/ooxml-xsds-src"/>
<property name="ooxml.xsds.src.jar" location="build/dist/maven/ooxml-schemas/ooxml-schemas-${maven.ooxml.xsds.version.id}-sources.jar"/>
<property name="ooxml.xsds.jar" location="build/dist/maven/ooxml-schemas/ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
<!-- additional schemas are packed into the poi schemas jar, -->
- <!-- so we don't have to care about a seperate versioning of the original ooxml schemas -->
+ <!-- so we don't have to care about a separate versioning of the original ooxml schemas -->
<property name="ooxml.xsds.izip.2" value="${basedir}/src/ooxml/resources/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip"/>
<property name="ooxml.security.src.dir" location="build/ooxml-security-src"/>
<property name="ooxml.security.xsd.dir" location="src/ooxml/resources/org/apache/poi/poifs/crypt"/>
public static final int EMU_PER_POINT = 12700;
public static final int EMU_PER_CENTIMETER = 360000;
+ /** 72 points per inch (dpi) */
+ public static final int EMU_PER_INCH = 12700*72;
+
+ /** EMU_PER_POINT/20 */
+ public static final int EMU_PER_DXA = 635;
+
/**
* Master DPI (576 pixels per inch).
* Used by the reference coordinate system in PowerPoint (HSLF)
*/
- public static final int MASTER_DPI = 576;
+ public static final int MASTER_DPI = 576;
/**
* Pixels DPI (96 pixels per inch)
/**
* Points DPI (72 pixels per inch)
*/
- public static final int POINT_DPI = 72;
+ public static final int POINT_DPI = 72;
/**
/**
* Column widths are in fractional characters, this is the EMU equivalent.
- * One character is defined as the widest value for the integers 0-9 in the
+ * One character is defined as the widest value for the integers 0-9 in the
* default font.
*/
public static final int EMU_PER_CHARACTER = (int) (EMU_PER_PIXEL * DEFAULT_CHARACTER_WIDTH);
public static int toEMU(double points){
return (int)Math.rint(EMU_PER_POINT*points);
}
-
+
/**
* Converts pixels to EMUs
* @param pixels pixels
* @return points
*/
public static double toPoints(long emu){
- return (double)emu/EMU_PER_POINT;
+ return (emu == -1) ? -1.d : (double)emu/EMU_PER_POINT;
}
-
+
/**
* Converts a value of type FixedPoint to a floating point
*
* @param fixedPoint value in fixed point notation
* @return floating point (double)
- *
+ *
* @see <a href="http://msdn.microsoft.com/en-us/library/dd910765(v=office.12).aspx">[MS-OSHARED] - 2.2.1.6 FixedPoint</a>
*/
public static double fixedPointToDouble(int fixedPoint) {
int f = fixedPoint & 0xFFFF;
return (i + f/65536d);
}
-
+
/**
* Converts a value of type floating point to a FixedPoint
*
* @param floatPoint value in floating point notation
* @return fixedPoint value in fixed points notation
- *
+ *
* @see <a href="http://msdn.microsoft.com/en-us/library/dd910765(v=office.12).aspx">[MS-OSHARED] - 2.2.1.6 FixedPoint</a>
*/
public static int doubleToFixedPoint(double floatPoint) {
points /= POINT_DPI;
return (int)Math.rint(points);
}
-
+
public static int pointsToPixel(double points) {
points *= PIXEL_DPI;
points /= POINT_DPI;
public static int charactersToEMU(double characters) {
return (int) characters * EMU_PER_CHARACTER;
}
-
+
/**
* @param columnWidth specified in 256ths of a standard character
* @return equivalent EMUs
public static int columnWidthToEMU(int columnWidth) {
return charactersToEMU(columnWidth / 256d);
}
-
- /**
- * @param twips (1/20th of a point) typically used for row heights
- * @return equivalent EMUs
- */
- public static int TwipsToEMU(short twips) {
- return (int) (twips / 20d * EMU_PER_POINT);
+
+ public static double toDXA(long emu) {
+ return (emu == -1) ? -1.d : (double)emu/EMU_PER_DXA;
}
}
exports org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes;
exports org.openxmlformats.schemas.officeDocument.x2006.extendedProperties;
exports org.openxmlformats.schemas.officeDocument.x2006.relationships;
+ exports org.openxmlformats.schemas.officeDocument.x2006.sharedTypes;
exports org.openxmlformats.schemas.presentationml.x2006.main;
exports org.openxmlformats.schemas.spreadsheetml.x2006.main;
exports org.openxmlformats.schemas.wordprocessingml.x2006.main;
--- /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.ooxml.util;
+
+import static org.apache.poi.util.Units.EMU_PER_DXA;
+import static org.apache.poi.util.Units.EMU_PER_INCH;
+import static org.apache.poi.util.Units.EMU_PER_POINT;
+
+import java.util.Locale;
+
+public class POIXMLUnits {
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STPositivePercentage pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STPositiveFixedPercentage pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STPercentage pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Specifies the percentage of the text size that this bullet should be. It is specified here in terms of
+ * 100% being equal to 100000 and 1% being specified in increments of 1000. This attribute should not be
+ * lower than 25%, or 25000, and not be higher than 400%, or 400000.
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STTextBulletSizePercent pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STTextSpacingPercentOrPercentString pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * Office will read percentages formatted with a trailing percent sign or formatted
+ * as 1000th of a percent without a trailing percent sign
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.main.STTextFontScalePercentOrPercentString pctUnion) {
+ return parsePercentInner(pctUnion, 1);
+ }
+
+ /**
+ * This type seems to be interpreted as percent value when the trailing percent sign is missing.<br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * <w:zoom w:percent="50" />
+ * <pre>
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.wordprocessingml.x2006.main.STDecimalNumberOrPercent pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+ /**
+ * This type seems to be interpreted as percent value when the trailing percent sign is missing.<br/>
+ * sample snippet from settings.xml
+ * <pre>
+ * <w:textscale w:w="50" />
+ * <pre>
+ *
+ * @return the percent scaled by 1000, so 100% = 100000
+ */
+ public static int parsePercent(org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextScale pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STGapAmount pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STOverlap pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STDepthPercent pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ public static int parsePercent(org.openxmlformats.schemas.drawingml.x2006.chart.STHPercent pctUnion) {
+ return parsePercentInner(pctUnion, 1000);
+ }
+
+
+ private static int parsePercentInner(org.apache.xmlbeans.XmlAnySimpleType pctUnion, int noUnitScale) {
+ String strVal = pctUnion.getStringValue();
+ if (strVal.endsWith("%")) {
+ return Integer.parseInt(strVal.substring(0, strVal.length()-1)) * 1000;
+ } else {
+ return Integer.parseInt(strVal) * noUnitScale;
+ }
+ }
+
+ /**
+ * The standard states that ST_Coordinate32 is read and written as either a length
+ * followed by a unit, or EMUs with no unit present.
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.drawingml.x2006.main.STCoordinate32 coordUnion) {
+ return parseLengthInner(coordUnion, 1d);
+ }
+
+ /**
+ * The standard states that ST_Coordinate is read and written as either a length
+ * followed by a unit, or EMUs with no unit present.
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.drawingml.x2006.main.STCoordinate coordUnion) {
+ return parseLengthInner(coordUnion, 1d);
+ }
+
+ /**
+ * The standard states that ST_TextPoint is read and written as a length followed by a unit
+ * or as hundredths of a point with no unit present.
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.drawingml.x2006.main.STTextPoint coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_POINT/100d);
+ }
+
+ /**
+ * If no unit is specified, a twips-measure is a twentieth of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTwipsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_DXA);
+ }
+
+ /**
+ * If no unit is specified, a twips-measure is a twentieth of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STSignedTwipsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_DXA);
+ }
+
+ /**
+ * If no unit is specified, a hps-measure is a half of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STHpsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_POINT*2d);
+ }
+
+
+ /**
+ * If no unit is specified, a hps-measure is a half of a point
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STSignedHpsMeasure coordUnion) {
+ return parseLengthInner(coordUnion, EMU_PER_POINT*2d);
+ }
+
+
+ /**
+ * If not unit is specified, DXA (twentieth of a point) is assumed
+ *
+ * @return length in EMUs
+ */
+ public static long parseLength(org.openxmlformats.schemas.wordprocessingml.x2006.main.STMeasurementOrPercent coordUnion) {
+ if (coordUnion.getStringValue().endsWith("%")) return -1;
+ return parseLengthInner(coordUnion, EMU_PER_DXA);
+ }
+
+
+ /**
+ * Returns the EMUs for the given measurment (mm|cm|in|pt|pc|pi, defaults to EMUs*noUnitEmuFactor if not specified)
+ *
+ * @param coordUnion the raw type
+ * @return the EMUs for the given attribute
+ */
+ private static long parseLengthInner(org.apache.xmlbeans.XmlAnySimpleType coordUnion, double noUnitEmuFactor) {
+ String strVal = coordUnion.getStringValue().toLowerCase(Locale.ROOT);
+ double digVal = Double.parseDouble(strVal.replaceAll("(mm|cm|in|pt|pc|pi)", ""));
+ long emu = 0;
+ // http://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
+ if (strVal.endsWith("mm")) {
+ emu = (long)(((digVal/10f)/2.54f)*EMU_PER_INCH);
+ } else if (strVal.endsWith("cm")) {
+ emu = (long)((digVal/2.54f)*EMU_PER_INCH);
+ } else if (strVal.endsWith("in")) {
+ emu = (long)(digVal*EMU_PER_INCH);
+ } else if (strVal.endsWith("pc") || strVal.endsWith("pi")) {
+ emu = (long)(digVal*0.166f*EMU_PER_INCH);
+ } else if (strVal.endsWith("pt")) {
+ emu = (long)(digVal*EMU_PER_POINT);
+ } else {
+ emu = (long)(digVal*noUnitEmuFactor);
+ }
+ return emu;
+ }
+
+
+
+ public static boolean parseOnOff(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff onOff) {
+ if(onOff == null) return false;
+ if(!onOff.isSetVal()) return true;
+ return parseOnOff(onOff.xgetVal());
+ }
+
+ public static boolean parseOnOff(org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff onOff) {
+ if (onOff == null) return false;
+ String str = onOff.getStringValue();
+ return ("true".equalsIgnoreCase(str) || "on".equalsIgnoreCase(str) || "x".equalsIgnoreCase(str) || "1".equals(str));
+ }
+
+}
import javax.xml.namespace.QName;
import com.microsoft.schemas.office.office.CTSignatureLine;
-import com.microsoft.schemas.office.office.STTrueFalse;
import com.microsoft.schemas.vml.CTGroup;
import com.microsoft.schemas.vml.CTImageData;
import com.microsoft.schemas.vml.CTShape;
import org.apache.poi.sl.draw.ImageRenderer;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
/**
* Base class for SignatureLines (XSSF,XWPF only)
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlObject;
}
public int getSaturation() {
- return color.getSat2();
+ return POIXMLUnits.parsePercent(color.xgetSat2()) / 1000;
}
public void setSaturation(int saturation) {
}
public int getLuminance() {
- return color.getLum2();
+ return POIXMLUnits.parsePercent(color.xgetLum2()) / 1000;
}
public void setLuminance(int lightness) {
}
public PresetColor getValue() {
- if (color.isSetVal()) {
+ if (color.xgetVal() != null) {
return PresetColor.valueOf(color.getVal());
} else {
return null;
public void setValue(PresetColor value) {
if (value == null) {
- if (color.isSetVal()) {
- color.unsetVal();
+ if (color.xgetVal() != null) {
+ // TODO: val is a requires attribute - removing a preset must be done in the parent container
+ color.setVal(PresetColor.WHITE.underlying);
}
} else {
color.setVal(value.underlying);
import java.util.Locale;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPercentage;
@Beta
public class XDDFColorRgbPercent extends XDDFColor {
- private CTScRgbColor color;
+ private final CTScRgbColor color;
public XDDFColorRgbPercent(int red, int green, int blue) {
this(CTScRgbColor.Factory.newInstance(), CTColor.Factory.newInstance());
}
public int getRed() {
- return color.getR();
+ return POIXMLUnits.parsePercent(color.xgetR());
}
public void setRed(int red) {
}
public int getGreen() {
- return color.getG();
+ return POIXMLUnits.parsePercent(color.xgetG());
}
public void setGreen(int green) {
}
public int getBlue() {
- return color.getB();
+ return POIXMLUnits.parsePercent(color.xgetB());
}
public void setBlue(int blue) {
}
private int normalize(int value) {
- if (value < 0) {
- return 0;
- }
- if (100_000 < value) {
- return 100_000;
- }
- return value;
+ return value < 0 ? 0 : Math.min(100_000, value);
}
public String toRGBHex() {
- StringBuilder sb = new StringBuilder(6);
- appendHex(sb, color.getR());
- appendHex(sb, color.getG());
- appendHex(sb, color.getB());
- return sb.toString().toUpperCase(Locale.ROOT);
- }
-
- private void appendHex(StringBuilder sb, int value) {
- int b = value * 255 / 100_000;
- sb.append(String.format(Locale.ROOT, "%02X", b));
+ int c = 0;
+ for (STPercentage pct : new STPercentage[] { color.xgetR(), color.xgetG(), color.xgetB() }) {
+ c = c << 8 | ((POIXMLUnits.parsePercent(pct) * 255 / 100_000) & 0xFF);
+ }
+ return String.format(Locale.ROOT, "%06X", c);
}
}
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTDashStop;
}
public int getDashLength() {
- return stop.getD();
+ return POIXMLUnits.parsePercent(stop.xgetD());
}
public void setDashLength(int length) {
}
public int getSpaceLength() {
- return stop.getSp();
+ return POIXMLUnits.parsePercent(stop.xgetSp());
}
public void setSpaceLength(int length) {
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTGradientStop;
}
public int getPosition() {
- return stop.getPos();
+ return POIXMLUnits.parsePercent(stop.xgetPos());
}
public void setPosition(int position) {
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineJoinMiterProperties;
public Integer getLimit() {
if (join.isSetLim()) {
- return join.getLim();
+ return POIXMLUnits.parsePercent(join.xgetLim());
} else {
return null;
}
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
if (point == null) {
return x;
} else {
- return point.getX();
+ return POIXMLUnits.parseLength(point.xgetX());
}
}
if (point == null) {
return y;
} else {
- return point.getY();
+ return POIXMLUnits.parseLength(point.xgetY());
}
}
}
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRelativeRect;
@Beta
public class XDDFRelativeRectangle {
- private CTRelativeRect rect;
+ private final CTRelativeRect rect;
public XDDFRelativeRectangle() {
this(CTRelativeRect.Factory.newInstance());
public Integer getBottom() {
if (rect.isSetB()) {
- return rect.getB();
+ return POIXMLUnits.parsePercent(rect.xgetB());
} else {
return null;
}
public Integer getLeft() {
if (rect.isSetL()) {
- return rect.getL();
+ return POIXMLUnits.parsePercent(rect.xgetL());
} else {
return null;
}
public Integer getRight() {
if (rect.isSetR()) {
- return rect.getR();
+ return POIXMLUnits.parsePercent(rect.xgetR());
} else {
return null;
}
public Integer getTop() {
if (rect.isSetT()) {
- return rect.getT();
+ return POIXMLUnits.parsePercent(rect.xgetT());
} else {
return null;
}
package org.apache.poi.xddf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTileInfoProperties;
public Integer getSx() {
if (props.isSetSx()) {
- return props.getSx();
+ return POIXMLUnits.parsePercent(props.xgetSx());
} else {
return null;
}
public Integer getSy() {
if (props.isSetSy()) {
- return props.getSy();
+ return POIXMLUnits.parsePercent(props.xgetSy());
} else {
return null;
}
public Long getTx() {
if (props.isSetTx()) {
- return props.getTx();
+ return POIXMLUnits.parseLength(props.xgetTx());
} else {
return null;
}
public Long getTy() {
if (props.isSetTy()) {
- return props.getTy();
+ return POIXMLUnits.parseLength(props.xgetTy());
} else {
return null;
}
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
}
public Integer getGapDepth() {
- if (chart.isSetGapDepth()) {
- return chart.getGapDepth().getVal();
- } else {
- return null;
- }
+ return chart.isSetGapDepth() ? POIXMLUnits.parsePercent(chart.getGapDepth().xgetVal()) / 1000 : null;
}
public void setGapDepth(Integer depth) {
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
}
public Integer getGapDepth() {
- if (chart.isSetGapDepth()) {
- return chart.getGapDepth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapDepth()) ? POIXMLUnits.parsePercent(chart.getGapDepth().xgetVal()) / 1000 : null;
}
public void setGapDepth(Integer depth) {
}
public Integer getGapWidth() {
- if (chart.isSetGapWidth()) {
- return chart.getGapWidth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapWidth()) ? POIXMLUnits.parsePercent(chart.getGapWidth().xgetVal()) / 1000 : null;
}
public void setGapWidth(Integer width) {
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
}
public Integer getGapWidth() {
- if (chart.isSetGapWidth()) {
- return chart.getGapWidth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapWidth()) ? (int)(POIXMLUnits.parsePercent(chart.getGapWidth().xgetVal()) / 1000.) : null;
}
public void setGapWidth(Integer width) {
}
public Byte getOverlap() {
- if (chart.isSetOverlap()) {
- return chart.getOverlap().getVal();
- } else {
- return null;
- }
+ return chart.isSetOverlap() ? (byte)(POIXMLUnits.parsePercent(chart.getOverlap().xgetVal())/1000) : null;
}
/**
import java.util.Map;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
}
public Integer getGapDepth() {
- if (chart.isSetGapDepth()) {
- return chart.getGapDepth().getVal();
- } else {
- return null;
- }
+ return (chart.isSetGapDepth()) ? POIXMLUnits.parsePercent(chart.getGapDepth().xgetVal()) / 1000 : null;
}
public void setGapDepth(Integer depth) {
package org.apache.poi.xddf.usermodel.chart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTView3D;
}
public Integer getDepthPercent() {
- if (view3D.isSetDepthPercent()) {
- return view3D.getDepthPercent().getVal();
- } else {
- return null;
- }
+ return (view3D.isSetDepthPercent()) ? POIXMLUnits.parsePercent(view3D.getDepthPercent().xgetVal()) : null;
}
public void setDepthPercent(Integer percent) {
}
public Integer getHPercent() {
- if (view3D.isSetHPercent()) {
- return view3D.getHPercent().getVal();
- } else {
- return null;
- }
+ return (view3D.isSetHPercent()) ? POIXMLUnits.parsePercent(view3D.getHPercent().xgetVal()) : null;
}
public void setHPercent(Integer percent) {
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
public Double getBottomInset() {
if (props.isSetBIns()) {
- return Units.toPoints(props.getBIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetBIns()));
} else {
return null;
}
public Double getLeftInset() {
if (props.isSetLIns()) {
- return Units.toPoints(props.getLIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetLIns()));
} else {
return null;
}
public Double getRightInset() {
if (props.isSetRIns()) {
- return Units.toPoints(props.getRIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetRIns()));
} else {
return null;
}
public Double getTopInset() {
if (props.isSetTIns()) {
- return Units.toPoints(props.getTIns());
+ return Units.toPoints(POIXMLUnits.parseLength(props.xgetTIns()));
} else {
return null;
}
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePercent;
}
public double getPercent() {
- return percent.getVal() * scale;
+ return POIXMLUnits.parsePercent(percent.xgetVal()) * scale;
}
public void setPercent(double value) {
- percent.setVal(Math.toIntExact(Math.round(1000 * value)));
+ percent.setVal(Long.toString(Math.round(1000 * value)));
}
}
public XDDFFont(FontGroup group, String typeface, Byte charset, Byte pitch, byte[] panose) {
this(group, CTTextFont.Factory.newInstance());
if (typeface == null) {
- if (font.isSetTypeface()) {
- font.unsetTypeface();
+ if (font.getTypeface() != null && !font.getTypeface().equals("")) {
+ font.setTypeface("");
}
} else {
font.setTypeface(typeface);
}
public String getTypeface() {
- if (font.isSetTypeface()) {
- return font.getTypeface();
- } else {
- return null;
- }
+ return font.getTypeface();
}
public Byte getCharset() {
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit;
@Override
public int getFontScale() {
if (autofit.isSetFontScale()) {
- return autofit.getFontScale();
+ return POIXMLUnits.parsePercent(autofit.xgetFontScale());
} else {
return 100_000;
}
@Override
public int getLineSpaceReduction() {
if (autofit.isSetLnSpcReduction()) {
- return autofit.getLnSpcReduction();
+ return POIXMLUnits.parsePercent(autofit.xgetLnSpcReduction());
} else {
return 0;
}
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing;
}
public double getPercent() {
- return percent.getVal() * scale;
+ return POIXMLUnits.parsePercent(percent.xgetVal()) * scale;
}
public void setPercent(double value) {
package org.apache.poi.xddf.usermodel.text;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
public Double getPosition() {
if (stop.isSetPos()) {
- return Units.toPoints(stop.getPos());
+ return Units.toPoints(POIXMLUnits.parseLength(stop.xgetPos()));
} else {
return null;
}
import org.apache.commons.collections4.iterators.IteratorIterable;
import org.apache.commons.collections4.iterators.ReverseListIterator;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
public Double getDefaultTabSize() {
return findDefinedParagraphProperty(
CTTextParagraphProperties::isSetDefTabSz,
- CTTextParagraphProperties::getDefTabSz)
- .map(Units::toPoints).orElse(null);
+ CTTextParagraphProperties::xgetDefTabSz)
+ .map(POIXMLUnits::parseLength).map(Units::toPoints).orElse(null);
}
/**
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.ooxml.POIXMLRelation;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackagePartName;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.apache.poi.xddf.usermodel.XDDFColor;
import org.apache.poi.xddf.usermodel.XDDFFillProperties;
import org.apache.poi.xddf.usermodel.XDDFLineProperties;
public boolean isSubscript() {
return findDefinedProperty(
CTTextCharacterProperties::isSetBaseline,
- CTTextCharacterProperties::getBaseline)
+ CTTextCharacterProperties::xgetBaseline)
+ .map(POIXMLUnits::parsePercent)
.map(baseline -> baseline < 0)
.orElse(false);
}
public boolean isSuperscript() {
return findDefinedProperty(
CTTextCharacterProperties::isSetBaseline,
- CTTextCharacterProperties::getBaseline)
+ CTTextCharacterProperties::xgetBaseline)
+ .map(POIXMLUnits::parsePercent)
.map(baseline -> baseline > 0)
.orElse(false);
}
public Double getCharacterSpacing() {
return findDefinedProperty(
CTTextCharacterProperties::isSetSpc,
- CTTextCharacterProperties::getSpc)
- .map(spacing -> 0.01 * spacing)
+ CTTextCharacterProperties::xgetSpc)
+ .map(POIXMLUnits::parseLength)
+ .map(Units::toPoints)
.orElse(null);
}
import javax.xml.namespace.QName;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.AbstractColorStyle;
import org.apache.poi.sl.usermodel.ColorStyle;
private static final POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class);
private static final QName VAL_ATTR = new QName("val");
- private XmlObject _xmlObject;
- private Color _color;
- private CTSchemeColor _phClr;
- private XSLFSheet _sheet;
+ private final XmlObject _xmlObject;
+ private final Color _color;
+ private final CTSchemeColor _phClr;
+ private final XSLFSheet _sheet;
@SuppressWarnings("WeakerAccess")
public XSLFColor(XmlObject obj, XSLFTheme theme, CTSchemeColor phClr, XSLFSheet sheet) {
private Color toColor(CTHslColor hsl) {
return DrawPaint.HSL2RGB(
hsl.getHue2() / 60000d,
- hsl.getSat2() / 1000d,
- hsl.getLum2() / 1000d,
+ POIXMLUnits.parsePercent(hsl.xgetSat2()) / 1000d,
+ POIXMLUnits.parsePercent(hsl.xgetLum2()) / 1000d,
1d);
}
private Color toColor(CTScRgbColor scrgb) {
// percental [0..100000] scRGB color space needs to be gamma corrected for AWT/sRGB colorspace
- return DrawPaint.SCRGB2RGB(scrgb.getR()/100_000d,scrgb.getG()/100_000d,scrgb.getB()/100_000d);
+ return DrawPaint.SCRGB2RGB(
+ POIXMLUnits.parsePercent(scrgb.xgetR())/100_000d,
+ POIXMLUnits.parsePercent(scrgb.xgetG())/100_000d,
+ POIXMLUnits.parsePercent(scrgb.xgetB())/100_000d);
}
private Color toColor(CTSRgbColor srgb) {
}
private static class XSLFColorStyle extends AbstractColorStyle {
- private XmlObject xmlObject;
- private Color color;
- private CTSchemeColor phClr;
+ private final XmlObject xmlObject;
+ private final Color color;
+ private final CTSchemeColor phClr;
XSLFColorStyle(XmlObject xmlObject, Color color, CTSchemeColor phClr) {
this.xmlObject = xmlObject;
import java.util.Calendar;
import java.util.Date;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.usermodel.Comment;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.Units;
@Override
public Point2D getOffset() {
final CTPoint2D pos = comment.getPos();
- return new Point2D.Double(Units.toPoints(pos.getX()), Units.toPoints(pos.getY()));
+ return new Point2D.Double(
+ Units.toPoints(POIXMLUnits.parseLength(pos.xgetX())),
+ Units.toPoints(POIXMLUnits.parseLength(pos.xgetY())));
}
@Override
import javax.xml.stream.XMLStreamReader;
import org.apache.poi.ooxml.POIXMLTypeLoader;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.geom.CustomGeometry;
import org.apache.poi.sl.draw.geom.PresetGeometries;
import org.apache.poi.sl.usermodel.FreeformShape;
numPoints += Math.max(points.length, 1);
it.next();
}
-
+
XmlObject xo = getShapeProperties();
if (!(xo instanceof CTShapeProperties)) {
return -1;
if (!(xo instanceof CTShapeProperties)) {
return null;
}
-
+
final CTCustomGeometry2D geom = ((CTShapeProperties)xo).getCustGeom();
- //noinspection deprecation
for(CTPath2D spPath : geom.getPathLst().getPathArray()){
XmlCursor cursor = spPath.newCursor();
try {
final CTTransform2D xfrm = getXfrm(false);
final Rectangle2D xfrm2d = new Rectangle2D.Double
- (xfrm.getOff().getX(), xfrm.getOff().getY(), xfrm.getExt().getCx(), xfrm.getExt().getCy());
+ (POIXMLUnits.parseLength(xfrm.getOff().xgetX()), POIXMLUnits.parseLength(xfrm.getOff().xgetY()), xfrm.getExt().getCx(), xfrm.getExt().getCy());
final Rectangle2D bounds = getAnchor();
at.translate(bounds.getX()+bounds.getCenterX(), bounds.getY()+bounds.getCenterY());
import java.util.Arrays;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.sl.usermodel.Insets2D;
import org.apache.poi.sl.usermodel.PaintStyle;
new CTGradientStop[0] : gradFill.getGsLst().getGsArray();
Arrays.sort(gs, (o1, o2) -> {
- int pos1 = o1.getPos();
- int pos2 = o2.getPos();
+ int pos1 = POIXMLUnits.parsePercent(o1.xgetPos());
+ int pos2 = POIXMLUnits.parsePercent(o2.xgetPos());
return Integer.compare(pos1, pos2);
});
phClrCgs = cgs.getSchemeClr();
}
cs[i] = new XSLFColor(cgs, theme, phClrCgs, sheet).getColorStyle();
- fractions[i] = cgs.getPos() / 100000.f;
+ fractions[i] = POIXMLUnits.parsePercent(cgs.xgetPos()) / 100000.f;
i++;
}
if (gradFill.isSetPath() && gradFill.getPath().isSetFillToRect()) {
final double base = 100_000;
CTRelativeRect rect = gradFill.getPath().getFillToRect();
- return new Insets2D(rect.getT()/base, rect.getL()/base, rect.getB()/base, rect.getR()/base);
+ return new Insets2D(
+ POIXMLUnits.parsePercent(rect.xgetT())/base,
+ POIXMLUnits.parsePercent(rect.xgetL())/base,
+ POIXMLUnits.parsePercent(rect.xgetB())/base,
+ POIXMLUnits.parsePercent(rect.xgetR())/base
+ );
}
return null;
}
import javax.xml.namespace.QName;
import org.apache.poi.ooxml.POIXMLException;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
public Rectangle2D getAnchor(){
CTTransform2D xfrm = ((CTGraphicalObjectFrame)getXmlObject()).getXfrm();
CTPoint2D off = xfrm.getOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
import java.util.List;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawPictureShape;
import org.apache.poi.sl.usermodel.GroupShape;
import org.apache.poi.sl.usermodel.PictureData;
/**
* Represents a group shape that consists of many shapes grouped together.
- *
+ *
* @author Yegor Kozlov
*/
@Beta
public class XSLFGroupShape extends XSLFShape
implements XSLFShapeContainer, GroupShape<XSLFShape,XSLFTextParagraph> {
private final static POILogger _logger = POILogFactory.getLogger(XSLFGroupShape.class);
-
+
private final List<XSLFShape> _shapes;
private final CTGroupShapeProperties _grpSpPr;
private XSLFDrawing _drawing;
protected CTGroupShapeProperties getGrpSpPr() {
return _grpSpPr;
}
-
+
private CTGroupTransform2D getSafeXfrm() {
CTGroupTransform2D xfrm = getXfrm();
return (xfrm == null ? getGrpSpPr().addNewXfrm() : xfrm);
}
-
+
protected CTGroupTransform2D getXfrm() {
return getGrpSpPr().getXfrm();
}
public Rectangle2D getAnchor(){
CTGroupTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
public Rectangle2D getInteriorAnchor(){
CTGroupTransform2D xfrm = getXfrm();
CTPoint2D off = xfrm.getChOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getChExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
Dimension dim = pictureData.getImageDimension();
oleObj.setImgW(Units.toEMU(dim.getWidth()));
oleObj.setImgH(Units.toEMU(dim.getHeight()));
-
-
+
+
getShapes().add(sh);
sh.setParent(this);
return sh;
}
-
+
public XSLFTable createTable(){
XSLFTable sh = getDrawing().createTable();
_shapes.add(sh);
sh.setParent(this);
return sh;
}
-
+
@Override
public XSLFTable createTable(int numRows, int numCols){
if (numRows < 1 || numCols < 1) {
return sh;
}
-
+
@Override
public void setFlipHorizontal(boolean flip){
getSafeXfrm().setFlipH(flip);
// recursively update each shape
List<XSLFShape> tgtShapes = getShapes();
List<XSLFShape> srcShapes = gr.getShapes();
-
+
// workaround for a call by XSLFSheet.importContent:
// if we have already the same amount of child shapes
// then assume, that we've been called by import content and only need to update the children
for(int i = 0; i < tgtShapes.size(); i++){
XSLFShape s1 = srcShapes.get(i);
XSLFShape s2 = tgtShapes.get(i);
-
+
s2.copy(s1);
}
} else {
// otherwise recreate the shapes from scratch
clear();
-
+
// recursively update each shape
for(XSLFShape shape : srcShapes) {
XSLFShape newShape;
_logger.log(POILogger.WARN, "copying of class "+shape.getClass()+" not supported.");
continue;
}
-
+
newShape.copy(shape);
}
}
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.ooxml.util.XPathHelper;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
@Override
public Insets getClipping(){
CTRelativeRect r = getBlipFill().getSrcRect();
- return (r == null) ? null : new Insets(r.getT(), r.getL(), r.getB(), r.getR());
+
+ return (r == null) ? null : new Insets(
+ POIXMLUnits.parsePercent(r.xgetT()),
+ POIXMLUnits.parsePercent(r.xgetL()),
+ POIXMLUnits.parsePercent(r.xgetB()),
+ POIXMLUnits.parsePercent(r.xgetR()));
}
/**
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.draw.geom.CustomGeometry;
}
CTPoint2D off = xfrm.getOff();
- double x = Units.toPoints(off.getX());
- double y = Units.toPoints(off.getY());
+ double x = Units.toPoints(POIXMLUnits.parseLength(off.xgetX()));
+ double y = Units.toPoints(POIXMLUnits.parseLength(off.xgetY()));
CTPositiveSize2D ext = xfrm.getExt();
double cx = Units.toPoints(ext.getCx());
double cy = Units.toPoints(ext.getCy());
XSLFGeometryProperties gp = XSLFPropertiesDelegate.getGeometryDelegate(getShapeProperties());
if (gp != null && gp.isSetPrstGeom() && gp.getPrstGeom().isSetAvLst()) {
- //noinspection deprecation
for (CTGeomGuide g : gp.getPrstGeom().getAvLst().getGdArray()) {
if (g.getName().equals(name)) {
Guide gd = new Guide();
package org.apache.poi.xslf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.usermodel.TabStop;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStop;
public class XSLFTabStop implements TabStop {
final CTTextTabStop tabStop;
-
+
XSLFTabStop(CTTextTabStop tabStop) {
this.tabStop = tabStop;
}
-
+
/** position in EMUs */
public int getPosition() {
- return tabStop.getPos();
+ return (int)POIXMLUnits.parseLength(tabStop.xgetPos());
}
/** position in EMUs */
public void setPositionInPoints(final double points) {
setPosition(Units.toEMU(points));
}
-
+
public TabStopType getType() {
return TabStopType.fromOoxmlId(tabStop.getAlgn().intValue());
}
import javax.xml.namespace.QName;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.DrawTableShape;
import org.apache.poi.sl.draw.DrawTextShape;
TableShape<XSLFShape,XSLFTextParagraph> {
/* package */ static final String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table";
- private CTTable _table;
- private List<XSLFTableRow> _rows;
+ private final CTTable _table;
+ private final List<XSLFTableRow> _rows;
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){
super(shape, sheet);
@Override
public double getColumnWidth(int idx){
- return Units.toPoints(
- _table.getTblGrid().getGridColArray(idx).getW());
+ return Units.toPoints(POIXMLUnits.parseLength(
+ _table.getTblGrid().getGridColArray(idx).xgetW()));
}
@Override
@Override
public double getRowHeight(int row) {
- return Units.toPoints(_table.getTrArray(row).getH());
+ return Units.toPoints(POIXMLUnits.parseLength(_table.getTrArray(row).xgetH()));
}
@Override
* @since POI 4.1.2
*/
public void addColumn() {
- long width = _table.getTblGrid().getGridColArray(getNumberOfColumns() - 1).getW();
+ long width = POIXMLUnits.parseLength(_table.getTblGrid().getGridColArray(getNumberOfColumns() - 1).xgetW());
CTTableCol col = _table.getTblGrid().addNewGridCol();
col.setW(width);
for (XSLFTableRow row : _rows) {
if (getNumberOfColumns() < colIdx) {
throw new IndexOutOfBoundsException("Cannot insert column at " + colIdx + "; table has only " + getNumberOfColumns() + "columns.");
}
- long width = _table.getTblGrid().getGridColArray(colIdx).getW();
+ long width = POIXMLUnits.parseLength(_table.getTblGrid().getGridColArray(colIdx).xgetW());
CTTableCol col = _table.getTblGrid().insertNewGridCol(colIdx);
col.setW(width);
for (XSLFTableRow row : _rows) {
import java.util.Iterator;
import java.util.List;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
/*package*/ XSLFTableRow(CTTableRow row, XSLFTable table){
_row = row;
_table = table;
- @SuppressWarnings("deprecation")
CTTableCell[] tcArray = _row.getTcArray();
_cells = new ArrayList<>(tcArray.length);
for(CTTableCell cell : tcArray) {
}
public double getHeight(){
- return Units.toPoints(_row.getH());
+ return Units.toPoints(POIXMLUnits.parseLength(_row.xgetH()));
}
public void setHeight(double height){
import java.util.function.Function;
import java.util.function.Supplier;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.AutoNumberingScheme;
import org.apache.poi.sl.usermodel.PaintStyle;
private static void fetchBulletFontSize(CTTextParagraphProperties props, Consumer<Double> val) {
if(props.isSetBuSzPct()){
- val.accept(props.getBuSzPct().getVal() * 0.001);
+ val.accept(POIXMLUnits.parsePercent(props.getBuSzPct().xgetVal()) * 0.001);
}
if(props.isSetBuSzPts()){
val.accept( - props.getBuSzPts().getVal() * 0.01);
if(bulletSize >= 0) {
CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct();
- pt.setVal((int)(bulletSize*1000));
+ pt.setVal(Integer.toString((int)(bulletSize*1000)));
if(pr.isSetBuSzPts()) {
pr.unsetBuSzPts();
}
public Double getDefaultTabSize(){
return fetchParagraphProperty((props, val) -> {
if (props.isSetDefTabSz()) {
- val.accept(Units.toPoints(props.getDefTabSz()));
+ val.accept(Units.toPoints(POIXMLUnits.parseLength(props.xgetDefTabSz())));
}
});
}
CTTextTabStopList tabStops = props.getTabLst();
if(idx < tabStops.sizeOfTabArray() ) {
CTTextTabStop ts = tabStops.getTabArray(idx);
- val.accept(Units.toPoints(ts.getPos()));
+ val.accept(Units.toPoints(POIXMLUnits.parseLength(ts.xgetPos())));
}
}
}
// check if the percentage value is scaled
final CTTextNormalAutofit normAutofit = getParentShape().getTextBodyPr().getNormAutofit();
if (normAutofit != null) {
- final double scale = 1 - (double)normAutofit.getLnSpcReduction() / 100000;
+ final double scale = 1 - POIXMLUnits.parsePercent(normAutofit.xgetLnSpcReduction()) / 100_000.;
return lnSpc * scale;
}
}
final CTTextSpacing spc = getSpc.apply(props).get();
if (spc != null) {
if (spc.isSetSpcPct()) {
- val.accept( spc.getSpcPct().getVal()*0.001 );
+ val.accept( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
} else if (spc.isSetSpcPts()) {
val.accept( -spc.getSpcPts().getVal()*0.01 );
}
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.common.usermodel.fonts.FontInfo;
import org.apache.poi.common.usermodel.fonts.FontPitch;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
import org.apache.poi.xslf.model.CharacterPropertyFetcher.CharPropFetcher;
import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties;
if (tbp != null) {
CTTextNormalAutofit afit = tbp.getNormAutofit();
if (afit != null && afit.isSetFontScale()) {
- scale = afit.getFontScale() / 100000.;
+ scale = POIXMLUnits.parsePercent(afit.xgetFontScale()) / 100000.;
}
}
}
public double getCharacterSpacing(){
Double d = fetchCharacterProperty((props, val) -> {
if (props.isSetSpc()) {
- val.accept(props.getSpc()*0.01);
+ val.accept(Units.toPoints(POIXMLUnits.parseLength(props.xgetSpc())));
}
});
return d == null ? 0 : d;
public boolean isSuperscript() {
Boolean b = fetchCharacterProperty((props, val) -> {
if (props.isSetBaseline()) {
- val.accept(props.getBaseline() > 0);
+ val.accept(POIXMLUnits.parsePercent(props.xgetBaseline()) > 0);
}
});
return b != null && b;
public boolean isSubscript() {
Boolean b = fetchCharacterProperty((props, val) -> {
if (props.isSetBaseline()) {
- val.accept(props.getBaseline() < 0);
+ val.accept(POIXMLUnits.parsePercent(props.xgetBaseline()) < 0);
}
});
return b != null && b;
@Override
public String getTypeface() {
CTTextFont tf = getXmlObject(false);
- return (tf != null && tf.isSetTypeface()) ? tf.getTypeface() : null;
+ return (tf != null) ? tf.getTypeface() : null;
}
@Override
return null;
}
- String typeface = font.isSetTypeface() ? font.getTypeface() : "";
+ String typeface = font.getTypeface();
+ if (typeface == null) {
+ typeface = "";
+ }
if (typeface.startsWith("+mj-") || typeface.startsWith("+mn-")) {
// "+mj-lt".equals(typeface) || "+mn-lt".equals(typeface)
final XSLFTheme theme = _p.getParentShape().getSheet().getTheme();
}
// SYMBOL is missing
- if (font == null || !font.isSetTypeface() || "".equals(font.getTypeface())) {
+ if (font == null || font.getTypeface() == null || "".equals(font.getTypeface())) {
// don't fallback to latin but bubble up in the style hierarchy (slide -> layout -> master -> theme)
return null;
// font = coll.getLatin();
import java.util.function.Predicate;
import org.apache.poi.ooxml.POIXMLException;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.sl.draw.DrawFactory;
import org.apache.poi.sl.draw.DrawTextShape;
import org.apache.poi.sl.usermodel.Insets2D;
}
};
fetchShapeProperty(fetcher);
- return fetcher.getValue() == null ? false : fetcher.getValue();
+ return fetcher.getValue() != null && fetcher.getValue();
}
@Override
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetBIns()) {
- double val = Units.toPoints(props.getBIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetBIns()));
setValue(val);
return true;
}
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetLIns()) {
- double val = Units.toPoints(props.getLIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetLIns()));
setValue(val);
return true;
}
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetRIns()) {
- double val = Units.toPoints(props.getRIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetRIns()));
setValue(val);
return true;
}
@Override
public boolean fetch(CTTextBodyProperties props) {
if (props.isSetTIns()) {
- double val = Units.toPoints(props.getTIns());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetTIns()));
setValue(val);
return true;
}
}
};
fetchShapeProperty(fetcher);
- return fetcher.getValue() == null ? true : fetcher.getValue();
+ return fetcher.getValue() == null || fetcher.getValue();
}
@Override
import java.util.List;
import java.util.function.Supplier;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRelativeRect;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTileInfoProperties;
+import org.openxmlformats.schemas.drawingml.x2006.main.STPercentage;
import org.openxmlformats.schemas.drawingml.x2006.main.STTileFlipMode;
@Internal
@Override
public int getAlpha() {
return (blip.sizeOfAlphaModFixArray() > 0)
- ? blip.getAlphaModFixArray(0).getAmt()
+ ? POIXMLUnits.parsePercent(blip.getAlphaModFixArray(0).xgetAmt())
: 100000;
}
public Dimension2D getScale() {
CTTileInfoProperties tile = blipFill.getTile();
return (tile == null) ? null : new Dimension2DDouble(
- tile.isSetSx() ? tile.getSx()/100_000. : 1,
- tile.isSetSy() ? tile.getSy()/100_000. : 1);
+ tile.isSetSx() ? POIXMLUnits.parsePercent(tile.xgetSx())/100_000. : 1,
+ tile.isSetSy() ? POIXMLUnits.parsePercent(tile.xgetSy())/100_000. : 1);
}
@Override
public Point2D getOffset() {
CTTileInfoProperties tile = blipFill.getTile();
return (tile == null) ? null : new Point2D.Double(
- tile.isSetTx() ? Units.toPoints(tile.getTx()) : 0,
- tile.isSetTy() ? Units.toPoints(tile.getTy()) : 0);
+ tile.isSetTx() ? Units.toPoints(POIXMLUnits.parseLength(tile.xgetTx())) : 0,
+ tile.isSetTy() ? Units.toPoints(POIXMLUnits.parseLength(tile.xgetTy())) : 0);
}
@Override
private static Insets2D getRectVal(CTRelativeRect rect) {
return rect == null ? null : new Insets2D(
- getRectVal(rect::isSetT, rect::getT),
- getRectVal(rect::isSetL, rect::getL),
- getRectVal(rect::isSetB, rect::getB),
- getRectVal(rect::isSetR, rect::getR)
+ getRectVal(rect::isSetT, rect::xgetT),
+ getRectVal(rect::isSetL, rect::xgetL),
+ getRectVal(rect::isSetB, rect::xgetB),
+ getRectVal(rect::isSetR, rect::xgetR)
);
}
- private static int getRectVal(Supplier<Boolean> isSet, Supplier<Integer> val) {
- return isSet.get() ? val.get() : 0;
+ private static int getRectVal(Supplier<Boolean> isSet, Supplier<STPercentage> val) {
+ return isSet.get() ? POIXMLUnits.parsePercent(val.get()) : 0;
}
}
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
+import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.ooxml.util.XPathHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.usermodel.XSSFTableColumn;
import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell;
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
for (XSSFSingleXmlCell singleXmlCell : singleXmlCells) {
- STXmlDataType.Enum xmlDataType = singleXmlCell.getXmlDataType();
+ String xmlDataType = singleXmlCell.getXmlDataType();
String xpathString = singleXmlCell.getXpath();
Node result = (Node) xpath.evaluate(xpathString, doc, XPathConstants.NODE);
// result can be null if value is optional (xsd:minOccurs=0), see bugzilla 55864
}
}
-
- private static enum DataType {
- BOOLEAN(STXmlDataType.BOOLEAN), //
- DOUBLE(STXmlDataType.DOUBLE), //
- INTEGER(STXmlDataType.INT, STXmlDataType.UNSIGNED_INT, STXmlDataType.INTEGER), //
- STRING(STXmlDataType.STRING), //
- DATE(STXmlDataType.DATE);
- private Set<STXmlDataType.Enum> xmlDataTypes;
+ private enum DataType {
+ BOOLEAN("boolean"), //
+ DOUBLE("double"), //
+ INTEGER("int", "unsignedInt", "integer"), //
+ STRING("string"), //
+ DATE("date");
+
+ private Set<String> xmlDataTypes;
- private DataType(STXmlDataType.Enum... xmlDataTypes) {
+ DataType(String... xmlDataTypes) {
this.xmlDataTypes = new HashSet<>(Arrays.asList(xmlDataTypes));
}
- public static DataType getDataType(STXmlDataType.Enum xmlDataType) {
+ public static DataType getDataType(String xmlDataType) {
for (DataType dataType : DataType.values()) {
if (dataType.xmlDataTypes.contains(xmlDataType)) {
return dataType;
}
}
- private void setCellValue(String value, XSSFCell cell, STXmlDataType.Enum xmlDataType) {
+ private void setCellValue(String value, XSSFCell cell, String xmlDataType) {
DataType type = DataType.getDataType(xmlDataType);
try {
if (value.isEmpty() || type == null) {
package org.apache.poi.xssf.usermodel;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
* <li>A position relative to a cell (top-left) and sized relative to another cell (bottom right)
* </ol>
*
- * which method is used is determined by the {@link AnchorType}.
+ * which method is used is determined by the {@link AnchorType}.
*/
public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
-
+
/**
* placeholder for zeros when needed for dynamic position calculations
*/
private static final CTMarker EMPTY_MARKER = CTMarker.Factory.newInstance();
-
+
private AnchorType anchorType;
/**
* if present, fixed size of the object to use instead of cell2, which is inferred instead
*/
private CTPositiveSize2D size;
-
+
/**
* if present, fixed top-left position to use instead of cell1, which is inferred instead
*/
private CTPoint2D position;
-
+
/**
* sheet to base dynamic calculations on, if needed. Required if size and/or position or set.
* Not needed if cell1/2 are set explicitly (dynamic sizing and position relative to cells).
*/
private XSSFSheet sheet;
-
+
/**
* Creates a new client anchor and defaults all the anchor positions to 0.
* Sets the type to {@link AnchorType#MOVE_AND_RESIZE} relative to cell range A1:A1.
this.cell1 = cell1;
// this.cell2 = calcCell(sheet, cell1, size.getCx(), size.getCy());
}
-
+
/**
* Create XSSFClientAnchor from existing xml beans, sized and positioned relative to a pair of cells.
* Sets the type to {@link AnchorType#DONT_MOVE_AND_RESIZE}.
// this.cell1 = calcCell(sheet, EMPTY_MARKER, position.getCx(), position.getCy());
// this.cell2 = calcCell(sheet, cell1, size.getCx(), size.getCy());
}
-
+
private CTMarker calcCell(CTMarker cell, long w, long h) {
CTMarker c2 = CTMarker.Factory.newInstance();
-
+
int r = cell.getRow();
int c = cell.getCol();
-
+
int cw = Units.columnWidthToEMU(sheet.getColumnWidth(c));
-
+
// start with width - offset, then keep adding column widths until the next one puts us over w
- long wPos = cw - cell.getColOff();
-
+ long wPos = cw - POIXMLUnits.parseLength(cell.xgetColOff());
+
while (wPos < w) {
c++;
cw = Units.columnWidthToEMU(sheet.getColumnWidth(c));
// now wPos >= w, so end column = c, now figure offset
c2.setCol(c);
c2.setColOff(cw - (wPos - w));
-
+
int rh = Units.toEMU(getRowHeight(sheet, r));
// start with height - offset, then keep adding row heights until the next one puts us over h
- long hPos = rh - cell.getRowOff();
-
+ long hPos = rh - POIXMLUnits.parseLength(cell.xgetRowOff());
+
while (hPos < h) {
r++;
rh = Units.toEMU(getRowHeight(sheet, r));
// now hPos >= h, so end row = r, now figure offset
c2.setRow(r);
c2.setRowOff(rh - (hPos - h));
-
+
return c2;
}
-
+
/**
* @param sheet
* @param row
XSSFRow r = sheet.getRow(row);
return r == null ? sheet.getDefaultRowHeightInPoints() : r.getHeightInPoints();
}
-
+
private CTMarker getCell1() {
- return cell1 != null ? cell1 : calcCell(EMPTY_MARKER, position.getX(), position.getY());
+ return cell1 != null ? cell1 : calcCell(EMPTY_MARKER, POIXMLUnits.parseLength(position.xgetX()), POIXMLUnits.parseLength(position.xgetY()));
}
-
+
private CTMarker getCell2() {
return cell2 != null ? cell2 : calcCell(getCell1(), size.getCx(), size.getCy());
}
-
+
public short getCol1() {
return (short)getCell1().getCol();
}
}
public int getDx1() {
- return Math.toIntExact(getCell1().getColOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetColOff()));
}
/**
}
public int getDy1() {
- return Math.toIntExact(getCell1().getRowOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell1().xgetRowOff()));
}
/**
}
public int getDy2() {
- return Math.toIntExact(getCell2().getRowOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetRowOff()));
}
/**
}
public int getDx2() {
- return Math.toIntExact(getCell2().getColOff());
+ return Math.toIntExact(POIXMLUnits.parseLength(getCell2().xgetColOff()));
}
/**
public CTPoint2D getPosition() {
return position;
}
-
+
/**
* Sets the top-left absolute position of the object. To use this, "from" must be set to null.
* @param position
public CTPositiveSize2D getSize() {
return size;
}
-
+
/**
* Sets the size of the object. To use this, "to" must be set to null.
* @param size
import org.apache.poi.util.Removal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
/**
* Represents a font used in a workbook.
* @see org.apache.poi.ss.usermodel.FontFamily
*/
public int getFamily() {
- CTIntProperty family = _ctFont.sizeOfFamilyArray() == 0 ? null : _ctFont.getFamilyArray(0);
+ CTFontFamily family = _ctFont.sizeOfFamilyArray() == 0 ? null : _ctFont.getFamilyArray(0);
return family == null ? FontFamily.NOT_APPLICABLE.getValue() : FontFamily.valueOf(family.getVal()).getValue();
}
* @see FontFamily
*/
public void setFamily(int value) {
- CTIntProperty family = _ctFont.sizeOfFamilyArray() == 0 ? _ctFont.addNewFamily() : _ctFont.getFamilyArray(0);
+ CTFontFamily family = _ctFont.sizeOfFamilyArray() == 0 ? _ctFont.addNewFamily() : _ctFont.getFamilyArray(0);
family.setVal(value);
}
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.FontFormatting;
import org.apache.poi.ss.usermodel.FontUnderline;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
/**
package org.apache.poi.xssf.usermodel;
-import java.util.*;
-import java.util.regex.Pattern;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.xml.namespace.QName;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.util.Internal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
-import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlCursor;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STXstring;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring;
/**
import javax.xml.namespace.QName;
import com.microsoft.schemas.office.excel.CTClientData;
-import com.microsoft.schemas.office.excel.STCF;
import com.microsoft.schemas.office.excel.STObjectType;
-import com.microsoft.schemas.office.excel.STTrueFalseBlank;
import com.microsoft.schemas.office.office.CTSignatureLine;
import com.microsoft.schemas.vml.CTImageData;
import com.microsoft.schemas.vml.CTShape;
import org.apache.poi.poifs.crypt.dsig.SignatureLine;
import org.apache.poi.schemas.vmldrawing.CTXML;
import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalseBlank;
public class XSSFSignatureLine extends SignatureLine {
private static final String MS_VML_URN = "urn:schemas-microsoft-com:vml";
clientData.addAnchor(anchorStr);
clientData.setObjectType(STObjectType.PICT);
clientData.addSizeWithCells(STTrueFalseBlank.X);
- clientData.addCF(STCF.PICT);
+ clientData.addCF("pict");
clientData.addAutoPict(STTrueFalseBlank.X);
}
package org.apache.poi.xssf.usermodel;
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
import org.apache.poi.xssf.model.ParagraphPropertyFetcher;
import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
/**
* Represents a paragraph of text within the containing text body.
* The paragraph is the highest level text separation mechanism.
}
};
fetchParagraphProperty(fetcher);
- return fetcher.getValue() == null ? TextAlign.LEFT : fetcher.getValue();
+ return fetcher.getValue() == null ? TextAlign.LEFT : fetcher.getValue();
}
/**
} else {
pr.setAlgn(STTextAlignType.Enum.forInt(align.ordinal() + 1));
}
- }
+ }
/**
* Returns where vertically on a line of text the actual words are positioned. This deals
* with vertical placement of the characters with respect to the baselines.
- *
+ *
* If this attribute is omitted, then a value of baseline is implied.
* @return alignment that is applied to the paragraph
*/
}
};
fetchParagraphProperty(fetcher);
- return fetcher.getValue() == null ? TextFontAlign.BASELINE : fetcher.getValue();
+ return fetcher.getValue() == null ? TextFontAlign.BASELINE : fetcher.getValue();
}
/**
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetBuSzPct()){
- setValue(props.getBuSzPct().getVal() * 0.001);
+ setValue(POIXMLUnits.parsePercent(props.getBuSzPct().xgetVal()) * 0.001);
return true;
}
if(props.isSetBuSzPts()){
if(bulletSize >= 0) {
// percentage
CTTextBulletSizePercent pt = pr.isSetBuSzPct() ? pr.getBuSzPct() : pr.addNewBuSzPct();
- pt.setVal((int)(bulletSize*1000));
+ pt.setVal(Integer.toString((int)(bulletSize*1000)));
// unset points if percentage is now set
if(pr.isSetBuSzPts()) pr.unsetBuSzPts();
} else {
/**
* Specifies the indent size that will be applied to the first line of text in the paragraph.
*
- * @param value the indent in points, -1 to unset indent and use the default of 0.
+ * @param value the indent in points, -1 to unset indent and use the default of 0.
*/
public void setIndent(double value){
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
};
fetchParagraphProperty(fetcher);
// if the marL attribute is omitted, then a value of 347663 is implied
- return fetcher.getValue() == null ? 0 : fetcher.getValue();
- }
+ return fetcher.getValue() == null ? 0 : fetcher.getValue();
+ }
/**
*
ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
public boolean fetch(CTTextParagraphProperties props){
if(props.isSetDefTabSz()){
- double val = Units.toPoints(props.getDefTabSz());
+ double val = Units.toPoints(POIXMLUnits.parseLength(props.xgetDefTabSz()));
setValue(val);
return true;
}
CTTextTabStopList tabStops = props.getTabLst();
if(idx < tabStops.sizeOfTabArray() ) {
CTTextTabStop ts = tabStops.getTabArray(idx);
- double val = Units.toPoints(ts.getPos());
+ double val = Units.toPoints(POIXMLUnits.parseLength(ts.xgetPos()));
setValue(val);
return true;
}
}
/**
* Add a single tab stop to be used on a line of text when there are one or more tab characters
- * present within the text.
- *
+ * present within the text.
+ *
* @param value the position of the tab stop relative to the left margin
*/
public void addTabStop(double value){
* // spacing will be 48 points
* paragraph.setLineSpacing(-48.0);
* </code></pre>
- *
+ *
* @param linespacing the vertical line spacing
*/
public void setLineSpacing(double linespacing){
if(props.isSetLnSpc()){
CTTextSpacing spc = props.getLnSpc();
- if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
+ if(spc.isSetSpcPct()) setValue( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
lnSpc *= scale;
}
}
-
+
return lnSpc;
}
if(props.isSetSpcBef()){
CTTextSpacing spc = props.getSpcBef();
- if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
+ if(spc.isSetSpcPct()) setValue( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
if(props.isSetSpcAft()){
CTTextSpacing spc = props.getSpcAft();
- if(spc.isSetSpcPct()) setValue( spc.getSpcPct().getVal()*0.001 );
+ if(spc.isSetSpcPct()) setValue( POIXMLUnits.parsePercent(spc.getSpcPct().xgetVal())*0.001 );
else if (spc.isSetSpcPts()) setValue( -spc.getSpcPts().getVal()*0.01 );
return true;
}
* that this paragraph belongs to (therefore in the parent shape).
* <p>
* Note that the closest properties object to the text is used, therefore if there is
- * a conflict between the text paragraph properties and the list style properties for
+ * a conflict between the text paragraph properties and the list style properties for
* this level then the text paragraph properties will take precedence.
* </p>
*
/**
* Returns the level of text properties that this paragraph will follow.
- *
+ *
* @return the text level of this paragraph (0-based). Default is 0.
*/
public int getLevel(){
return pr.getLvl();
}
-
+
/**
* Returns whether this paragraph has bullets
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? false : fetcher.getValue();
}
-
+
/**
* Set or unset this paragraph as a bullet point
- *
+ *
* @param flag whether text in this paragraph has bullets
*/
public void setBullet(boolean flag) {
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
if(!flag) {
pr.addNewBuNone();
-
+
if(pr.isSetBuAutoNum()) pr.unsetBuAutoNum();
if(pr.isSetBuBlip()) pr.unsetBuBlip();
if(pr.isSetBuChar()) pr.unsetBuChar();
public void setBullet(ListAutoNumber scheme, int startAt) {
if(startAt < 1) throw new IllegalArgumentException("Start Number must be greater or equal that 1") ;
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
- CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
+ CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
lst.setType(STTextAutonumberScheme.Enum.forInt(scheme.ordinal() + 1));
lst.setStartAt(startAt);
-
+
if(!pr.isSetBuFont()) pr.addNewBuFont().setTypeface("Arial");
- if(pr.isSetBuNone()) pr.unsetBuNone();
+ if(pr.isSetBuNone()) pr.unsetBuNone();
// remove these elements if present as it results in invalid content when opening in Excel.
if(pr.isSetBuBlip()) pr.unsetBuBlip();
- if(pr.isSetBuChar()) pr.unsetBuChar();
+ if(pr.isSetBuChar()) pr.unsetBuChar();
}
-
+
/**
* Set this paragraph as an automatic numbered bullet point
*
CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr();
CTTextAutonumberBullet lst = pr.isSetBuAutoNum() ? pr.getBuAutoNum() : pr.addNewBuAutoNum();
lst.setType(STTextAutonumberScheme.Enum.forInt(scheme.ordinal() + 1));
-
+
if(!pr.isSetBuFont()) pr.addNewBuFont().setTypeface("Arial");
if(pr.isSetBuNone()) pr.unsetBuNone();
// remove these elements if present as it results in invalid content when opening in Excel.
if(pr.isSetBuBlip()) pr.unsetBuBlip();
if(pr.isSetBuChar()) pr.unsetBuChar();
}
-
+
/**
* Returns whether this paragraph has automatic numbered bullets
*/
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? false : fetcher.getValue();
}
-
+
/**
* Returns the starting number if this paragraph has automatic numbered bullets, otherwise returns 0
*/
fetchParagraphProperty(fetcher);
return fetcher.getValue() == null ? 0 : fetcher.getValue();
}
-
+
/**
* Returns the auto number scheme if this paragraph has automatic numbered bullets, otherwise returns ListAutoNumber.ARABIC_PLAIN
*/
}
};
fetchParagraphProperty(fetcher);
-
+
// Note: documentation does not define a default, return ListAutoNumber.ARABIC_PLAIN (1,2,3...)
return fetcher.getValue() == null ? ListAutoNumber.ARABIC_PLAIN : fetcher.getValue();
- }
+ }
+
-
@SuppressWarnings("rawtypes")
private boolean fetchParagraphProperty(ParagraphPropertyFetcher visitor){
boolean ok = false;
return ok;
}
-
+
@Override
public String toString(){
return "[" + getClass() + "]" + getText();
==================================================================== */
package org.apache.poi.xssf.usermodel;
+import java.awt.Color;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
+import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextStrikeType;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
-import java.awt.Color;
-
/**
* Represents a run of text within the containing text body. The run element is the
* lowest level text separation mechanism within a text body.
CTSRgbColor clr = fill.getSrgbClr();
byte[] rgb = clr.getVal();
return new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2]);
- }
+ }
}
return new Color(0, 0, 0);
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetSz()){
- size = rPr.getSz()*0.01;
+ size = rPr.getSz()*0.01;
}
return size * scale;
public double getCharacterSpacing(){
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetSpc()){
- return rPr.getSpc()*0.01;
+ return Units.toPoints(POIXMLUnits.parseLength(rPr.xgetSpc()));
}
return 0;
}
public boolean isSuperscript() {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetBaseline()){
- return rPr.getBaseline() > 0;
+ return POIXMLUnits.parsePercent(rPr.xgetBaseline()) > 0;
}
return false;
}
public boolean isSubscript() {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetBaseline()){
- return rPr.getBaseline() < 0;
+ return POIXMLUnits.parsePercent(rPr.xgetBaseline()) < 0;
}
return false;
}
/**
* @return whether a run of text will be formatted as a superscript text. Default is false.
*/
- public TextCap getTextCap() {
+ public TextCap getTextCap() {
CTTextCharacterProperties rPr = getRPr();
if(rPr.isSetCap()){
return TextCap.values()[rPr.getCap().intValue() - 1];
import com.microsoft.schemas.vml.CTShapetype;
import com.microsoft.schemas.vml.STExt;
import com.microsoft.schemas.vml.STStrokeJoinStyle;
-import com.microsoft.schemas.vml.STTrueFalse;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.util.DocumentHelper;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSingleXmlCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlCellPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType.Enum;
/**
- *
+ *
* This class is a wrapper around the CTSingleXmlCell (Open Office XML Part 4:
- * chapter 3.5.2.1)
- *
+ * chapter 3.5.2.1)
+ *
- *
+ *
* @author Roberto Manicardi
*
*/
public class XSSFSingleXmlCell {
-
+
private CTSingleXmlCell singleXmlCell;
private SingleXmlCells parent;
-
-
+
+
public XSSFSingleXmlCell(CTSingleXmlCell singleXmlCell, SingleXmlCells parent){
this.singleXmlCell = singleXmlCell;
this.parent = parent;
}
-
+
/**
* Gets the XSSFCell referenced by the R attribute or creates a new one if cell doesn't exists
* @return the referenced XSSFCell, null if the cell reference is invalid
*/
public XSSFCell getReferencedCell(){
XSSFCell cell = null;
-
-
- CellReference cellReference = new CellReference(singleXmlCell.getR());
-
+
+
+ CellReference cellReference = new CellReference(singleXmlCell.getR());
+
XSSFRow row = parent.getXSSFSheet().getRow(cellReference.getRow());
if(row==null){
row = parent.getXSSFSheet().createRow(cellReference.getRow());
}
-
- cell = row.getCell(cellReference.getCol());
+
+ cell = row.getCell(cellReference.getCol());
if(cell==null){
cell = row.createCell(cellReference.getCol());
}
-
-
+
+
return cell;
}
-
+
public String getXpath(){
CTXmlCellPr xmlCellPr = singleXmlCell.getXmlCellPr();
CTXmlPr xmlPr = xmlCellPr.getXmlPr();
return xmlPr.getXpath();
}
-
+
public long getMapId(){
return singleXmlCell.getXmlCellPr().getXmlPr().getMapId();
}
- public Enum getXmlDataType() {
+ public String getXmlDataType() {
CTXmlCellPr xmlCellPr = singleXmlCell.getXmlCellPr();
CTXmlPr xmlPr = xmlCellPr.getXmlPr();
return xmlPr.getXmlDataType();
import org.apache.poi.xssf.usermodel.XSSFTable;
import org.apache.poi.xssf.usermodel.XSSFTableColumn;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXmlColumnPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType.Enum;
/**
- *
+ *
* This class is a wrapper around the CTXmlColumnPr (Open Office XML Part 4:
* chapter 3.5.1.7)
- *
+ *
*
* @author Roberto Manicardi
*/
/**
* If the XPath is, for example, /Node1/Node2/Node3 and /Node1/Node2 is the common XPath for the table, the local XPath is /Node3
- *
+ *
* @return the local XPath
*/
public String getLocalXPath() {
return localXPath.toString();
}
- public Enum getXmlDataType() {
+ public String getXmlDataType() {
return ctXmlColumnPr.getXmlDataType();
}
+++ /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.model;
-
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-
-public final class WMLHelper {
-
- public static boolean convertSTOnOffToBoolean (STOnOff.Enum value) {
- if (value == STOnOff.TRUE || value == STOnOff.ON || value == STOnOff.X_1) {
- return true;
- }
- return false;
- }
-
- public static STOnOff.Enum convertBooleanToSTOnOff (boolean value) {
- return (value ? STOnOff.TRUE : STOnOff.FALSE);
- }
-}
==================================================================== */
package org.apache.poi.xwpf.model;
+import com.microsoft.schemas.office.office.CTLock;
+import com.microsoft.schemas.office.office.STConnectType;
+import com.microsoft.schemas.vml.CTFormulas;
+import com.microsoft.schemas.vml.CTGroup;
+import com.microsoft.schemas.vml.CTH;
+import com.microsoft.schemas.vml.CTHandles;
+import com.microsoft.schemas.vml.CTPath;
+import com.microsoft.schemas.vml.CTShape;
+import com.microsoft.schemas.vml.CTShapetype;
+import com.microsoft.schemas.vml.CTTextPath;
+import com.microsoft.schemas.vml.STExt;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRelation;
import org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtrRef;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr.Enum;
-import com.microsoft.schemas.office.office.CTLock;
-import com.microsoft.schemas.office.office.STConnectType;
-import com.microsoft.schemas.vml.CTFormulas;
-import com.microsoft.schemas.vml.CTGroup;
-import com.microsoft.schemas.vml.CTH;
-import com.microsoft.schemas.vml.CTHandles;
-import com.microsoft.schemas.vml.CTPath;
-import com.microsoft.schemas.vml.CTShape;
-import com.microsoft.schemas.vml.CTShapetype;
-import com.microsoft.schemas.vml.CTTextPath;
-import com.microsoft.schemas.vml.STExt;
-import com.microsoft.schemas.vml.STTrueFalse;
-
/**
* A .docx file can have no headers/footers, the same header/footer
* on each page, odd/even page footers, and optionally also
ref.setType(type);
ref.setId(doc.getRelationId(wrapper));
}
-
+
public XWPFHeader getFirstPageHeader() {
return firstPageHeader;
}
}
return defaultHeader;
}
-
+
/**
* Get this section header for the given type
*
}
return defaultFooter;
}
-
+
/**
* Get this section footer for the given type
*
}
return defaultFooter;
}
-
+
public void createWatermark(String text) {
XWPFParagraph[] pars = new XWPFParagraph[1];
import java.util.HashMap;
import java.util.Map;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+
/**
* Specifies all types of alignment which are available to be applied to objects in a
* WordprocessingML document
public enum ParagraphAlignment {
//YK: TODO document each alignment option
- LEFT(1),
- CENTER(2),
- RIGHT(3),
- BOTH(4),
- MEDIUM_KASHIDA(5),
- DISTRIBUTE(6),
- NUM_TAB(7),
- HIGH_KASHIDA(8),
- LOW_KASHIDA(9),
- THAI_DISTRIBUTE(10);
+ START(STJc.INT_START), // 1
+ CENTER(STJc.INT_CENTER), // 2
+ END(STJc.INT_END), // 3
+ BOTH(STJc.INT_BOTH), // 4
+ MEDIUM_KASHIDA(STJc.INT_MEDIUM_KASHIDA), // 5
+ DISTRIBUTE(STJc.INT_DISTRIBUTE), // 6
+ NUM_TAB(STJc.INT_NUM_TAB), // 7
+ HIGH_KASHIDA(STJc.INT_HIGH_KASHIDA), // 8
+ LOW_KASHIDA(STJc.INT_LOW_KASHIDA), // 9
+ THAI_DISTRIBUTE(STJc.INT_THAI_DISTRIBUTE), // 10
+ LEFT(STJc.INT_LEFT), // 11
+ RIGHT(STJc.INT_RIGHT) // 12
+ ;
- private static Map<Integer, ParagraphAlignment> imap = new HashMap<>();
+ private static final Map<Integer, ParagraphAlignment> imap = new HashMap<>();
static {
for (ParagraphAlignment p : values()) {
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
import org.apache.xmlbeans.impl.xb.xmlschema.SpaceAttribute.Space;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTabs;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFldCharType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTabJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTabTlc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTheme;
fonts.setEastAsiaTheme(STTheme.MINOR_H_ANSI);
fonts.setHAnsiTheme(STTheme.MINOR_H_ANSI);
fonts.setCstheme(STTheme.MINOR_BIDI);
- rPr.addNewB().setVal(STOnOff.OFF);
- rPr.addNewBCs().setVal(STOnOff.OFF);
+ rPr.addNewB().setVal(STOnOff1.OFF);
+ rPr.addNewBCs().setVal(STOnOff1.OFF);
rPr.addNewColor().setVal("auto");
rPr.addNewSz().setVal(BigInteger.valueOf(24));
rPr.addNewSzCs().setVal(BigInteger.valueOf(24));
package org.apache.poi.xwpf.usermodel;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
+import org.apache.poi.ooxml.util.POIXMLUnits;
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrGeneral;
/**
* Default Paragraph style, from which other styles will override
* TODO Share logic with {@link XWPFParagraph} which also uses CTPPr
*/
public class XWPFDefaultParagraphStyle {
- private CTPPr ppr;
+ private final CTPPrGeneral ppr;
- public XWPFDefaultParagraphStyle(CTPPr ppr) {
+ public XWPFDefaultParagraphStyle(CTPPrGeneral ppr) {
this.ppr = ppr;
}
- protected CTPPr getPPr() {
+ protected CTPPrGeneral getPPr() {
return ppr;
}
public int getSpacingAfter() {
- if (ppr.isSetSpacing())
- return ppr.getSpacing().getAfter().intValue();
- return -1;
+ return ppr.isSetSpacing() ? (int) Units.toDXA(POIXMLUnits.parseLength(ppr.getSpacing().xgetAfter())) : -1;
}
}
package org.apache.poi.xwpf.usermodel;
-import org.apache.poi.util.Removal;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-
import java.math.BigDecimal;
import java.math.RoundingMode;
+import org.apache.poi.ooxml.util.POIXMLUnits;
+import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+
/**
* Default Character Run style, from which other styles will override
* TODO Share logic with {@link XWPFRun} which also uses CTRPr
}
private BigDecimal getFontSizeAsBigDecimal(int scale) {
- return (rpr != null && rpr.isSetSz()) ?
- new BigDecimal(rpr.getSz().getVal()).divide(BigDecimal.valueOf(2)).setScale(scale, RoundingMode.HALF_UP) :
- null;
+ return (rpr != null && rpr.isSetSz())
+ ? BigDecimal.valueOf(Units.toPoints(POIXMLUnits.parseLength(rpr.getSz().xgetVal()))).divide(BigDecimal.valueOf(4), scale, RoundingMode.HALF_UP)
+ : null;
}
}
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.EndnotesDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHdrFtr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/**
* <p>High(ish) level class for working with .docx files.</p>
CTSectPr ctSectPr = getSection();
if (!ctSectPr.isSetTitlePg()) {
CTOnOff titlePg = ctSectPr.addNewTitlePg();
- titlePg.setVal(STOnOff.ON);
+ titlePg.setVal(STOnOff1.ON);
}
// } else if (type == HeaderFooterType.EVEN) {
// TODO Add support for Even/Odd headings and footers
CTSectPr ctSectPr = getSection();
if (!ctSectPr.isSetTitlePg()) {
CTOnOff titlePg = ctSectPr.addNewTitlePg();
- titlePg.setVal(STOnOff.ON);
+ titlePg.setVal(STOnOff1.ON);
}
// } else if (type == HeaderFooterType.EVEN) {
// TODO Add support for Even/Odd headings and footers
import java.util.function.Function;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.apache.poi.wp.usermodel.Paragraph;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/**
*/
public boolean isKeepNext() {
if (getCTP() != null && getCTP().getPPr() != null && getCTP().getPPr().isSetKeepNext()) {
- return getCTP().getPPr().getKeepNext().getVal() == STOnOff.ON;
+ return POIXMLUnits.parseOnOff(getCTP().getPPr().getKeepNext().xgetVal());
}
return false;
}
*/
public void setKeepNext(boolean keepNext) {
CTOnOff state = CTOnOff.Factory.newInstance();
- state.setVal(keepNext ? STOnOff.ON : STOnOff.OFF);
+ state.setVal(keepNext ? STOnOff1.ON : STOnOff1.OFF);
getCTP().getPPr().setKeepNext(state);
}
if (ctPageBreak == null) {
return false;
}
- return isTruelike(ctPageBreak.getVal());
- }
-
- private static boolean isTruelike(final STOnOff.Enum value) {
- if (value == null) {
- return false;
- }
- switch (value.intValue()) {
- case STOnOff.INT_TRUE:
- case STOnOff.INT_X_1:
- case STOnOff.INT_ON:
- return true;
- /*STOnOff.INT_FALSE:
- STOnOff.INT_X_0:
- STOnOff.INT_OFF:*/
- default:
- return false;
- }
+ return POIXMLUnits.parseOnOff(ctPageBreak.xgetVal());
}
/**
CTPPr ppr = getCTPPr();
CTOnOff ctPageBreak = ppr.isSetPageBreakBefore() ? ppr
.getPageBreakBefore() : ppr.addNewPageBreakBefore();
- if (pageBreak) {
- ctPageBreak.setVal(STOnOff.TRUE);
- } else {
- ctPageBreak.setVal(STOnOff.FALSE);
- }
+ ctPageBreak.setVal(pageBreak ? STOnOff1.ON : STOnOff1.OFF);
}
/**
*/
public int getSpacingAfter() {
CTSpacing spacing = getCTSpacing(false);
- return (spacing != null && spacing.isSetAfter()) ? spacing.getAfter().intValue() : -1;
+ return (spacing != null && spacing.isSetAfter()) ? (int)Units.toDXA(POIXMLUnits.parseLength(spacing.xgetAfter())) : -1;
}
/**
*/
public int getSpacingBefore() {
CTSpacing spacing = getCTSpacing(false);
- return (spacing != null && spacing.isSetBefore()) ? spacing.getBefore().intValue() : -1;
+ return (spacing != null && spacing.isSetBefore()) ? (int)Units.toDXA(POIXMLUnits.parseLength(spacing.xgetBefore())) : -1;
}
/**
CTSpacing spacing = getCTSpacing(false);
if (spacing == null || !spacing.isSetLine()) {
return -1;
- } else if (spacing.getLineRule() == null || spacing.getLineRule() == STLineSpacingRule.AUTO) {
- BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(240L));
- return val[0].doubleValue() + (val[1].doubleValue() / 240L);
}
- BigInteger[] val = spacing.getLine().divideAndRemainder(BigInteger.valueOf(20L));
- return val[0].doubleValue() + (val[1].doubleValue() / 20L);
+
+ double twips = Units.toDXA(POIXMLUnits.parseLength(spacing.xgetLine()));
+
+ return twips / ((spacing.getLineRule() == null || spacing.getLineRule() == STLineSpacingRule.AUTO) ? 240 : 20);
}
/**
*/
public int getIndentationLeft() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetLeft()) ? indentation.getLeft().intValue()
- : -1;
+ return (indentation != null && indentation.isSetLeft())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetLeft()))
+ : -1;
}
/**
public int getIndentationRight() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetRight()) ? indentation.getRight().intValue()
- : -1;
+ return (indentation != null && indentation.isSetRight())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetRight()))
+ : -1;
}
/**
*/
public int getIndentationHanging() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetHanging()) ? indentation.getHanging().intValue() : -1;
+ return (indentation != null && indentation.isSetHanging())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetHanging())) : -1;
}
/**
*/
public int getIndentationFirstLine() {
CTInd indentation = getCTInd(false);
- return (indentation != null && indentation.isSetFirstLine()) ? indentation.getFirstLine().intValue()
- : -1;
+ return (indentation != null && indentation.isSetFirstLine())
+ ? (int)Units.toDXA(POIXMLUnits.parseLength(indentation.xgetFirstLine()))
+ : -1;
}
/**
*/
@Override
public boolean isWordWrapped() {
- CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
- .getWordWrap() : null;
- if (wordWrap != null) {
- return isTruelike(wordWrap.getVal());
- }
- return false;
+ return getCTPPr().isSetWordWrap() && POIXMLUnits.parseOnOff(getCTPPr().getWordWrap());
}
/**
*/
@Override
public void setWordWrapped(boolean wrap) {
- CTOnOff wordWrap = getCTPPr().isSetWordWrap() ? getCTPPr()
- .getWordWrap() : getCTPPr().addNewWordWrap();
+ CTPPr ppr = getCTPPr();
if (wrap) {
- wordWrap.setVal(STOnOff.TRUE);
+ CTOnOff wordWrap = ppr.isSetWordWrap() ? ppr.getWordWrap() : ppr.addNewWordWrap();
+ wordWrap.setVal(STOnOff1.ON);
} else {
- wordWrap.unsetVal();
+ if (ppr.isSetWordWrap()) {
+ ppr.unsetWordWrap();
+ }
}
}
import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ooxml.util.DocumentHelper;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
+import org.apache.poi.util.Units;
import org.apache.poi.wp.usermodel.CharacterRun;
import org.apache.xmlbeans.SimpleValue;
import org.apache.xmlbeans.XmlCursor;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STHexColorRGB;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
* For isBold, isItalic etc
*/
private static boolean isCTOnOff(CTOnOff onoff) {
- if (!onoff.isSetVal()) {
- return true;
- }
- final STOnOff.Enum val = onoff.getVal();
- return (
- (STOnOff.TRUE == val) ||
- (STOnOff.X_1 == val) ||
- (STOnOff.ON == val)
- );
+ return !onoff.isSetVal() || POIXMLUnits.parseOnOff(onoff);
}
/**
public void setBold(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff bold = pr.isSetB() ? pr.getB() : pr.addNewB();
- bold.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ bold.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
public void setItalic(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff italic = pr.isSetI() ? pr.getI() : pr.addNewI();
- italic.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ italic.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
public void setStrikeThrough(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff strike = pr.isSetStrike() ? pr.getStrike() : pr.addNewStrike();
- strike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ strike.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Deprecated
public void setDoubleStrikethrough(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff dstrike = pr.isSetDstrike() ? pr.getDstrike() : pr.addNewDstrike();
- dstrike.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ dstrike.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
public void setSmallCaps(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff caps = pr.isSetSmallCaps() ? pr.getSmallCaps() : pr.addNewSmallCaps();
- caps.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ caps.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
public void setCapitalized(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff caps = pr.isSetCaps() ? pr.getCaps() : pr.addNewCaps();
- caps.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ caps.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
public void setShadow(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff shadow = pr.isSetShadow() ? pr.getShadow() : pr.addNewShadow();
- shadow.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ shadow.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
public void setImprinted(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff imprinted = pr.isSetImprint() ? pr.getImprint() : pr.addNewImprint();
- imprinted.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ imprinted.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
@Override
public void setEmbossed(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff emboss = pr.isSetEmboss() ? pr.getEmboss() : pr.addNewEmboss();
- emboss.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ emboss.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
if (pr == null || !pr.isSetKern()) {
return 0;
}
- return pr.getKern().getVal().intValue();
+ return (int)POIXMLUnits.parseLength(pr.getKern().xgetVal());
}
@Override
if (pr == null || !pr.isSetSpacing()) {
return 0;
}
- return pr.getSpacing().getVal().intValue();
+ return (int)Units.toDXA(POIXMLUnits.parseLength(pr.getSpacing().xgetVal()));
}
@Override
private BigDecimal getFontSizeAsBigDecimal(int scale) {
CTRPr pr = getRunProperties(false);
- return (pr != null && pr.isSetSz()) ?
- new BigDecimal(pr.getSz().getVal()).divide(BigDecimal.valueOf(2)).setScale(scale, RoundingMode.HALF_UP) :
- null;
+ return (pr != null && pr.isSetSz())
+ ? BigDecimal.valueOf(Units.toPoints(POIXMLUnits.parseLength(pr.getSz().xgetVal()))).divide(BigDecimal.valueOf(4), scale, RoundingMode.HALF_UP)
+ : null;
}
/**
*/
public int getTextPosition() {
CTRPr pr = getRunProperties(false);
- return (pr != null && pr.isSetPosition()) ? pr.getPosition().getVal().intValue()
+ return (pr != null && pr.isSetPosition()) ? (int)(Units.toPoints(POIXMLUnits.parseLength(pr.getPosition().xgetVal())) / 2.)
: -1;
}
if (ctfldChar.getFldCharType() == STFldCharType.BEGIN) {
if (ctfldChar.getFfData() != null) {
for (CTFFCheckBox checkBox : ctfldChar.getFfData().getCheckBoxList()) {
- if (checkBox.getDefault() != null && checkBox.getDefault().getVal() == STOnOff.X_1) {
- text.append("|X|");
- } else {
- text.append("|_|");
- }
+ text.append((checkBox.getDefault() != null && POIXMLUnits.parseOnOff(checkBox.getDefault().xgetVal())) ? "|X|" : "|_|");
}
}
}
* @since 4.0.0
*/
public int getTextScale() {
- CTRPr pr = getRunProperties(true);
- CTTextScale scale = pr.isSetW() ? pr.getW() : pr.addNewW();
- int value = scale.getVal();
- if (value == 0) {
- value = 100; // 100% scaling, that is, no change. See 17.3.2.43 w (Expanded/Compressed Text)
+ CTRPr pr = getRunProperties(false);
+ if (pr == null || !pr.isSetW()) {
+ return 100;
}
- return value;
+
+ int value = POIXMLUnits.parsePercent(pr.getW().xgetVal());
+ // 100% scaling, that is, no change. See 17.3.2.43 w (Expanded/Compressed Text)
+ return value == 0 ? 100 : value / 1000;
}
/**
public void setVanish(boolean value) {
CTRPr pr = getRunProperties(true);
CTOnOff vanish = pr.isSetVanish() ? pr.getVanish() : pr.addNewVanish();
- vanish.setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+ vanish.setVal(value ? STOnOff1.ON : STOnOff1.OFF);
}
/**
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STAlgClass;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STAlgType;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STCryptProv;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSettings;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTZoom;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STAlgClass;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STAlgType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STCryptProv;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.SettingsDocument;
public class XWPFSettings extends POIXMLDocumentPart {
public XWPFSettings(PackagePart part) throws IOException {
super(part);
}
-
+
public XWPFSettings() {
super();
ctSettings = CTSettings.Factory.newInstance();
zoom = ctSettings.getZoom();
}
-
- BigInteger percent = zoom.getPercent();
- if(percent == null) {
- return 100;
- }
- return percent.longValue();
+
+ return (zoom.getPercent() == null) ? 100 : POIXMLUnits.parsePercent(zoom.xgetPercent()) / 1000;
}
/**
CTZoom zoom = ctSettings.getZoom();
zoom.setPercent(BigInteger.valueOf(zoomPercent));
}
-
+
/**
* Verifies the documentProtection tag inside settings.xml file <br>
* if the protection is enforced (w:enforcement="1") <br>
*/
public boolean isEnforcedWith() {
CTDocProtect ctDocProtect = ctSettings.getDocumentProtection();
+ return ctDocProtect != null && POIXMLUnits.parseOnOff(ctDocProtect.xgetEnforcement());
- if (ctDocProtect == null) {
- return false;
- }
-
- return ctDocProtect.getEnforcement().equals(STOnOff.X_1);
}
/**
*/
public boolean isEnforcedWith(STDocProtect.Enum editValue) {
CTDocProtect ctDocProtect = ctSettings.getDocumentProtection();
+ return ctDocProtect != null && POIXMLUnits.parseOnOff(ctDocProtect.xgetEnforcement()) && ctDocProtect.getEdit().equals(editValue);
- if (ctDocProtect == null) {
- return false;
- }
-
- return ctDocProtect.getEnforcement().equals(STOnOff.X_1) && ctDocProtect.getEdit().equals(editValue);
}
/**
* </pre>
*/
public void setEnforcementEditValue(org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect.Enum editValue) {
- safeGetDocumentProtection().setEnforcement(STOnOff.X_1);
+ safeGetDocumentProtection().setEnforcement(STOnOff1.ON);
safeGetDocumentProtection().setEdit(editValue);
}
*/
public void setEnforcementEditValue(org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect.Enum editValue,
String password, HashAlgorithm hashAlgo) {
- safeGetDocumentProtection().setEnforcement(STOnOff.X_1);
+ safeGetDocumentProtection().setEnforcement(STOnOff1.ON);
safeGetDocumentProtection().setEdit(editValue);
if (password == null) {
if (hashAlgo == null) {
hashAlgo = HashAlgorithm.sha1;
}
-
+
switch (hashAlgo) {
case md2:
providerType = STCryptProv.RSA_FULL;
/**
* Validates the existing password
*
- * @param password
+ * @param password the password
* @return true, only if password was set and equals, false otherwise
*/
public boolean validateProtectionPassword(String password) {
* it sets the value of enforcement to "0" (w:enforcement="0") <br>
*/
public void removeEnforcement() {
- safeGetDocumentProtection().setEnforcement(STOnOff.X_0);
+ safeGetDocumentProtection().setEnforcement(STOnOff1.OFF);
}
/**
*/
public void setUpdateFields() {
CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(STOnOff.TRUE);
+ onOff.setVal(STOnOff1.ON);
ctSettings.setUpdateFields(onOff);
}
boolean isUpdateFields() {
- return ctSettings.isSetUpdateFields() && ctSettings.getUpdateFields().getVal() == STOnOff.TRUE;
+ return ctSettings.isSetUpdateFields() && POIXMLUnits.parseOnOff(ctSettings.getUpdateFields().xgetVal());
}
/**
/**
* Turn separate even-and-odd headings on or off
*
- * @param enable <code>true</code> to turn on separate even and odd headings,
+ * @param enable <code>true</code> to turn on separate even and odd headings,
* <code>false</code> to turn off even and odd headings.
*/
public void setEvenAndOddHeadings(boolean enable) {
CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(enable ? STOnOff.TRUE : STOnOff.FALSE);
+ onOff.setVal(enable ? STOnOff1.ON : STOnOff1.OFF);
ctSettings.setEvenAndOddHeaders(onOff);
}
/**
* Turn mirrored margins on or off
*
- * @param enable <code>true</code> to turn on mirrored margins,
+ * @param enable <code>true</code> to turn on mirrored margins,
* <code>false</code> to turn off mirrored marginss.
*/
public void setMirrorMargins(boolean enable) {
CTOnOff onOff = CTOnOff.Factory.newInstance();
- onOff.setVal(enable ? STOnOff.TRUE : STOnOff.FALSE);
+ onOff.setVal(enable ? STOnOff1.ON : STOnOff1.OFF);
ctSettings.setMirrorMargins(onOff);
}
import java.util.function.Function;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
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.CTJcTable;
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.STJcTable;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
/**
*/
public int getWidth() {
CTTblPr tblPr = getTblPr();
- return tblPr.isSetTblW() ? tblPr.getTblW().getW().intValue() : -1;
+ return tblPr.isSetTblW() ? (int)Units.toDXA(POIXMLUnits.parseLength(tblPr.getTblW().xgetW())) : -1;
}
/**
*/
public void setTableAlignment(TableRowAlign tra) {
CTTblPr tPr = getTblPr(true);
- CTJc jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
- jc.setVal(STJc.Enum.forInt(tra.getValue()));
+ CTJcTable jc = tPr.isSetJc() ? tPr.getJc() : tPr.addNewJc();
+ jc.setVal(STJcTable.Enum.forInt(tra.getValue()));
}
/**
if (tcm != null) {
CTTblWidth tw = margin.apply(tcm);
if (tw != null) {
- return tw.getW().intValue();
+ return (int) Units.toDXA(POIXMLUnits.parseLength(tw.xgetW()));
}
}
return 0;
if (typeValue == STTblWidth.DXA
|| typeValue == STTblWidth.AUTO
|| typeValue == STTblWidth.NIL) {
- result = 0.0 + ctWidth.getW().intValue();
+ result = 0.0 + Units.toDXA(POIXMLUnits.parseLength(ctWidth.xgetW()));
} else if (typeValue == STTblWidth.PCT) {
// Percentage values are stored as integers that are 50 times
// percentage.
- result = ctWidth.getW().intValue() / 50.0;
+ result = Units.toDXA(POIXMLUnits.parseLength(ctWidth.xgetW())) / 50.0;
} else {
// Should never get here
}
import java.util.List;
import org.apache.poi.ooxml.POIXMLDocumentPart;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
* @return Width value as a double-precision decimal.
* @since 4.0.0
*/
- public double getWidthDecimal() {
- return XWPFTable.getWidthDecimal(getTcWidth());
+ public double getWidthDecimal() {
+ return XWPFTable.getWidthDecimal(getTcWidth());
}
/**
* @since 4.0.0
*/
public TableWidthType getWidthType() {
- return XWPFTable.getWidthType(getTcWidth());
+ return XWPFTable.getWidthType(getTcWidth());
}
/**
* @since 4.0.0
*/
public void setWidth(String widthValue) {
- XWPFTable.setWidthValue(widthValue, getTcWidth());
+ XWPFTable.setWidthValue(widthValue, getTcWidth());
}
private CTTblWidth getTcWidth() {
}
public int getWidth() {
- return getTcWidth().getW().intValue();
+ return (int) Units.toDXA(POIXMLUnits.parseLength(getTcWidth().xgetW()));
}
}
import java.util.ArrayList;
import java.util.List;
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.util.Internal;
-import org.apache.poi.xwpf.model.WMLHelper;
+import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHeight;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
*/
public int getHeight() {
CTTrPr properties = getTrPr();
- return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
+ return properties.sizeOfTrHeightArray() == 0 ? 0 : (int) Units.toDXA(POIXMLUnits.parseLength(properties.getTrHeightArray(0).xgetVal()));
}
/**
CTTrPr trpr = getTrPr();
if (trpr.sizeOfCantSplitArray() > 0) {
CTOnOff onoff = trpr.getCantSplitArray(0);
- isCant = (onoff.isSetVal() ? WMLHelper.convertSTOnOffToBoolean(onoff.getVal()) : true);
+ isCant = !onoff.isSetVal() || POIXMLUnits.parseOnOff(onoff.xgetVal());
}
}
return isCant;
public void setCantSplitRow(boolean split) {
CTTrPr trpr = getTrPr();
CTOnOff onoff = (trpr.sizeOfCantSplitArray() > 0 ? trpr.getCantSplitArray(0) : trpr.addNewCantSplit());
- onoff.setVal(WMLHelper.convertBooleanToSTOnOff(split));
+ onoff.setVal(split ? STOnOff1.ON : STOnOff1.OFF);
}
/**
* table split across pages. NOTE - Word will not repeat a table row unless
* all preceding rows of the table are also repeated. This function returns
* false if the row will not be repeated even if the repeat tag is present
- * for this row.
+ * for this row.
*
* @return true if table's header row should be repeated at the top of each
* page of table, false otherwise.
}
return repeat;
}
-
+
private boolean getRepeat() {
boolean repeat = false;
if (ctRow.isSetTrPr()) {
CTTrPr trpr = getTrPr();
if (trpr.sizeOfTblHeaderArray() > 0) {
CTOnOff rpt = trpr.getTblHeaderArray(0);
- repeat = (rpt.isSetVal() ? WMLHelper.convertSTOnOffToBoolean(rpt.getVal()) : true);
+ repeat = !rpt.isSetVal() || POIXMLUnits.parseOnOff(rpt.xgetVal());
}
}
return repeat;
public void setRepeatHeader(boolean repeat) {
CTTrPr trpr = getTrPr();
CTOnOff onoff = (trpr.sizeOfTblHeaderArray() > 0 ? trpr.getTblHeaderArray(0) : trpr.addNewTblHeader());
- onoff.setVal(WMLHelper.convertBooleanToSTOnOff(repeat));
+ onoff.setVal(repeat ? STOnOff1.ON : STOnOff1.OFF);
}
}
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.ooxml.util.POIXMLUnits;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-
public final class TestContentTypeManager {
/**
anchor = (XSSFClientAnchor) helper.createClientAnchor();
CTMarker markerFrom = oldAnchor.getFrom();
CTMarker markerTo = oldAnchor.getTo();
- anchor.setDx1((int) markerFrom.getColOff());
- anchor.setDx2((int) markerTo.getColOff());
- anchor.setDy1((int) markerFrom.getRowOff());
- anchor.setDy2((int) markerTo.getRowOff());
+ anchor.setDx1((int) POIXMLUnits.parseLength(markerFrom.xgetColOff()));
+ anchor.setDx2((int) POIXMLUnits.parseLength(markerTo.xgetColOff()));
+ anchor.setDy1((int) POIXMLUnits.parseLength(markerFrom.xgetRowOff()));
+ anchor.setDy2((int) POIXMLUnits.parseLength(markerTo.xgetRowOff()));
anchor.setCol1(markerFrom.getCol());
anchor.setCol2(markerTo.getCol());
anchor.setRow1(markerFrom.getRow());
built = (XDDFColorRgbPercent) XDDFColor.from(654321, 654321, 654321);
assertEquals(expected, built.getXmlObject().toString());
assertEquals("FFFFFF", built.toRGBHex());
+
+ built = (XDDFColorRgbPercent) XDDFColor.from(75000, 50000, 25000);
+ assertEquals("BF7F3F", built.toRGBHex());
}
}
package org.apache.poi.xssf.usermodel;
+import static org.junit.Assert.*;
+
import java.io.IOException;
import org.apache.poi.common.usermodel.fonts.FontCharset;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontFamily;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
-
-import static org.junit.Assert.*;
public final class TestXSSFFont extends BaseTestFont{
@Test
public void testFamily() {
CTFont ctFont=CTFont.Factory.newInstance();
- CTIntProperty family=ctFont.addNewFamily();
+ CTFontFamily family=ctFont.addNewFamily();
family.setVal(FontFamily.MODERN.getValue());
ctFont.setFamilyArray(0,family);
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.StylesTable;
import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STXstring;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXstring;
/**
* Tests functionality of the XSSFRichTextRun object
import com.microsoft.schemas.office.excel.CTClientData;
import com.microsoft.schemas.office.excel.STObjectType;
-import com.microsoft.schemas.office.excel.STTrueFalseBlank;
import com.microsoft.schemas.office.office.CTShapeLayout;
import com.microsoft.schemas.office.office.STConnectType;
import com.microsoft.schemas.office.office.STInsetMode;
import com.microsoft.schemas.vml.CTShape;
import com.microsoft.schemas.vml.CTShapetype;
import com.microsoft.schemas.vml.STExt;
-import com.microsoft.schemas.vml.STTrueFalse;
import org.apache.poi.POIDataSamples;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.junit.Test;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalse;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STTrueFalseBlank;
public class TestXSSFVMLDrawing {
--- /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.xssf.usermodel.charts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.ss.util.SheetBuilder;
+import org.apache.poi.xddf.usermodel.chart.AxisPosition;
+import org.apache.poi.xddf.usermodel.chart.ChartTypes;
+import org.apache.poi.xddf.usermodel.chart.XDDFArea3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFBar3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFCategoryAxis;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFDataSourcesFactory;
+import org.apache.poi.xddf.usermodel.chart.XDDFLine3DChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
+import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
+
+/**
+ * Tests for XSSF Area3d Charts
+ */
+public class TestXSSF3DChartData {
+
+ private static final Object[][] plotData = {
+ {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"},
+ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+ };
+
+ @Test
+ public void testArea3D() throws IOException {
+ // This test currently doesn't produce a valid area 3d chart and is only used to test accessors
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ XSSFSheet sheet = (XSSFSheet) new SheetBuilder(wb, plotData).build();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+
+ Map<ChartTypes, Consumer<XDDFChartData>> map = new HashMap<>();
+ map.put(ChartTypes.AREA3D, this::handleArea3D);
+ map.put(ChartTypes.BAR3D, this::handleBar3D);
+ map.put(ChartTypes.LINE3D, this::handleLine3D);
+
+ for (Map.Entry<ChartTypes, Consumer<XDDFChartData>> me : map.entrySet()) {
+
+ XSSFChart chart = drawing.createChart(anchor);
+
+ XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
+
+ XDDFDataSource<String> xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, CellRangeAddress.valueOf("A1:J1"));
+ XDDFNumericalDataSource<Double> ys = XDDFDataSourcesFactory.fromNumericCellRange(sheet, CellRangeAddress.valueOf("A2:J2"));
+
+ XDDFChartData data = chart.createData(me.getKey(), bottomAxis, leftAxis);
+ XDDFChartData.Series series = data.addSeries(xs, ys);
+
+ assertNotNull(series);
+ assertEquals(1, data.getSeriesCount());
+ assertEquals(series, data.getSeries(0));
+ chart.plot(data);
+
+ me.getValue().accept(data);
+ }
+ }
+ }
+
+ private void handleArea3D(XDDFChartData data) {
+ XDDFArea3DChartData xArea3d = (XDDFArea3DChartData)data;
+ xArea3d.setGapDepth(10);
+ assertEquals(10, (int)xArea3d.getGapDepth());
+ }
+
+ private void handleBar3D(XDDFChartData data) {
+ XDDFBar3DChartData xBar3d = (XDDFBar3DChartData) data;
+ xBar3d.setGapDepth(10);
+ assertEquals(10, (int)xBar3d.getGapDepth());
+ xBar3d.setGapWidth(10);
+ assertEquals(10, (int)xBar3d.getGapWidth());
+ }
+
+ private void handleLine3D(XDDFChartData data) {
+ XDDFLine3DChartData xLine3d = (XDDFLine3DChartData) data;
+ xLine3d.setGapDepth(10);
+ assertEquals(10, (int)xLine3d.getGapDepth());
+ }
+}
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
/**
assertEquals(10, p.getSpacingBefore());
p.setSpacingAfter(100);
- assertEquals(100, spacing.getAfter().intValue());
+ assertEquals("100", spacing.xgetAfter().getStringValue());
p.setSpacingBefore(100);
- assertEquals(100, spacing.getBefore().intValue());
+ assertEquals("100", spacing.xgetBefore().getStringValue());
p.setSpacingBetween(.25, LineSpacingRule.EXACT);
assertEquals(.25, p.getSpacingBetween(), 0.01);
assertEquals(LineSpacingRule.AT_LEAST, p.getSpacingLineRule());
p.setSpacingAfter(100);
- assertEquals(100, spacing.getAfter().intValue());
+ assertEquals("100", spacing.xgetAfter().getStringValue());
}
}
assertEquals(10, p.getIndentationLeft());
p.setIndentationLeft(100);
- assertEquals(100, ind.getLeft().intValue());
+ assertEquals("100", ind.xgetLeft().getStringValue());
}
}
@Test
CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
CTOnOff wordWrap = ppr.addNewWordWrap();
- wordWrap.setVal(STOnOff.FALSE);
+ wordWrap.setVal(STOnOff1.OFF);
assertFalse(p.isWordWrap());
p.setWordWrapped(true);
- assertEquals(STOnOff.TRUE, ppr.getWordWrap().getVal());
+ assertEquals("on", ppr.getWordWrap().getVal());
}
}
CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
CTOnOff pageBreak = ppr.addNewPageBreakBefore();
- pageBreak.setVal(STOnOff.FALSE);
+ pageBreak.setVal(STOnOff1.OFF);
assertFalse(p.isPageBreak());
p.setPageBreak(true);
- assertEquals(STOnOff.TRUE, ppr.getPageBreakBefore().getVal());
+ assertEquals("on", ppr.getPageBreakBefore().getVal());
}
}
assertTrue(p.removeRun(0));
}
}
-
+
@Test
public void testFieldRuns() throws IOException {
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FldSimple.docx")) {
/**
* Tests for numbered lists
- *
+ *
* See also https://github.com/jimklo/apache-poi-sample/blob/master/src/main/java/com/sri/jklo/StyledDocument.java
* for someone else trying a similar thing
*/
==================================================================== */
package org.apache.poi.xwpf.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.math.BigInteger;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1;
+import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STVerticalAlignRun;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STEm;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STHighlightColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STThemeColor;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
/**
* Tests for XWPF Run
@Test
public void testCTOnOff() {
CTRPr rpr = ctRun.addNewRPr();
- CTOnOff bold = rpr.addNewB();
+ CTOnOff bold = rpr.addNewB();
XWPFRun run = new XWPFRun(ctRun, irb);
// True values: "true", "1", "on"
- bold.setVal(STOnOff.TRUE);
+ bold.setVal(STOnOff1.ON);
assertTrue(run.isBold());
- bold.setVal(STOnOff.X_1);
+ bold.setVal(STOnOff1.ON);
assertTrue(run.isBold());
- bold.setVal(STOnOff.ON);
+ bold.setVal(STOnOff1.ON);
assertTrue(run.isBold());
// False values: "false", "0", "off"
- bold.setVal(STOnOff.FALSE);
+ bold.setVal(STOnOff1.OFF);
assertFalse(run.isBold());
- bold.setVal(STOnOff.X_0);
+ bold.setVal(STOnOff1.OFF);
assertFalse(run.isBold());
- bold.setVal(STOnOff.OFF);
+ bold.setVal(STOnOff1.OFF);
assertFalse(run.isBold());
}
@Test
public void testSetGetBold() {
CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewB().setVal(STOnOff.TRUE);
+ rpr.addNewB().setVal(STOnOff1.ON);
XWPFRun run = new XWPFRun(ctRun, irb);
assertTrue(run.isBold());
run.setBold(false);
// Implementation detail: POI natively prefers <w:b w:val="false"/>,
// but should correctly read val="0" and val="off"
- assertEquals(STOnOff.FALSE, rpr.getB().getVal());
+ assertEquals("off", rpr.getB().getVal());
}
@Test
public void testSetGetItalic() {
CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewI().setVal(STOnOff.TRUE);
+ rpr.addNewI().setVal(STOnOff1.ON);
XWPFRun run = new XWPFRun(ctRun, irb);
assertTrue(run.isItalic());
run.setItalic(false);
- assertEquals(STOnOff.FALSE, rpr.getI().getVal());
+ assertEquals("off", rpr.getI().getVal());
}
@Test
public void testSetGetStrike() {
CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewStrike().setVal(STOnOff.TRUE);
+ rpr.addNewStrike().setVal(STOnOff1.ON);
XWPFRun run = new XWPFRun(ctRun, irb);
assertTrue(run.isStrikeThrough());
run.setStrikeThrough(false);
- assertEquals(STOnOff.FALSE, rpr.getStrike().getVal());
+ assertEquals("off", rpr.getStrike().getVal());
}
@Test
assertEquals(7.0, run.getFontSizeAsDouble(), 0.01);
run.setFontSize(24);
- assertEquals(48, rpr.getSz().getVal().longValue());
+ assertEquals("48", rpr.getSz().getVal().toString());
run.setFontSize(24.5f);
- assertEquals(49, rpr.getSz().getVal().longValue());
+ assertEquals("49", rpr.getSz().getVal().toString());
assertEquals(25, run.getFontSize());
assertEquals(24.5, run.getFontSizeAsDouble(), 0.01);
}
assertEquals(4000, run.getTextPosition());
run.setTextPosition(2400);
- assertEquals(2400, rpr.getPosition().getVal().longValue());
+ assertEquals("2400", rpr.getPosition().getVal().toString());
}
@Test
assertFalse(run.isItalic());
assertFalse(run.isStrikeThrough());
assertNull(run.getCTR().getRPr());
-
+
doc.close();
}
assertEquals(1, doc.getAllPictures().size());
assertEquals(1, r.getEmbeddedPictures().size());
-
+
XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
XWPFParagraph pBack = docBack.getParagraphArray(2);
XWPFRun rBack = pBack.getRuns().get(0);
-
+
assertEquals(1, docBack.getAllPictures().size());
assertEquals(1, rBack.getEmbeddedPictures().size());
docBack.close();
doc.close();
}
-
+
/**
* Bugzilla #58237 - Unable to add image to word document header
*/
XWPFHeader hdr = doc.createHeader(HeaderFooterType.DEFAULT);
XWPFParagraph p = hdr.createParagraph();
XWPFRun r = p.createRun();
-
+
assertEquals(0, hdr.getAllPictures().size());
assertEquals(0, r.getEmbeddedPictures().size());
assertEquals(1, hdr.getAllPictures().size());
assertEquals(1, r.getEmbeddedPictures().size());
-
+
XWPFPicture pic = r.getEmbeddedPictures().get(0);
CTPicture ctPic = pic.getCTPicture();
CTBlipFillProperties ctBlipFill = ctPic.getBlipFill();
assertNotNull(ctBlipFill);
-
+
CTBlip ctBlip = ctBlipFill.getBlip();
-
+
assertNotNull(ctBlip);
assertEquals("rId1", ctBlip.getEmbed());
-
+
XWPFDocument docBack = XWPFTestDataSamples.writeOutAndReadBack(doc);
XWPFHeader hdrBack = docBack.getHeaderArray(0);
XWPFParagraph pBack = hdrBack.getParagraphArray(0);
XWPFRun rBack = pBack.getRuns().get(0);
-
+
assertEquals(1, hdrBack.getAllPictures().size());
assertEquals(1, rBack.getEmbeddedPictures().size());
docBack.close();
run.setTextPosition(-1);
assertEquals(-1, run.getTextPosition());
-
+
document.close();
}
run.setImprinted(true);
run.setItalic(true);
}
-
+
@Test
public void testSetGetTextScale() throws IOException {
XWPFDocument document = new XWPFDocument();
assertEquals(200, run.getTextScale());
document.close();
}
-
+
@Test
public void testSetGetTextHighlightColor() throws IOException {
XWPFDocument document = new XWPFDocument();
assertTrue(run.isHighlighted());
run.setTextHighlightColor("none");
assertFalse(run.isHighlighted());
-
+
document.close();
}
assertFalse(run.isVanish());
document.close();
}
-
+
@Test
public void testSetGetVerticalAlignment() throws IOException {
XWPFDocument document = new XWPFDocument();
assertEquals(STEm.DOT, run.getEmphasisMark());
document.close();
}
-
+
@Test
public void testSetGetUnderlineColor() throws IOException {
XWPFDocument document = new XWPFDocument();
assertEquals("auto", run.getUnderlineColor());
document.close();
}
-
+
@Test
public void testSetGetUnderlineThemeColor() throws IOException {
XWPFDocument document = new XWPFDocument();
assertEquals(STThemeColor.NONE, run.getUnderlineThemeColor());
document.close();
}
-
+
@Test
public void testSetStyleId() throws IOException {
XWPFDocument document = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
final XWPFRun run = document.createParagraph().createRun();
-
+
String styleId = "bolditalic";
run.setStyle(styleId);
String candStyleId = run.getCTR().getRPr().getRStyle().getVal();
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 org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblCellMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
public class TestXWPFTable {
@Test
- public void testConstructor() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable xtab = new XWPFTable(ctTable, doc);
- assertNotNull(xtab);
- assertEquals(1, ctTable.sizeOfTrArray());
- assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
- assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
-
- ctTable = CTTbl.Factory.newInstance();
- xtab = new XWPFTable(ctTable, doc, 3, 2);
- assertNotNull(xtab);
- assertEquals(3, ctTable.sizeOfTrArray());
- assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
- assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testConstructor() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable xtab = new XWPFTable(ctTable, doc);
+ assertNotNull(xtab);
+ assertEquals(1, ctTable.sizeOfTrArray());
+ assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
+ assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
+
+ ctTable = CTTbl.Factory.newInstance();
+ xtab = new XWPFTable(ctTable, doc, 3, 2);
+ assertNotNull(xtab);
+ assertEquals(3, ctTable.sizeOfTrArray());
+ assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
+ assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
}
}
@Test
- public void testTblGrid() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- CTTblGrid cttblgrid = ctTable.addNewTblGrid();
- cttblgrid.addNewGridCol().setW(BigInteger.valueOf(123));
- cttblgrid.addNewGridCol().setW(BigInteger.valueOf(321));
-
- XWPFTable xtab = new XWPFTable(ctTable, doc);
- assertEquals(123, xtab.getCTTbl().getTblGrid().getGridColArray(0).getW().intValue());
- assertEquals(321, xtab.getCTTbl().getTblGrid().getGridColArray(1).getW().intValue());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testTblGrid() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ CTTblGrid cttblgrid = ctTable.addNewTblGrid();
+ cttblgrid.addNewGridCol().setW(BigInteger.valueOf(123));
+ cttblgrid.addNewGridCol().setW(BigInteger.valueOf(321));
+
+ XWPFTable xtab = new XWPFTable(ctTable, doc);
+ CTTblGridCol[] ca = xtab.getCTTbl().getTblGrid().getGridColArray();
+ assertEquals("123", ca[0].getW().toString());
+ assertEquals("321", ca[1].getW().toString());
}
}
@Test
- public void testGetText() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl table = CTTbl.Factory.newInstance();
- CTRow row = table.addNewTr();
- CTTc cell = row.addNewTc();
- CTP paragraph = cell.addNewP();
- CTR run = paragraph.addNewR();
- CTText text = run.addNewT();
- text.setStringValue("finally I can write!");
-
- XWPFTable xtab = new XWPFTable(table, doc);
- assertEquals("finally I can write!\n", xtab.getText());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testGetText() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl table = CTTbl.Factory.newInstance();
+ CTRow row = table.addNewTr();
+ CTTc cell = row.addNewTc();
+ CTP paragraph = cell.addNewP();
+ CTR run = paragraph.addNewR();
+ CTText text = run.addNewT();
+ text.setStringValue("finally I can write!");
+
+ XWPFTable xtab = new XWPFTable(table, doc);
+ assertEquals("finally I can write!\n", xtab.getText());
}
}
@Test
- public void testCreateRow() {
- XWPFDocument doc = new XWPFDocument();
-
- CTTbl table = CTTbl.Factory.newInstance();
- CTRow r1 = table.addNewTr();
- r1.addNewTc().addNewP();
- r1.addNewTc().addNewP();
- CTRow r2 = table.addNewTr();
- r2.addNewTc().addNewP();
- r2.addNewTc().addNewP();
- CTRow r3 = table.addNewTr();
- r3.addNewTc().addNewP();
- r3.addNewTc().addNewP();
-
- XWPFTable xtab = new XWPFTable(table, doc);
- assertEquals(3, xtab.getNumberOfRows());
- assertNotNull(xtab.getRow(2));
-
- //add a new row
- xtab.createRow();
- assertEquals(4, xtab.getNumberOfRows());
-
- //check number of cols
- assertEquals(2, table.getTrArray(0).sizeOfTcArray());
-
- //check creation of first row
- xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
- assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testCreateRow() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ CTTbl table = CTTbl.Factory.newInstance();
+ CTRow r1 = table.addNewTr();
+ r1.addNewTc().addNewP();
+ r1.addNewTc().addNewP();
+ CTRow r2 = table.addNewTr();
+ r2.addNewTc().addNewP();
+ r2.addNewTc().addNewP();
+ CTRow r3 = table.addNewTr();
+ r3.addNewTc().addNewP();
+ r3.addNewTc().addNewP();
+
+ XWPFTable xtab = new XWPFTable(table, doc);
+ assertEquals(3, xtab.getNumberOfRows());
+ assertNotNull(xtab.getRow(2));
+
+ //add a new row
+ xtab.createRow();
+ assertEquals(4, xtab.getNumberOfRows());
+
+ //check number of cols
+ assertEquals(2, table.getTrArray(0).sizeOfTcArray());
+
+ //check creation of first row
+ xtab = new XWPFTable(CTTbl.Factory.newInstance(), doc);
+ assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
}
}
@Test
- public void testSetGetWidth() {
- XWPFDocument doc = new XWPFDocument();
-
- XWPFTable xtab = doc.createTable();
-
- assertEquals(0, xtab.getWidth());
- assertEquals(TableWidthType.AUTO, xtab.getWidthType());
-
- xtab.setWidth(1000);
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(1000, xtab.getWidth());
-
- xtab.setWidth("auto");
- assertEquals(TableWidthType.AUTO, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
- assertEquals(0.0, xtab.getWidthDecimal(), 0.01);
-
- xtab.setWidth("999");
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(999, xtab.getWidth());
-
- xtab.setWidth("50.5%");
- assertEquals(TableWidthType.PCT, xtab.getWidthType());
- assertEquals(50.5, xtab.getWidthDecimal(), 0.01);
-
- // Test effect of setting width type to a new value
-
- // From PCT to NIL:
- xtab.setWidthType(TableWidthType.NIL);
- assertEquals(TableWidthType.NIL, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
-
- xtab.setWidth("999"); // Sets type to DXA
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
-
- // From DXA to AUTO:
- xtab.setWidthType(TableWidthType.AUTO);
- assertEquals(TableWidthType.AUTO, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
-
- xtab.setWidthType(TableWidthType.PCT);
- assertEquals(TableWidthType.PCT, xtab.getWidthType());
-
- // From PCT to DXA:
- xtab.setWidth("33.3%");
- xtab.setWidthType(TableWidthType.DXA);
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(0, xtab.getWidth());
-
- // From DXA to DXA: (value should be unchanged)
- xtab.setWidth("999");
- xtab.setWidthType(TableWidthType.DXA);
- assertEquals(TableWidthType.DXA, xtab.getWidthType());
- assertEquals(999, xtab.getWidth());
-
- // From DXA to PCT:
- xtab.setWidthType(TableWidthType.PCT);
- assertEquals(TableWidthType.PCT, xtab.getWidthType());
- assertEquals(100.0, xtab.getWidthDecimal(), 0.0);
-
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetWidth() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ XWPFTable xtab = doc.createTable();
+
+ assertEquals(0, xtab.getWidth());
+ assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+
+ xtab.setWidth(1000);
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(1000, xtab.getWidth());
+
+ xtab.setWidth("auto");
+ assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+ assertEquals(0.0, xtab.getWidthDecimal(), 0.01);
+
+ xtab.setWidth("999");
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(999, xtab.getWidth());
+
+ xtab.setWidth("50.5%");
+ assertEquals(TableWidthType.PCT, xtab.getWidthType());
+ assertEquals(50.5, xtab.getWidthDecimal(), 0.01);
+
+ // Test effect of setting width type to a new value
+
+ // From PCT to NIL:
+ xtab.setWidthType(TableWidthType.NIL);
+ assertEquals(TableWidthType.NIL, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+
+ xtab.setWidth("999"); // Sets type to DXA
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+
+ // From DXA to AUTO:
+ xtab.setWidthType(TableWidthType.AUTO);
+ assertEquals(TableWidthType.AUTO, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+
+ xtab.setWidthType(TableWidthType.PCT);
+ assertEquals(TableWidthType.PCT, xtab.getWidthType());
+
+ // From PCT to DXA:
+ xtab.setWidth("33.3%");
+ xtab.setWidthType(TableWidthType.DXA);
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(0, xtab.getWidth());
+
+ // From DXA to DXA: (value should be unchanged)
+ xtab.setWidth("999");
+ xtab.setWidthType(TableWidthType.DXA);
+ assertEquals(TableWidthType.DXA, xtab.getWidthType());
+ assertEquals(999, xtab.getWidth());
+
+ // From DXA to PCT:
+ xtab.setWidthType(TableWidthType.PCT);
+ assertEquals(TableWidthType.PCT, xtab.getWidthType());
+ assertEquals(100.0, xtab.getWidthDecimal(), 0.0);
}
}
@Test
- public void testSetGetHeight() {
- XWPFDocument doc = new XWPFDocument();
-
- CTTbl table = CTTbl.Factory.newInstance();
-
- XWPFTable xtab = new XWPFTable(table, doc);
- XWPFTableRow row = xtab.createRow();
- row.setHeight(20);
- assertEquals(20, row.getHeight());
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetHeight() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ CTTbl table = CTTbl.Factory.newInstance();
+
+ XWPFTable xtab = new XWPFTable(table, doc);
+ XWPFTableRow row = xtab.createRow();
+ row.setHeight(20);
+ assertEquals(20, row.getHeight());
}
}
@Test
- public void testSetGetMargins() {
+ public void testSetGetMargins() throws IOException {
// instantiate the following class so it'll get picked up by
// the XmlBean process and added to the jar file. it's required
// for the following XWPFTable methods.
CTTblCellMar ctm = CTTblCellMar.Factory.newInstance();
assertNotNull(ctm);
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // set margins
- table.setCellMargins(50, 50, 250, 450);
- // get margin components
- int t = table.getCellMarginTop();
- assertEquals(50, t);
- int l = table.getCellMarginLeft();
- assertEquals(50, l);
- int b = table.getCellMarginBottom();
- assertEquals(250, b);
- int r = table.getCellMarginRight();
- assertEquals(450, r);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // set margins
+ table.setCellMargins(50, 50, 250, 450);
+ // get margin components
+ int t = table.getCellMarginTop();
+ assertEquals(50, t);
+ int l = table.getCellMarginLeft();
+ assertEquals(50, l);
+ int b = table.getCellMarginBottom();
+ assertEquals(250, b);
+ int r = table.getCellMarginRight();
+ assertEquals(450, r);
}
}
@Test
- public void testSetGetHBorders() {
+ public void testSetGetHBorders() throws IOException {
// 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.
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);
- // check initial state
- XWPFBorderType bt = table.getInsideHBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getInsideHBorderSize();
- assertEquals(-1, sz);
- int sp = table.getInsideHBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getInsideHBorderColor();
- assertNull(clr);
- // set inside horizontal border
- table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
- // get inside horizontal border components
- bt = table.getInsideHBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- sz = table.getInsideHBorderSize();
- assertEquals(4, sz);
- sp = table.getInsideHBorderSpace();
- assertEquals(0, sp);
- clr = table.getInsideHBorderColor();
- assertEquals("FF0000", clr);
- // remove the border and verify state
- table.removeInsideHBorder();
- bt = table.getInsideHBorderType();
- assertNull(bt);
- sz = table.getInsideHBorderSize();
- assertEquals(-1, sz);
- sp = table.getInsideHBorderSpace();
- assertEquals(-1, sp);
- clr = table.getInsideHBorderColor();
- assertNull(clr);
- // check other borders
- bt = table.getInsideVBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- // remove the rest all at once and test
- table.removeBorders();
- bt = table.getInsideVBorderType();
- assertNull(bt);
- bt = table.getTopBorderType();
- assertNull(bt);
- bt = table.getBottomBorderType();
- assertNull(bt);
- bt = table.getLeftBorderType();
- assertNull(bt);
- bt = table.getRightBorderType();
- assertNull(bt);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getInsideHBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getInsideHBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getInsideHBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getInsideHBorderColor();
+ assertNull(clr);
+ // set inside horizontal border
+ table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
+ // get inside horizontal border components
+ bt = table.getInsideHBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ sz = table.getInsideHBorderSize();
+ assertEquals(4, sz);
+ sp = table.getInsideHBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getInsideHBorderColor();
+ assertEquals("FF0000", clr);
+ // remove the border and verify state
+ table.removeInsideHBorder();
+ bt = table.getInsideHBorderType();
+ assertNull(bt);
+ sz = table.getInsideHBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getInsideHBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getInsideHBorderColor();
+ assertNull(clr);
+ // check other borders
+ bt = table.getInsideVBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ // remove the rest all at once and test
+ table.removeBorders();
+ bt = table.getInsideVBorderType();
+ assertNull(bt);
+ bt = table.getTopBorderType();
+ assertNull(bt);
+ bt = table.getBottomBorderType();
+ assertNull(bt);
+ bt = table.getLeftBorderType();
+ assertNull(bt);
+ bt = table.getRightBorderType();
+ assertNull(bt);
}
}
@Test
- public void testSetGetVBorders() {
+ public void testSetGetVBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getInsideVBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getInsideVBorderSize();
- assertEquals(-1, sz);
- int sp = table.getInsideVBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getInsideVBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getInsideVBorderType();
- assertEquals(XWPFBorderType.DOUBLE, bt);
- sz = table.getInsideVBorderSize();
- assertEquals(4, sz);
- sp = table.getInsideVBorderSpace();
- assertEquals(0, sp);
- clr = table.getInsideVBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeInsideVBorder();
- bt = table.getInsideVBorderType();
- assertNull(bt);
- sz = table.getInsideVBorderSize();
- assertEquals(-1, sz);
- sp = table.getInsideVBorderSpace();
- assertEquals(-1, sp);
- clr = table.getInsideVBorderColor();
- assertNull(clr);
- // check the rest
- bt = table.getInsideHBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- // remove the rest one at a time and test
- table.removeInsideHBorder();
- table.removeTopBorder();
- table.removeBottomBorder();
- table.removeLeftBorder();
- table.removeRightBorder();
- bt = table.getInsideHBorderType();
- assertNull(bt);
- bt = table.getTopBorderType();
- assertNull(bt);
- bt = table.getBottomBorderType();
- assertNull(bt);
- bt = table.getLeftBorderType();
- assertNull(bt);
- bt = table.getRightBorderType();
- assertNull(bt);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getInsideVBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getInsideVBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getInsideVBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getInsideVBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getInsideVBorderType();
+ assertEquals(XWPFBorderType.DOUBLE, bt);
+ sz = table.getInsideVBorderSize();
+ assertEquals(4, sz);
+ sp = table.getInsideVBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getInsideVBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeInsideVBorder();
+ bt = table.getInsideVBorderType();
+ assertNull(bt);
+ sz = table.getInsideVBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getInsideVBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getInsideVBorderColor();
+ assertNull(clr);
+ // check the rest
+ bt = table.getInsideHBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ // remove the rest one at a time and test
+ table.removeInsideHBorder();
+ table.removeTopBorder();
+ table.removeBottomBorder();
+ table.removeLeftBorder();
+ table.removeRightBorder();
+ bt = table.getInsideHBorderType();
+ assertNull(bt);
+ bt = table.getTopBorderType();
+ assertNull(bt);
+ bt = table.getBottomBorderType();
+ assertNull(bt);
+ bt = table.getLeftBorderType();
+ assertNull(bt);
+ bt = table.getRightBorderType();
+ assertNull(bt);
}
}
@Test
- public void testSetGetTopBorders() {
+ public void testSetGetTopBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getTopBorderSize();
- assertEquals(-1, sz);
- int sp = table.getTopBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getTopBorderColor();
- assertNull(clr);
- // set top border
- table.setTopBorder(XWPFBorderType.THICK, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getTopBorderType();
- assertEquals(XWPFBorderType.THICK, bt);
- sz = table.getTopBorderSize();
- assertEquals(4, sz);
- sp = table.getTopBorderSpace();
- assertEquals(0, sp);
- clr = table.getTopBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeTopBorder();
- bt = table.getTopBorderType();
- assertNull(bt);
- sz = table.getTopBorderSize();
- assertEquals(-1, sz);
- sp = table.getTopBorderSpace();
- assertEquals(-1, sp);
- clr = table.getTopBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getTopBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getTopBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getTopBorderColor();
+ assertNull(clr);
+ // set top border
+ table.setTopBorder(XWPFBorderType.THICK, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getTopBorderType();
+ assertEquals(XWPFBorderType.THICK, bt);
+ sz = table.getTopBorderSize();
+ assertEquals(4, sz);
+ sp = table.getTopBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getTopBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeTopBorder();
+ bt = table.getTopBorderType();
+ assertNull(bt);
+ sz = table.getTopBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getTopBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getTopBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetBottomBorders() {
+ public void testSetGetBottomBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getBottomBorderSize();
- assertEquals(-1, sz);
- int sp = table.getBottomBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getBottomBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setBottomBorder(XWPFBorderType.DOTTED, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getBottomBorderType();
- assertEquals(XWPFBorderType.DOTTED, bt);
- sz = table.getBottomBorderSize();
- assertEquals(4, sz);
- sp = table.getBottomBorderSpace();
- assertEquals(0, sp);
- clr = table.getBottomBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeBottomBorder();
- bt = table.getBottomBorderType();
- assertNull(bt);
- sz = table.getBottomBorderSize();
- assertEquals(-1, sz);
- sp = table.getBottomBorderSpace();
- assertEquals(-1, sp);
- clr = table.getBottomBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getBottomBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getBottomBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getBottomBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setBottomBorder(XWPFBorderType.DOTTED, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getBottomBorderType();
+ assertEquals(XWPFBorderType.DOTTED, bt);
+ sz = table.getBottomBorderSize();
+ assertEquals(4, sz);
+ sp = table.getBottomBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getBottomBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeBottomBorder();
+ bt = table.getBottomBorderType();
+ assertNull(bt);
+ sz = table.getBottomBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getBottomBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getBottomBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetLeftBorders() {
+ public void testSetGetLeftBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getLeftBorderSize();
- assertEquals(-1, sz);
- int sp = table.getLeftBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getLeftBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setLeftBorder(XWPFBorderType.DASHED, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getLeftBorderType();
- assertEquals(XWPFBorderType.DASHED, bt);
- sz = table.getLeftBorderSize();
- assertEquals(4, sz);
- sp = table.getLeftBorderSpace();
- assertEquals(0, sp);
- clr = table.getLeftBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeLeftBorder();
- bt = table.getLeftBorderType();
- assertNull(bt);
- sz = table.getLeftBorderSize();
- assertEquals(-1, sz);
- sp = table.getLeftBorderSpace();
- assertEquals(-1, sp);
- clr = table.getLeftBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getLeftBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getLeftBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getLeftBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setLeftBorder(XWPFBorderType.DASHED, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getLeftBorderType();
+ assertEquals(XWPFBorderType.DASHED, bt);
+ sz = table.getLeftBorderSize();
+ assertEquals(4, sz);
+ sp = table.getLeftBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getLeftBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeLeftBorder();
+ bt = table.getLeftBorderType();
+ assertNull(bt);
+ sz = table.getLeftBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getLeftBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getLeftBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetRightBorders() {
+ public void testSetGetRightBorders() throws IOException {
// create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // check initial state
- XWPFBorderType bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.SINGLE, bt);
- int sz = table.getRightBorderSize();
- assertEquals(-1, sz);
- int sp = table.getRightBorderSpace();
- assertEquals(-1, sp);
- String clr = table.getRightBorderColor();
- assertNull(clr);
- // set inside vertical border
- table.setRightBorder(XWPFBorderType.DOT_DASH, 4, 0, "00FF00");
- // get inside vertical border components
- bt = table.getRightBorderType();
- assertEquals(XWPFBorderType.DOT_DASH, bt);
- sz = table.getRightBorderSize();
- assertEquals(4, sz);
- sp = table.getRightBorderSpace();
- assertEquals(0, sp);
- clr = table.getRightBorderColor();
- assertEquals("00FF00", clr);
- // remove the border and verify state
- table.removeRightBorder();
- bt = table.getRightBorderType();
- assertNull(bt);
- sz = table.getRightBorderSize();
- assertEquals(-1, sz);
- sp = table.getRightBorderSpace();
- assertEquals(-1, sp);
- clr = table.getRightBorderColor();
- assertNull(clr);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // check initial state
+ XWPFBorderType bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.SINGLE, bt);
+ int sz = table.getRightBorderSize();
+ assertEquals(-1, sz);
+ int sp = table.getRightBorderSpace();
+ assertEquals(-1, sp);
+ String clr = table.getRightBorderColor();
+ assertNull(clr);
+ // set inside vertical border
+ table.setRightBorder(XWPFBorderType.DOT_DASH, 4, 0, "00FF00");
+ // get inside vertical border components
+ bt = table.getRightBorderType();
+ assertEquals(XWPFBorderType.DOT_DASH, bt);
+ sz = table.getRightBorderSize();
+ assertEquals(4, sz);
+ sp = table.getRightBorderSpace();
+ assertEquals(0, sp);
+ clr = table.getRightBorderColor();
+ assertEquals("00FF00", clr);
+ // remove the border and verify state
+ table.removeRightBorder();
+ bt = table.getRightBorderType();
+ assertNull(bt);
+ sz = table.getRightBorderSize();
+ assertEquals(-1, sz);
+ sp = table.getRightBorderSpace();
+ assertEquals(-1, sp);
+ clr = table.getRightBorderColor();
+ assertNull(clr);
}
}
@Test
- public void testSetGetRowBandSize() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- table.setRowBandSize(12);
- int sz = table.getRowBandSize();
- assertEquals(12, sz);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetRowBandSize() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ table.setRowBandSize(12);
+ int sz = table.getRowBandSize();
+ assertEquals(12, sz);
}
}
@Test
- public void testSetGetColBandSize() {
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- table.setColBandSize(16);
- int sz = table.getColBandSize();
- assertEquals(16, sz);
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ public void testSetGetColBandSize() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ table.setColBandSize(16);
+ int sz = table.getColBandSize();
+ assertEquals(16, sz);
}
}
@Test
public void testCreateTable() throws Exception {
// open an empty document
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-
- // create a table with 5 rows and 7 columns
- int noRows = 5;
- int noCols = 7;
- XWPFTable table = doc.createTable(noRows, noCols);
-
- // assert the table is empty
- List<XWPFTableRow> rows = table.getRows();
- assertEquals("Table has less rows than requested.", noRows, rows.size());
- for (XWPFTableRow xwpfRow : rows) {
- assertNotNull(xwpfRow);
- for (int i = 0; i < 7; i++) {
- XWPFTableCell xwpfCell = xwpfRow.getCell(i);
- assertNotNull(xwpfCell);
- assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
- xwpfCell = xwpfRow.getCell(i);
- assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+ try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
+
+ // create a table with 5 rows and 7 columns
+ int noRows = 5;
+ int noCols = 7;
+ XWPFTable table = doc.createTable(noRows, noCols);
+
+ // assert the table is empty
+ List<XWPFTableRow> rows = table.getRows();
+ assertEquals("Table has less rows than requested.", noRows, rows.size());
+ for (XWPFTableRow xwpfRow : rows) {
+ assertNotNull(xwpfRow);
+ for (int i = 0; i < 7; i++) {
+ XWPFTableCell xwpfCell = xwpfRow.getCell(i);
+ assertNotNull(xwpfCell);
+ assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
+ xwpfCell = xwpfRow.getCell(i);
+ assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+ }
}
- }
- doc.getPackage().revert();
- try {
- doc.close();
- } catch (IOException e) {
- fail("Unable to close doc");
+ doc.getPackage().revert();
}
}
-
+
@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");
+ public void testSetGetTableAlignment() throws IOException {
+ try (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());
}
}
}
\ No newline at end of file