[英]how to merge cells dynamically in JXLS API in transformed template
我正在使用Jxls API
我現在可以創建,將數據列表傳遞給模板,根據需要創建excel輸出表
但現在我必須合並具有相同值的列單元格
這是重復細胞的每個標簽
<jx:forEach items="${dummyData}" var="dummy" groupBy="col1">
<jx:forEach items="${group.items}" var="myList123">
${myList123.col1} ${myList123.col2} ${myList123.col3} ${myList123.col4} ${myList123.col5} ${myList123.col6} ${myList123.col7}
</jx:forEach>
</jx:forEach>
我不確定這是否有幫助。 但這是我的想法
你可以使用sheet.addMergedRegion(rowFrom,rowTo,colFrom,colTo);
來自POI圖書館
我從未在Jxlx上工作,但看起來他們沒有這個功能。
我做了一個自定義的jx:each-merge
命令來做自動合並的事情。 但是需要注意我正在使用org.jxls:jxls:2.4.2
, org.jxls:jxls-poi:1.0.13
並且具有org.jxls:jxls-poi:1.0.13
數據結構(意味着數據已經被分組過)。 您可以從下面的圖片中看到模板和渲染結果:
代碼示例:
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));
}
您可以從github項目simter-jxls-ext獲取源代碼。 測試類是EachMergeCommandTest.java 。
數據結構是:
[
{
sn: 1,
name: 'row1',
subs: [
{sn: '1-1', name: 'row1sub1'},
...
]
},
...
]
希望這是有幫助的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.