簡體   English   中英

如何為 XLSReader 配置 XML-config

[英]How to configure XML-config for XLSReader

我正在使用org.jxls:jxls-reader從 excel 表中讀取一些數據。 這些行從 excel 第 20 行開始,應該讀取到下一行為空。 但是我無法正確配置 xml-config 以讀取行。

第一行之后的每一行都返回一個null值。

我試圖了解http://jxls.sourceforge.net/reference/reader.html中提供的departmentdata.xls但我無法正確理解。

對配置的一些見解將不勝感激。

我在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)

我的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>

當 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 

預期行為:讀取所有行

實際結果:讀取第一行,然后一切都是null

在您的循環標記中,startRow 和 endRow 必須相同。 在您的 loopbreakcondition 中, cellcheck 標記位於 rowcheck 標記內。

而且我不確定映射是否適用於與字符串不同的東西

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM