for (int i = 0; i < list.size(); i++) {
Map
SmLiuliangjiLx item = list.get(i);
if(item.getLxCd().equals(ywXunJian.get(“lljLxCd”))){
map.put(“lxCd”,ExportWordUtil.createCheckBoxTextRenderData(1));
}else{
map.put(“lxCd”,ExportWordUtil.createCheckBoxTextRenderData(0));
}
//每3个节点换行,加入\n,最后一行不加
map.put(“lxNm”,Texts.of(item.getLxNm() + ((i + 1) % 3 == 0 && i != list.size() - 1 ? “\n” : “ “) ).fontFamily(“仿宋”).create());
listMap.add(map);
}
List
List
int columnCount = 3; //几列
int tableWidth = 13; //表格宽度
double[] arrColumnWidth = new double[columnCount]; //每列宽度
for(int i = 0 ;i < arrColumnWidth.length;i++ ){
arrColumnWidth[i] = tableWidth * 1.0 / columnCount;
}
List
for (int i = 0; i < list.size(); i++) {
SmLiuliangjiLx item = list.get(i);
ParagraphRenderData paragraph = new ParagraphRenderData();
if (item.getLxCd().equals(ywXunJian.get(“lljLxCd”))) {
paragraph.addText(ExportWordUtil.createCheckBoxTextRenderData(1));
paragraph.addText(Texts.of(item.getLxNm()).fontFamily(“仿宋”).create());
listCell.add(Cells.of().create().addParagraph(paragraph));
} else {
paragraph.addText(ExportWordUtil.createCheckBoxTextRenderData(0));
paragraph.addText(Texts.of(item.getLxNm()).fontFamily(“仿宋”).create());
listCell.add(Cells.of().create().addParagraph(paragraph));
}
//每columnCount 个cell 加入1行,并清除listCell
if ((i + 1) % columnCount == 0) {
listRow.add(Rows.of(listCell.toArray(new CellRenderData[listCell.size()])).create());
listCell = new ArrayList();
}
}
if (listCell.size() > 0) {
//如果 listCell有剩余 ,补齐剩余的单元格
if (listCell.size() < columnCount) {
for (int i = 0; i < columnCount - listCell.size(); i++) {
listCell.add(Cells.of(“”).create());
}
}
listRow.add(Rows.of(listCell.toArray(new CellRenderData[listCell.size()])).create());
}
//=============list中的数据可能不全部生成=============按下面的
/*
@author: qzf
@date: 2022/2/14 10:01
@describe: list转为图片table TableRenderData
@param: list 列表 tableWidth 表格宽度 columnCount 列数 relativePicPathKey 图片相对路径 picDescKey 图片描述
@return:
/
public static TableRenderData listToTableRenderDataForPic(List 1.0 / columnCount;
}
for (int i = 0; i < list.size(); i++) {
map = list.get(i);
ParagraphRenderData paragraph = new ParagraphRenderData();
if(!StringUtil.isEmpty(map.get(picDescKey))){
paragraph.addText(map.get(picDescKey).toString()+”\n”);
}
String fileName = ApplicationConfig.uploadPath + map.get(relativePicPathKey);
if(new File(fileName).exists() && !StringUtil.isEmpty(map.get(relativePicPathKey))) {
paragraph.addPicture((Pictures.ofLocal(fileName)).size(picWidth, picHeight).create());
listCell.add(Cells.of().create().addParagraph(paragraph));
if (listCell.size() % columnCount == 0) { //或者 listCell.size() == columnCount<br /> listRow.add(Rows.of(listCell.toArray(new CellRenderData[listCell.size()])).create());<br /> listCell = new ArrayList();<br /> }<br /> }<br /> }<br /> if (listCell.size() > 0) {<br /> //补齐剩余的单元格<br /> int listCellSize = listCell.size();<br />if (listCellSize < columnCount) {<br /> for (int i = 0; i < columnCount - listCellSize; i++) {<br /> listCell.add(Cells.of("").create());<br /> }<br />}<br /> listRow.add(Rows.of(listCell.toArray(new CellRenderData[listCell.size()])).create());<br /> }<br /> return Tables.of(listRow.toArray(new RowRenderData[listRow.size()])).border(new BorderStyle(){{setSize(0);}}).width(tableWidth, arrColumnWidth).create();<br /> }