0

I am trying to generate excel sheets, PDFs, and word documents using apache poi. Following are the pom entries I used in the code

 <!-- EXCEL GENERATION REPORT -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.2</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.2</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls-reader</artifactId>
            <version>2.0.5</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.jxls</groupId>
            <artifactId>jxls</artifactId>
            <version>2.6.0</version>
            <optional>true</optional>
        </dependency>

        <!-- WORD GENERATION REPORT-->

        <dependency>
            <groupId>org.docx4j</groupId>
            <artifactId>docx4j</artifactId>
            <version>3.3.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpclient</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.4.4</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.itextpdf.tool</groupId>
            <artifactId>xmlworker</artifactId>
            <version>5.4.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itext-pdfa</artifactId>
            <version>5.4.4</version>
            <optional>true</optional>
        </dependency>


        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.xdocreport.document.docx</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.xdocreport.document</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId> fr.opensagres.xdocreport.core</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.xdocreport.converter</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.xdocreport.converter.docx.xwpf</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>fr.opensagres.xdocreport</groupId>
                    <artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.poi.xwpf.converter.pdf.itext5</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>fr.opensagres.xdocreport</groupId>
            <artifactId>fr.opensagres.xdocreport.template</artifactId>
            <version>2.0.4</version>
            <optional>true</optional>
        </dependency>


import java.math.BigInteger;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageSz;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STPageOrientation;

public class DocumentHelper {

     public static XWPFDocument getXwpfDocument() {
        XWPFDocument document = new XWPFDocument();
        CTBody body = document.getDocument().getBody();
        if (!body.isSetSectPr()) {
            body.addNewSectPr();
        }
        CTSectPr section = body.getSectPr();
        if (!section.isSetPgSz()) {
            section.addNewPgSz();
        }
        return document;
    }

    }

Following code is using to generate the report

public void generateReport(ReportParameters reportParameters, OutputStream outputStream) throws XDocConverterException, IOException {
        val document = getXwpfDocument();
        createParagraph(document, "RESTRICTED", 12, CENTER, true, SINGLE);
        document.write(outputStream);
    }

When I am trying to deploy the application, I am getting this exception :

java.lang.ClassNotFoundException: fr.opensagres.xdocreport.converter.XDocConverterException Any leads to solve the issue.

Misthi
  • 33
  • 10

1 Answers1

0

You can refer to this link: https://github.com/zkh152/xdocreport/issues/40 Summarize: Maybe you should try to upgrade dependencies -> itext -> version to 2.1.7