求助!将图片插入到word文件,用JAVA语言或者JS该怎么操作?

闭目鱼 2011-06-14 08:35:49
如题,在数据库中,图片文件的数据有两种形式。第一种存为一个image字段类型,另一种是存放图片的路径。
现业务需要,将图片以及页面的其他内容导出到word文件里特定的位置,页面内容已经通过代码实现,但现在图片不知如何处理。请有经验的朋友帮帮忙,谢谢!
...全文
961 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
shgogoii 2011-10-17
  • 打赏
  • 举报
回复
顶一下
aadfadsfadsfa 2011-06-16
  • 打赏
  • 举报
回复
用控件做也行,目前就是在搞这屁玩意,蛋疼死了
用js做也行,只要是用js能取得活动文档对象,再调用接口往文档中插入图片,这是本地的做法
如果不想这么麻烦,可以去购买在线编辑控件,如金格控件,用法很简单的
KingViker 2011-06-16
  • 打赏
  • 举报
回复
路过 学习一下
gy19890220 2011-06-16
  • 打赏
  • 举报
回复
路过 学习一下
tonglane11 2011-06-16
  • 打赏
  • 举报
回复
学习中~~~~
UPC_思念 2011-06-15
  • 打赏
  • 举报
回复
可以使用itext来搞

import java.awt.Color;
import java.io.FileOutputStream;
import java.util.Date;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.style.RtfFont;
public class CreateWord {
public static void main(String[] args) throws Exception {
/** 创建Document对象(word文档) author:yyli Sep 15, 2010 */
Rectangle rectPageSize = new Rectangle(PageSize.A4);
rectPageSize = rectPageSize.rotate();
// 创建word文档,并设置纸张的大小
Document doc = new Document(PageSize.A4);
String fileName="E:/企业详细信息登记表_"+System.currentTimeMillis()+".doc";
/** 建立一个书写器与document对象关联,通过书写器可以将文档写入到输出流中 author:yyli Sep 15, 2010 */
RtfWriter2.getInstance(doc, new FileOutputStream(fileName));
doc.open();
/** 标题字体 author:yyli Sep 15, 2010 */
RtfFont titleFont = new RtfFont("仿宋_GB2312", 15, Font.BOLD,
Color.BLACK);
/** 正文字体 author:yyli Sep 15, 2010 */
RtfFont contextFont = new RtfFont("仿宋_GB2312", 9, Font.NORMAL,
Color.BLACK);
/** 表格设置 author:yyli Sep 15, 2010 */
Table table = new Table(4, 3);
int[] withs = { 15, 35, 15, 35};
/** 设置每列所占比例 author:yyli Sep 15, 2010 */
table.setWidths(withs);
/** 表格所占页面宽度 author:yyli Sep 15, 2010 */
table.setWidth(100);
/** 居中显示 author:yyli Sep 15, 2010 */
table.setAlignment(Element.ALIGN_CENTER);
/** 自动填满 author:yyli Sep 15, 2010 */
table.setAutoFillEmptyCells(true);
table.setBorderWidth(5); // 边框宽度
table.setBorderColor(new Color(0, 125, 255)); // 边框颜色
table.setPadding(12);// 衬距,看效果就知道什么意思了
table.setSpacing(0);// 即单元格之间的间距
table.setBorder(5);// 边框
/** 第一行(标题) author:yyli Sep 15, 2010 */
String titleString = "企业详细信息登记表";
Paragraph title = new Paragraph(titleString);
// 设置标题格式对其方式
title.setAlignment(Element.ALIGN_CENTER);
title.setFont(titleFont);
doc.add(title);
/** 第二行(正文) author:yyli Sep 15, 2010 */
String contextString = "登记人:"+"admin "+"登记时间:"+new Date().toLocaleString();
Paragraph context = new Paragraph(contextString);
// 正文格式对齐方式
context.setAlignment(Element.ALIGN_RIGHT);
context.setFont(contextFont);
// 与上一段落(标题)的行距
context.setSpacingBefore(10);
// 设置第一行空的列数(缩进)
// context.setFirstLineIndent(20);
doc.add(context);
Cell cell=null;
cell=new Cell("企业名称:");
cell.setHeader(true);
cell.setVerticalAlignment(Element.ALIGN_CENTER);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);

table.addCell(cell);
cell=new Cell("中国安芯");
cell.setColspan(3);
cell.setVerticalAlignment(Element.ALIGN_CENTER);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);

cell=new Cell("企业地址:");
cell.setVerticalAlignment(Element.ALIGN_CENTER);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);

cell=new Cell("淮安市洪泽县");
cell.setVerticalAlignment(Element.ALIGN_CENTER);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);

cell=new Cell("企业代码:");
cell.setVerticalAlignment(Element.ALIGN_CENTER);
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);

cell=new Cell("zxc797ddd797979");
cell.setVerticalAlignment(Element.ALIGN_CENTER);
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);

doc.add(table);
//在表格末尾添加图片
Image png = Image.getInstance("E:/baby.jpg");
doc.add(png);
doc.close();
}
}

24K純帥 2011-06-15
  • 打赏
  • 举报
回复
没做过,是不是用POI解析后在需要的位置插入图片啊
liufeng0209 2011-06-15
  • 打赏
  • 举报
回复
itext可以导出word,有个Image类可以将图片插入到word中的相应位置.
angel 2011-06-14
  • 打赏
  • 举报
回复
可以试试导出成word,我以前只是做过ireport的导出,可以将页面内容导出成word。直接插入到word,这个还真不知道。
闭目鱼 2011-06-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 peng_hao1988 的回复:]
还挺难的,个人认为图片也是一种文件,应该要调word用插入文件的接口才行,这样估计也只能插入到末尾,要想插入到指定位置估计有难度。期待高手解答.....
[/Quote]

文字内容,我通过word的域对象,与页面相应信息一一绑定导过去的
但word域对象没有图片类型的属性
桃园闲人 2011-06-14
  • 打赏
  • 举报
回复
还挺难的,个人认为图片也是一种文件,应该要调word用插入文件的接口才行,这样估计也只能插入到末尾,要想插入到指定位置估计有难度。期待高手解答.....

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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