easyexcel icon indicating copy to clipboard operation
easyexcel copied to clipboard

使用fill填充数据,再填充图片时,除了头只有顶部的可以显示图片,其他位置的行就显示空白了,怎么回事(注:一个sheet多个维度的填充)

Open sghgithua opened this issue 1 year ago • 5 comments

sghgithua avatar Sep 03 '24 07:09 sghgithua

public void doExport(ExcelWriter excelWriter, AllDimExportExcelVO exportVO, String sheet) {
        if (exportVO == null) {
            return;
        }
        WriteSheet writeSheet = EasyExcel.writerSheet().sheetName(sheet).build();
        if (exportVO.getData() != null) {
            JSONObject obj = fixFieldName(exportVO.getDimKey(), exportVO.getData());
            excelWriter.fill(obj, writeSheet);
        }
        if (MapUtils.isNotEmpty(exportVO.getHorizontalListMap())) {
            exportVO.getHorizontalListMap().forEach((key, value) -> {
                excelWriter.fill(new FillWrapper(genListKey(exportVO.getDimKey(), key), value), HORIZONTAL, writeSheet);
            });
        }
        if (MapUtils.isNotEmpty(exportVO.getVerticalListMap())) {
            exportVO.getVerticalListMap().forEach((key, value) -> {
                if (exportVO.getDimKey().equals(CompanyExportDimEnum.TM.getDimKey())) {
                    dimExportGenerateExcel.imageCells(value);
                }
                if (exportVO.getDimKey().equals(CompanyExportDimEnum.PAST_TM.getDimKey())) {
                    dimExportGenerateExcel.imageCells(value);
                }
                excelWriter.fill(new FillWrapper(genListKey(exportVO.getDimKey(), key), value), VERTICAL, writeSheet);
            });
        }
    }

public void imageCells(List<JSONObject> jsonObjects) {
        if (CollectionUtils.isEmpty(jsonObjects)) {
            return;
        }

        for (JSONObject jsonObject : jsonObjects) {
            WriteCellData<Void> writeCellData = new WriteCellData<>();
            List<ImageData> imageDataList = new ArrayList<>();
            String tmPic = jsonObject.getString("tmPic");
            if (StringUtils.isEmpty(tmPic)) {
                continue;
            }
            ImageData imageData = new ImageData();
            byte[] bytes = getPicBytes(tmPic);
            if (bytes == null) {
                jsonObject.put("tmPic", "-");
                continue;
            }
            imageData.setImage(bytes);

            imageData.setTop(1);
            imageData.setRight(1);
            imageData.setBottom(1);
            imageData.setLeft(1);

            imageData.setRelativeFirstRowIndex(0);
            imageData.setRelativeFirstColumnIndex(0);
            imageData.setRelativeLastRowIndex(0);
            imageData.setRelativeLastColumnIndex(0);
            imageDataList.add(imageData);
            writeCellData.setImageDataList(imageDataList);
            jsonObject.put("tmPic", writeCellData);
        }
    }
    
    
![image](https://github.com/user-attachments/assets/ba86facb-9623-4384-8659-c61380772c49)
![image](https://github.com/user-attachments/assets/f3a4bada-c238-4a75-bd08-4eece69027c0)

sghgithua avatar Sep 03 '24 07:09 sghgithua

image

sghgithua avatar Sep 03 '24 07:09 sghgithua

image

sghgithua avatar Sep 03 '24 07:09 sghgithua

我把下面这几行代码去掉后,图片能出来,但是这个图片把别的维度数据覆盖了 imageData.setRelativeFirstRowIndex(0); imageData.setRelativeFirstColumnIndex(0); imageData.setRelativeLastRowIndex(0); imageData.setRelativeLastColumnIndex(0); image

sghgithua avatar Sep 03 '24 09:09 sghgithua

public void doExport(ExcelWriter excelWriter, AllDimExportExcelVO exportVO, String sheet) {
        if (exportVO == null) {
            return;
        }
        WriteSheet writeSheet = EasyExcel.writerSheet().sheetName(sheet).build();
        if (exportVO.getData() != null) {
            JSONObject obj = fixFieldName(exportVO.getDimKey(), exportVO.getData());
            excelWriter.fill(obj, writeSheet);
        }
        if (MapUtils.isNotEmpty(exportVO.getHorizontalListMap())) {
            exportVO.getHorizontalListMap().forEach((key, value) -> {
                excelWriter.fill(new FillWrapper(genListKey(exportVO.getDimKey(), key), value), HORIZONTAL, writeSheet);
            });
        }
        if (MapUtils.isNotEmpty(exportVO.getVerticalListMap())) {
            exportVO.getVerticalListMap().forEach((key, value) -> {
                if (exportVO.getDimKey().equals(CompanyExportDimEnum.TM.getDimKey())) {
                    dimExportGenerateExcel.imageCells(value);
                }
                if (exportVO.getDimKey().equals(CompanyExportDimEnum.PAST_TM.getDimKey())) {
                    dimExportGenerateExcel.imageCells(value);
                }
                excelWriter.fill(new FillWrapper(genListKey(exportVO.getDimKey(), key), value), VERTICAL, writeSheet);
            });
        }
    }

public void imageCells(List<JSONObject> jsonObjects) {
        if (CollectionUtils.isEmpty(jsonObjects)) {
            return;
        }

        for (JSONObject jsonObject : jsonObjects) {
            WriteCellData<Void> writeCellData = new WriteCellData<>();
            List<ImageData> imageDataList = new ArrayList<>();
            String tmPic = jsonObject.getString("tmPic");
            if (StringUtils.isEmpty(tmPic)) {
                continue;
            }
            ImageData imageData = new ImageData();
            byte[] bytes = getPicBytes(tmPic);
            if (bytes == null) {
                jsonObject.put("tmPic", "-");
                continue;
            }
            imageData.setImage(bytes);

            imageData.setTop(1);
            imageData.setRight(1);
            imageData.setBottom(1);
            imageData.setLeft(1);

            imageData.setRelativeFirstRowIndex(0);
            imageData.setRelativeFirstColumnIndex(0);
            imageData.setRelativeLastRowIndex(0);
            imageData.setRelativeLastColumnIndex(0);
            imageDataList.add(imageData);
            writeCellData.setImageDataList(imageDataList);
            jsonObject.put("tmPic", writeCellData);
        }
    }
    
    
![image](https://github.com/user-attachments/assets/ba86facb-9623-4384-8659-c61380772c49)
![image](https://github.com/user-attachments/assets/f3a4bada-c238-4a75-bd08-4eece69027c0)

@sghgithua 我也遇到这个问题了,我是在{.list}列表后面还有行数据需要填充,结果{.list}填充后直接将后面需要填充的行数据给覆盖了 ,博主解决了吗

husen5323 avatar Oct 01 '24 15:10 husen5323