poi-tl
poi-tl copied to clipboard
插入excel附件之图标异常
相同的数据,在服务器上导出word时,第一次下载的excel附件图标是正常的,见图1;第二次图标就变形了,见图2
图1
图2
目前发现这个问题出现的版本1.11.1 1.12.0
使用wps打开不会出现图标异常,用word打开才出现这个异常
在本地调试的时候也出现了图标异常问题,之前使用1.10.2的时候,图标异常会出现在服务器端,本地不会出现
@PhotonIV 你代码AttachmentRenderData指定一个图片试试?
@Sayi 好的 我试试
@Sayi 自定义图片效果一样,第一次下载正常,第二次图标就不正常了,本地环境和服务器环境都是。
刚刚尝试的版本是1.11.1
你好sayi,在引用了1.12.0的包后,PictureRenderData改成了抽象类,本来想在1.12.0自定义图标,但是抽象类没法实例化
你把图标不正常的word发我邮箱下。
1.12.0使用具体的类实例化或者使用Pictures构造器:http://deepoove.com/poi-tl/#_%E5%9B%BE%E7%89%87
public void downloadReport1( HttpServletResponse response) throws IOException { Configure config = Configure.builder().bind("annex", new AttachmentRenderPolicy()).build(); Map<String, Object> map = new HashMap<String, Object>(); String file = "template/test.xlsx"; AttachmentRenderData attachmentRenderData = Attachments.ofLocal(file, AttachmentType.XLSX).create(); map.put("annex", attachmentRenderData); XWPFTemplate template = XWPFTemplate.compile("template/test.docx", config).render(map); response.setContentType("application/force-download"); response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("test.docx", "UTF-8")); template.writeAndClose(response.getOutputStream()); }
刘灶新 @.***
------------------ 原始邮件 ------------------ 发件人: "Sayi/poi-tl" @.>; 发送时间: 2022年5月9日(星期一) 中午12:00 @.>; @.@.>; 主题: Re: [Sayi/poi-tl] 插入excel附件之图标异常 (Issue #785)
你把图标不正常的word发我邮箱下。
1.12.0使用具体的类实例化或者使用Pictures构造器:http://deepoove.com/poi-tl/#_%E5%9B%BE%E7%89%87
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
你好sayi,我分析了一下word的xml,发现正常的word的xml如下
异常的wordxml如下:
看上去是shapeId的问题,所以我重写了attrachmentRenderPolicy
这是原来的代码:
现在我把判断去掉了,当然这样可能会引起多sheet的excel打印异常,不过我这里是单sheet的,所以我就暂时这样处理了
最后测试了一下,每次打印的图标都是正常的
按照上面的方法重写AttachmentRenderPolicy的doRender方法,还是会出现下面的问题:
word文档中插入两个附件:word附件和Excel附件
打开xlsx附件之前
打开xlsx附件之后,Excel附件图标变小