XWPF转换器在打开XLSX时引发异常

时间:2019-03-14 14:26:32

标签: java apache-poi pdf-generation openxml xwpf

我需要将XLSX文件转换为PDF文件。 XLSX是使用Apache POI使用以下元素生成的(其中很多元素,仅显示每种1):

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFCellStyle mainTJKHeaderCellStyle; //it is defined later
Font mainTJKHeaderFont; //defined later
XSSFRow mainTJKHeaderRow = sheet.createRow(0);
XSSFCell mainTJKHeaderCell = mainTJKHeaderRow.createCell(0);

我还必须使用一些CellRangeAddress-es,但是据我所知,它们没有任何特定的XSSF变体。或者我找不到任何东西。

Excel可以打开生成的文件而没有问题。

当我尝试将电子表格馈送到转换器时出现问题,它将引发以下异常:

org.apache.poi.ooxml.POIXMLException: org.apache.xmlbeans.XmlException: Element workbook@http://schemas.openxmlformats.org/spreadsheetml/2006/main is not a valid document@http://schemas.openxmlformats.org/wordprocessingml/2006/main document or a valid substitution.
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:267)
    at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:184)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:144)
    at Utilities.PDFConverter.convertToPDF(PDFConverter.java:16)
    at TEMPLATE.GenericTestClass.closeBrowser(GenericTestClass.java:75)

还有另一个例外,但是它也没有使我靠近问题的根源:

Caused by: org.apache.xmlbeans.XmlException: Element workbook@http://schemas.openxmlformats.org/spreadsheetml/2006/main is not a valid document@http://schemas.openxmlformats.org/wordprocessingml/2006/main document or a valid substitution.
    at org.apache.xmlbeans.impl.store.Locale.autoTypeDocument(Locale.java:324)
    at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1275)
    at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
    at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
    at org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:177)
    ... 31 more

我试图检查异常中的URL,但它似乎不起作用,因此问题可能是该库使用了过时的资源,并且由于它无法访问那里的文件,因此将无法使用确定接收到的xml的类型?

我正在使用fr.opensagres.xdocreporthttps://mvnrepository.com/search?q=fr.opensagres.xdocreport)中的最新库

有人遇到类似的问题吗?

PS:由于预算问题,我们的项目无法使用GcExcel解决方案。

0 个答案:

没有答案