使用java

时间:2016-02-24 16:27:28

标签: java

我遇到了一个问题,即我有下面的代码片段,其中我读取了多个excel选项卡表并将sheet值存储在名为brokerInvoice object的对象中

如果我有单个tab excel表,如下所示,最终它会读取单个excel表单并进行一些操作并最终设置对象brokerInvoice

 List<BrokerInvoiceLineItem> brokerInvoiceLineItemList = new ArrayList<BrokerInvoiceLineItem>();
               brokerInvoice = readinginvoiceimpl.findHeaderRowNumber(workbookXls, 0, brokerInvoiceLineItemList, brokerInvoice , brokerIdLong , finalfilteredfilename,dateType );

当我必须阅读带有多个标签的excel表时,问题就出现了,下面你可以看到我已经开始循环了但是问题就出现了,它会立即读取第一张表,它设置了名为brokerInvoice的对象的值,然后它进行第二次excel表操作并覆盖第一个存储的对象属性值,因此名为brokerInvoice的对象始终使用最后一个表的值填充

请告知我如何更正我的下方循环,以便每个工作表操作都已完成,经纪人发票应包含所有选项卡的值

  for (int i = 0; i < workbookXls.getNumberOfSheets(); i++) {
                List<BrokerInvoiceLineItem> brokerInvoiceLineItemList = new ArrayList<BrokerInvoiceLineItem>();
                brokerInvoice = readinginvoiceimpl.findHeaderRowNumber(workbookXls, 0, brokerInvoiceLineItemList, brokerInvoice , brokerIdLong , finalfilteredfilename,dateType );
                }   

1 个答案:

答案 0 :(得分:1)

如果brokerInvoiceBrokerInvoice的对象。然后,您需要将该对象添加到brokerInvoiceList。最后,此列表将包含所有选项卡对象:

    List<BrokerInvoice> brokerInvoiceList = new ArrayList<BrokerInvoice>();
        for (int i = 0; i < workbookXls.getNumberOfSheets(); i++) {
           List<BrokerInvoiceLineItem> brokerInvoiceLineItemList = new ArrayList<BrokerInvoiceLineItem>();                  
brokerInvoice = readinginvoiceimpl.findHeaderRowNumber(workbookXls, 0, brokerInvoiceLineItemList, brokerInvoice , brokerIdLong , finalfilteredfilename,dateType );
                             brokerInvoiceList.add(brokerInvoice );
                            }