我陷入一个问题,就是我有以下一段代码,其中我读取了多个excel选项卡工作表并将工作表值存储在名为brokerInvoice对象的对象中
如果我有如下所示的单个选项卡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 );
}
最佳答案
如果brokerInvoice
是BrokerInvoice
的对象。然后,您需要将该对象添加到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 );
}
关于java - 用Java中的每个条件独立执行for循环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35607612/