您可以使用循环将每个图片链接放在一个单独的单元格中。以下是修改后的代码示例:

JSONObject json = new JSONObject(jsonstr);
JSONArray data = json.getJSONArray("data");
int length = data.length();
String allImageUrls = "";

for (int i = 0; i < length; i++) {
    r = sheet.createRow(i + rowcount);
    r.setHeight((short) (256 * 2));

    int cellNum = 0;
    JSONObject temp = new JSONObject(data.optString(i));
    for (cellNum = 0; cellNum < displayKeys.length + 5; cellNum++) {
        if (cellNum >= dataKeys.length) {
            break;
        }
        String value = temp.optString(dataKeys[cellNum]);

        if (dataKeys[cellNum].equals("images")) {
            JSONArray images = temp.optJSONArray("images");
            if ((images != null)&&(cellNum<(displayKeys.length+images.length()-1))) {
                for (int j = 0; j < images.length(); j++) {
                    String imageUrl = images.optString(j) + "?imageMogr2/thumbnail/!20p";
                    String imageHyperLinkString = "=HYPERLINK(\"" + imageUrl + "\")";
                    System.out.println(imageUrl);
                    System.out.println(imageHyperLinkString);
                    CellUtil.createCell(r, cellNum + j, imageHyperLinkString);
                    // 将imageUrl添加到allImageUrls中
                    allImageUrls += imageUrl + "\n";
                }
            }
        } else {
            CellUtil.createCell(r, cellNum, value);
        }
    }
}

在上述代码中,通过在循环中使用CellUtil.createCell(r, cellNum + j, imageHyperLinkString);,将每个图片链接放在一个单独的单元格中。您可以根据需要进行调整

JSONObject json = new JSONObjectjsonstr;			Systemoutprintlnjson;			JSONArray data = jsongetJSONArraydata;			int length = datalength;			String allImageUrls = ;									for int i = 0; i length; i++

原文地址: http://www.cveoy.top/t/topic/iZoH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录