Reputation: 11
I'm trying to get single spacing (or no spacing) inside multiple Word Tables created using Apache POI. If I create the XWPFTable using the default parameters, the spacing is established into Normal (1.5 if I'm not wrong), but I don't know how to change the default spacing.
Upvotes: 0
Views: 1254
Reputation: 11493
You should be able to do that by setting the paragraph properties for the paragraph in question. Unfortunately the appropriate property is not surfaced in the API. Please report this in bugzilla https://bz.apache.org/bugzilla/buglist.cgi?product=POI and I will try to get it into the next release. In the mean time you could modify XWPFParagraph by adding the following method:
public void setSpacingBetween(int spaces, LineSpacingRule rule) {
CTSpacing spacing = getCTSpacing(true);
spacing.setLine(new BigInteger("" + spaces));
spacing.setLineRule(STLineSpacingRule.Enum.forInt(rule.getValue()));
}
or you could use the CT classes to add the appropriate attribute to the paragraph property like this (where p is your paragraph):
CTP ctP = p.getCTP();
CTPPr ctPr = ctP.isSetPPr() ? ctP.getPPr() : ctP.addNewPPr();
CTSpacing ctSpacing = ctPr.isSetSpacing() ? ctPr.getSpacing() : ctPr.addNewSpacing();
ctSpacing.setLine(new BigInteger("240"));
Upvotes: 2