jeecgboot / jeecgboot/JeecgBoot

excel模板导出图片失败

Open
#9,741 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
47.8k
Forks
16.2k
PR merge metrics
No merged PRs in 30d

Description

##### 版本号: jeecgboot.version > 3.9.1
java.version > 21
autopoi-web.version > 2.0.4
##### 分支:
main
##### 问题描述:
// 导出测试类
package org.jeecg.modules.demo.test.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecgframework.poi.entity.ImageEntity;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.def.TemplateExcelConstants;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.view.JeecgTemplateExcelView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "测试导出")
@RestController
@RequestMapping("/demo/file")
@Slf4j
public class TestController {
/**
* 导出excel
*
* @param request 请求
*/
@Operation(summary = "导出excel")
@IgnoreAuth
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request) {
// Step.3 组装单值数据
Map map = new HashMap<>();
// 1. 构建文件路径
String singPath = "D:\\work\\code\\test\\template\\sign.png";
ImageEntity image = new ImageEntity();
image.setHeight(200);
image.setWidth(500);
image.setUrl(singPath);
map.put("jyy", image);
map.put("name", "图片导出");
// Step.5 AutoPoi 导出Excel
TemplateExportParams params = new TemplateExportParams();
// 模板文件名称
String templateFileName = "test.xlsx";
log.info(templateFileName);
params.setTemplateUrl("D:\\work\\code\\test\\template\\test.xlsx");
params.setSheetName("测试导出图片");
ModelAndView mv = new ModelAndView(new JeecgTemplateExcelView());
mv.addObject(TemplateExcelConstants.PARAMS, params);
mv.addObject(TemplateExcelConstants.MAP_DATA, map);
mv.addObject(NormalExcelConstants.FILE_NAME, "测试导出图片");
return mv;
}
}

Image

[test.xlsx](https://github.com/user-attachments/files/29580971/test.xlsx)

##### 错误截图:
图片未正常导出
Image

#### 友情提示:
- 未按格式要求发帖、描述过于简单的,会被直接删掉;
- 描述问题请图文并茂,方便我们理解并快速定位问题;
- 如果使用的不是master,请说明你使用的分支;

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the TestController exportXls example and trace how JeecgTemplateExcelView, TemplateExportParams, and ImageEntity process the attached test.xlsx template and sign.png file. Reproduce the export with the shown Java 21 and AutoPoi versions, then verify that the image appears correctly in the generated workbook.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.