Мне нужна помощь с использованием jxls-reader (http://jxls.sourceforge.net/reference/reader.html).
Мне удобно зацикливать лист, где одна строка представляет конкретный объект Java, но в случае вложенных циклов я в тупике.
Мне нужно сопоставить приведенный выше лист Excel со следующим pojo:
class Student {
private String name;
private String dob;
private List<Class> class;
//getters & setters
}
class Class {
private String name;
private String link;
//getters & setters
}
Моя проблема заключается в определении условия взлома для чтения внутреннего объекта. Обратите внимание, что условие прерывания цикла для объекта Class требует чего-то вроде следующих:
- Первая ячейка следующей строки не пуста ИЛИ
- Первая ячейка следующей строки пуста И следующая ячейка текущего столбца пуста (для разрыва последней строки)
Как выразить указанное выше логическое условие в условии прерывания цикла. У меня есть следующее, но я знаю, что это неправильно:
<workbook>
<worksheet name="Students">
<section startRow="0" endRow="0">
<!--Empty Header Section-->
</section>
<loop startRow="1" endRow="1" items="students" var="student" varType="com.test.Student">
<section startRow="1" endRow="1">
<mapping row="1" col="0">student.name</mapping>
<mapping row="1" col="1">student.dob</mapping>
</section>
<loopbreakcondition>
<rowcheck offset="0">
<cellcheck offset="0"> <!--Breaks on next empty cell--></cellcheck>
</rowcheck>
</loopbreakcondition>
<loop startRow="1" endRow="1" items="student.class" var="class" varType="com.test.Class">
<section startRow="1" endRow="1">
<mapping row="1" col="2">class.name</mapping>
<mapping row="1" col="3">class.link</mapping>
</section>
<loopbreakcondition>
<rowcheck offset="0">
<cellcheck offset="0"> </cellcheck>
</rowcheck>
</loopbreakcondition>
</loop>
</loop>
</worksheet>
</workbook>
Это вообще возможно? Есть ли другие библиотеки, которые помогут мне в этом? Или мне лучше написать свой парсер с помощью apache-poi?
Спасибо.