假设存在这样一张表A (audience),观众表
id,zjhm,name,gender,address
表B(seat),座位表,表明这个观众主动坐过哪些座位
id,
表C(check),校核表,表明这个观众被系统管理人员校核过哪些座位
id
一、插入网络图片并自适应
Excel中插入图片方法
参数1: 工作薄
参数2: 工作表名
参数3: 网络图片地址
参数4: 图片插入到哪一行
参数5: 图片插入到哪一列
public static void insertImage(XSSFWorkbook workbook, String sheetName,String imageUrl,
int row,int col) {
try {
URL url = new URL(imageUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
InputStream inputStream = conn.getInputStream();
XSSFSheet sheet = workbook.getSheet(sheetName);
XSSFDrawing patriarch = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = new XSSFClientAnchor(0,0,255,255,
col,row,col+1,row+1);
// 图片自适应单元格大小
anchor.setAnchorType(AnchorType.byId(0));
patriarch.createPicture(anchor,workbook.addPicture(inputStream,XSSFWorkbook.PICTURE_TYPE_WPG));
} catch (Exception e) {
e.printStackTrace();
}
}
调用
int startRowIndex = 2;
int endRowIndex = 1;
for (Audience audience : audienceList) {
int checkSize = audience.getCheckList().size();
int seatSize = audience.getSeatList().size();
if (checkSize >= seatSize) {
endRowIndex += checkSize;
} else {
endRowIndex += seatSize;
}
for (int i = 0; i < aliPersonFace.getSeatList().size(); i++) {
AliPersonFace child = aliPersonFace.getSeatList().get(i);
ExcelUtil.insertImage(xssfWorkbook, sheetName, child.getImageUrl(), startRowIndex + i, 10);
}
startRowIndex = endRowIndex + 1;
}
待加: