NPOI 向WORD2007插入图片

oreoconansisu 2013-05-21 11:13:07
NPOI的下载实例中没有涉及WORD2007插入图片的功能

我试过读取图片可以

但是插入图片有问题

打开WORD2007会显示错误,错误信息如下



请教各位,如何解决
...全文
738 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
gltide 2014-03-17
  • 打赏
  • 举报
回复
参看http://blog.csdn.net/gltide/article/details/21191357
x-code-man 2013-09-03
  • 打赏
  • 举报
回复
引用 11 楼 oYongYuanYou 的回复:
有能解决这个问题么? 我也遇到同样的问题 我找到了可以在新页面插入图片的方式 但是在特定位置插入还是不会
贴个代码看看
oYongYuanYou 2013-07-18
  • 打赏
  • 举报
回复
我稍微重写了addPicture方法, 可以在指定的地方插入图片了 我刚测试过 希望对你有用: public void addPictureNew(InputStream pictureData, int pictureType, String filename, int width, int height) throws InvalidFormatException, IOException { XWPFDocument doc = paragraph.document; String relationId = doc.addPictureData(pictureData, pictureType); final int EMU = 9525; width *= EMU; height *= EMU; String blipId = "1"; CTInline inline = paragraph.createRun().getCTR() .addNewDrawing().addNewInline(); paragraph.createRun().setText(""); String picXml = "" + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + " <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:nvPicPr>" + " <pic:cNvPr id=\"" + 0 + "\" name=\"Generated\"/>" + " <pic:cNvPicPr/>" + " </pic:nvPicPr>" + " <pic:blipFill>" + " <a:blip r:embed=\"" + relationId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" + " <a:stretch>" + " <a:fillRect/>" + " </a:stretch>" + " </pic:blipFill>" + " <pic:spPr>" + " <a:xfrm>" + " <a:off x=\"0\" y=\"0\"/>" + " <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + " </a:xfrm>" + " <a:prstGeom prst=\"rect\">" + " <a:avLst/>" + " </a:prstGeom>" + " </pic:spPr>" + " </pic:pic>" + " </a:graphicData>" + "</a:graphic>"; // CTGraphicalObjectData graphicData = inline.addNewGraphic().addNewGraphicData(); XmlToken xmlToken = null; try { xmlToken = XmlToken.Factory.parse(picXml); } catch (XmlException xe) { xe.printStackTrace(); } inline.set(xmlToken); // graphicData.set(xmlToken); inline.setDistT(0); inline.setDistB(0); inline.setDistL(0); inline.setDistR(0); CTPositiveSize2D extent = inline.addNewExtent(); extent.setCx(width); extent.setCy(height); CTNonVisualDrawingProps docPr = inline.addNewDocPr(); docPr.setId(pictureType); docPr.setName("图片" + pictureType); docPr.setDescr(""); }
oYongYuanYou 2013-07-18
  • 打赏
  • 举报
回复
有能解决这个问题么? 我也遇到同样的问题 我找到了可以在新页面插入图片的方式 但是在特定位置插入还是不会
YuFS 2013-06-07
  • 打赏
  • 举报
回复
Aspose.Words 生成word方法http://www.cnblogs.com/rhythmK/archive/2011/12/05/2276651.html dll这个链接也有附件6.05版本的,可以生成word2003
YuFS 2013-06-06
  • 打赏
  • 举报
回复
引用 8 楼 oreoconansisu 的回复:
[quote=引用 7 楼 yfs2468 的回复:] 亲,NPOI插入图片你实现了吗,我现在也遇到这样问题了。
木有[/quote] 加关注吧,我已经加你了,可以相互讨论学习哦
oreoconansisu 2013-06-06
  • 打赏
  • 举报
回复
引用 7 楼 yfs2468 的回复:
亲,NPOI插入图片你实现了吗,我现在也遇到这样问题了。
木有
YuFS 2013-06-04
  • 打赏
  • 举报
回复
亲,NPOI插入图片你实现了吗,我现在也遇到这样问题了。
  • 打赏
  • 举报
回复
npoi用过,貌似是和office版本有关,有兼容性问题,楼主这方面找找原因 我只搞过excel的。
oreoconansisu 2013-05-22
  • 打赏
  • 举报
回复
引用 4 楼 dr592112441 的回复:
[quote=引用 3 楼 oreoconansisu 的回复:] [quote=引用 2 楼 sj178220709 的回复:] npoi用过,貌似是和office版本有关,有兼容性问题,楼主这方面找找原因 我只搞过excel的。
对的,我以前也只搞过excel NPOI支持excel2003/2007 对word只支持2007且并不稳定 [/quote] 用最低兼容版本[/quote] 比如?
Mirror然 2013-05-22
  • 打赏
  • 举报
回复
引用 3 楼 oreoconansisu 的回复:
[quote=引用 2 楼 sj178220709 的回复:] npoi用过,貌似是和office版本有关,有兼容性问题,楼主这方面找找原因 我只搞过excel的。
对的,我以前也只搞过excel NPOI支持excel2003/2007 对word只支持2007且并不稳定 [/quote] 用最低兼容版本
oreoconansisu 2013-05-22
  • 打赏
  • 举报
回复
引用 2 楼 sj178220709 的回复:
npoi用过,貌似是和office版本有关,有兼容性问题,楼主这方面找找原因 我只搞过excel的。
对的,我以前也只搞过excel NPOI支持excel2003/2007 对word只支持2007且并不稳定
oreoconansisu 2013-05-22
  • 打赏
  • 举报
回复
自顶自顶自顶
oreoconansisu 2013-05-21
  • 打赏
  • 举报
回复
插入图片使用的方法是 XWPFRun的AddPicture方法

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧