简体   繁体   English

如何为 XLSReader 配置 XML-config

[英]How to configure XML-config for XLSReader

I'm using the org.jxls:jxls-reader to read some data from an excel-sheet.我正在使用org.jxls:jxls-reader从 excel 表中读取一些数据。 The rows start at excel row 20 and should be read until the next row is empty.这些行从 excel 第 20 行开始,应该读取到下一行为空。 But I have problems to get the xml-config configured right to read the rows.但是我无法正确配置 xml-config 以读取行。

Every following row after the first returns a null value.第一行之后的每一行都返回一个null值。

I've tried to understand the departmentdata.xls provided in http://jxls.sourceforge.net/reference/reader.html but i can't get it right.我试图了解http://jxls.sourceforge.net/reference/reader.html中提供的departmentdata.xls但我无法正确理解。

Some insights for the configuration would be appreciated.对配置的一些见解将不胜感激。

My Code in ExcelUploadController :我在ExcelUploadController中的代码:

            InputStream xmlInputStream = new FileInputStream(xmlFile)

            XLSReader reader = ReaderBuilder.buildFromXML(xmlInputStream);

            InputStream xlsInputStream = dataFile.getInputStream();

            DocumentDetailPosition documentDetailPosition = new DocumentDetailPosition();

            List<DocumentDetailPosition> documentDetailPositions = new ArrayList<>();

            Map<String, Object> beans = new HashMap<>();

            beans.put("documentDetailPosition", documentDetailPosition);

            beans.put("documentDetailPositions", documentDetailPositions);

            XLSReadStatus status = reader.read(xlsInputStream, beans)

My xml-Config :我的xml-Config

   <workbook>
       <worksheet name="worksheet1">
        <section startRow="0" endRow="19"/>
            <loop startRow="19" endRow="29" items="documentDetailPositions" var="documentDetailPosition" varType="pl.fissst.crm.esales.pojo.DocumentDetailPosition">
               <section startRow="19" endRow="29">
                   <mapping row="19" col="0" type="java.lang.Integer">documentDetailPosition.posProductNo</mapping>
                   <mapping row="19" col="1" type="java.lang.Integer">documentDetailPosition.quantity</mapping>
                   <mapping row="19" col="3"  type="java.util.Date">documentDetailPosition.requestDate</mapping>
               </section>
               <loopbreakcondition>
                   <rowcheck offset="0"/>
                   <cellcheck offset="0"></cellcheck>
               </loopbreakcondition>
           </loop>
       </worksheet>
    </workbook>

when the values of DocumentDetail get printed the log shows:当 DocumentDetail 的值被打印时,日志显示:

INFO  885744 g.a.c.p.f.c.e.ExcelUploadController - 1234567
INFO  885744 g.a.c.p.f.c.e.ExcelUploadController - 5 
INFO  885746 g.a.c.p.f.c.e.ExcelUploadController - Thu Jan 03 00:00:00 CET 2019 

INFO  885746 g.a.c.p.f.c.e.ExcelUploadController - null 
INFO  885746 g.a.c.p.f.c.e.ExcelUploadController - null 
INFO  885746 g.a.c.p.f.c.e.ExcelUploadController - null 

Expected behavior: Reading all rows预期行为:读取所有行

Actual Result: Reading first row and then everything is null实际结果:读取第一行,然后一切都是null

In your loop tag, startRow and endRow must be the same.在您的循环标记中,startRow 和 endRow 必须相同。 In your loopbreakcondition, the cellcheck tag goes inside the rowcheck tag.在您的 loopbreakcondition 中, cellcheck 标记位于 rowcheck 标记内。

And I'm not sure if the mapping works with something different than strings而且我不确定映射是否适用于与字符串不同的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM