Reputation: 11
Used versions
poi :3.15
jxls : 2.4.0
jxls-poi : 1.0.12
Here is a template allowing a simple reproduction of the problem.
Please note that I'm using the multisheet feature of JXLS.
When the if-condition is true (the site has an address) the result is displayed as expected
but when it's false and no adress is displayed I lose 2 rows, number 7 and 8, replaced by blanks rows.
result
As anyone already encoutered such problem ? Am I making a mistake in the way I'm using JXLS to create my sheet ?
public class Test {
public static void main(String[] args) throws Exception {
String first = "Bob";
String last = "John";
String phone = "";
List<Person> personList = new ArrayList<>();
for (int i=1 ; i<10 ; i++) {
personList.add(new Person(first + i, last + i, phone + i));
}
List<Site> mySites = new ArrayList<>();
Site site = new Site("site 1", "Paris", "", "rue 1", "rue 2", personList);
mySites.add(site);
site = new Site("site 2", "", "Bob", "", "", personList);
mySites.add(site);
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
InputStream template = null;
if (contextClassLoader != null) {
template = contextClassLoader.getResourceAsStream("test1.xls");
}
OutputStream os = new BufferedOutputStream(new FileOutputStream("c:/temp/res.xls"));
org.jxls.common.Context contextData = PoiTransformer.createInitialContext();
Map<String, Object> beansData = new HashMap<>();
List<String> sheetNames = Arrays.asList("site1","site2");
beansData.put("mySites", mySites);
beansData.put("sheetNames", sheetNames);
for (Map.Entry<String, Object> entry : beansData.entrySet())
{
contextData.putVar(entry.getKey(), entry.getValue());
}
JxlsHelper.getInstance().setUseFastFormulaProcessor(false).processTemplate(template, os, contextData);
template.close();
os.flush();
os.close();
}
}
Regards,
Upvotes: 1
Views: 1821
Reputation: 1264
The issue is now fixed and the fix will go in the next Jxls release v2.4.1.
See issue#77 JXLS Losing rows when using if-command inside each-command for more detail.
Upvotes: 1