I make a custom jx:each-merge
command to do the auto merge things. But need to pay attention that I am using org.jxls:jxls:2.4.2
, org.jxls:jxls-poi:1.0.13
and having a main-sub data structure (means the data has been grouped by before).
You can see the template and the rendered result from the bellow picture:
code example:
public void xls() throws Exception {
// from template
InputStream template = getClass().getClassLoader().getResourceAsStream("templates/each-merge.xls");
// output to
File out = new File("target/each-merge-result.xls");
if (out.exists()) out.delete();
OutputStream output = new FileOutputStream(out);
// template data
Map<String, Object> data = generateData();
// render
JxlsUtils.renderTemplate(template, data, output);
// verify
assertThat(out.exists(), is(true));
assertThat(out.getTotalSpace() > 0, is(true));
}
You can get the source code from the github project simter-jxls-ext. The test class is EachMergeCommandTest.java.
The data structure is:
[
{
sn: 1,
name: 'row1',
subs: [
{sn: '1-1', name: 'row1sub1'},
...
]
},
...
]
Hope this is helpful.