使用过的版本
兴趣点:3.15
jxls:2.4.0
jxls-poi:1.0.12
这是一个template允许简单地重现问题。
请注意,我正在使用 JXLS 的多页功能。
当if-condition为真(站点有地址)时,结果将按预期显示
但是当它为 false 并且没有显示地址时,我会丢失 2 行,即第 7 行和第 8 行,并由空白行替换。
result
有人已经遇到过这样的问题吗? 我使用 JXLS 创建工作表的方式是否犯了错误?
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();
}
}
问候,
最佳答案
该问题现已修复,该修复将在下一个 Jxls 版本 v2.4.1 中进行。
参见issue#77 JXLS Losing rows when using if-command inside each-command了解更多详情。
关于java - JXLS 在每个命令中使用 if 命令时丢失行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44288618/