Improve html type field exports

This commit is contained in:
George Kalampokis 2021-11-09 17:44:47 +02:00
parent adeca327a2
commit 7820235258
2 changed files with 12 additions and 2 deletions

View File

@ -205,7 +205,14 @@ public class HtmlToWorldBuilder implements NodeVisitor {
ctLvl.addNewNumFmt().setVal(format); ctLvl.addNewNumFmt().setVal(format);
ctLvl.addNewStart().setVal(BigInteger.ONE); ctLvl.addNewStart().setVal(BigInteger.ONE);
if (format == STNumberFormat.BULLET) { if (format == STNumberFormat.BULLET) {
ctLvl.addNewLvlJc().setVal(STJc.LEFT);
ctLvl.addNewLvlText().setVal("\u2022"); ctLvl.addNewLvlText().setVal("\u2022");
ctLvl.addNewRPr(); //Set the Symbol font
CTFonts f = ctLvl.getRPr().addNewRFonts();
f.setAscii("Symbol");
f.setHAnsi("Symbol");
f.setCs("Symbol");
f.setHint(STHint.DEFAULT);
} else { } else {
ctLvl.addNewLvlText().setVal("%1."); ctLvl.addNewLvlText().setVal("%1.");
} }

View File

@ -34,10 +34,12 @@ public class WordBuilder {
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>(); private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
private CTAbstractNum cTAbstractNum; private CTAbstractNum cTAbstractNum;
private BigInteger numId; private BigInteger numId;
private Integer indent;
public WordBuilder() { public WordBuilder() {
this.cTAbstractNum = CTAbstractNum.Factory.newInstance(); this.cTAbstractNum = CTAbstractNum.Factory.newInstance();
this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1)); this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1));
this.indent = 0;
this.buildOptions(); this.buildOptions();
} }
@ -52,7 +54,7 @@ public class WordBuilder {
}); });
this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> { this.options.put(ParagraphStyle.HTML, (mainDocumentPart, item) -> {
Document htmlDoc = Jsoup.parse(item.replaceAll("\n", "<br>")); Document htmlDoc = Jsoup.parse(item.replaceAll("\n", "<br>"));
HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, 0.8F); HtmlToWorldBuilder htmlToWorldBuilder = HtmlToWorldBuilder.convert(mainDocumentPart, htmlDoc, indent > 0 ? (indent/2.0F) * 0.8F : 0.8F);
return htmlToWorldBuilder.getParagraph(); return htmlToWorldBuilder.getParagraph();
}); });
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> { this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
@ -221,7 +223,8 @@ public class WordBuilder {
if (!createListing) { if (!createListing) {
try { try {
if (field.getValue() != null && !field.getValue().toString().isEmpty()) { if (field.getValue() != null && !field.getValue().toString().isEmpty()) {
XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, ParagraphStyle.TEXT, numId); this.indent = indent;
XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, field.getViewStyle().getRenderStyle().equals("richTextarea") ? ParagraphStyle.HTML : ParagraphStyle.TEXT, numId);
if (paragraph != null) { if (paragraph != null) {
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent)); number.setVal(BigInteger.valueOf(indent));