导航:首页 > 文字图片 > java导出带富文本图片的word

java导出带富文本图片的word

发布时间:2023-09-01 15:52:50

⑴ java如何将有图片的html转为word

如果你只是想要不依赖网络的存储图片的话,可以试试把图片转base64

⑵ java中如何导出word

如果电脑里装的有WORD,可以通过JS新建一个WORD,并把页面文件拷贝进去。我这有操作Excel的,word的差不多。<input type="button" onclick="javascript:method1('tableExcel');" value="导入到EXCEL">  <SCRIPT LANGUAGE="javascript"> function method1(tableid) {//整个表格拷贝到EXCEL中  var curTbl = document.getElementById(tableid);  var oXL = new ActiveXObject("Excel.Application");  //创建AX对象excel  var oWB = oXL.Workbooks.Add();  //获取workbook对象  var oSheet = oWB.ActiveSheet;  //激活当前sheet  var sel = document.body.createTextRange();  sel.moveToElementText(curTbl);  //把表格中的内容移到TextRange中  sel.select();  //全选TextRange中内容  sel.execCommand("Copy");  //复制TextRange中内容  oSheet.Paste();  //粘贴到活动的EXCEL中  oXL.Visible = true;  //设置excel可见属性 }  function method2(tableid) //读取表格中每个单元到EXCEL中 {  var curTbl = document.getElementById(tableid);  var oXL = new ActiveXObject("Excel.Application");  //创建AX对象excel  var oWB = oXL.Workbooks.Add();  //获取workbook对象  var oSheet = oWB.ActiveSheet;  //激活当前sheet  var Lenr = curTbl.rows.length;  //取得表格行数  for (i = 0; i < Lenr; i++)  {  var Lenc = curTbl.rows(i).cells.length;  //取得每行的列数  for (j = 0; j < Lenc; j++)  {  oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;  //赋值  }  }  oXL.Visible = true;  //设置excel可见属性 }  function getXlsFromTbl(inTblId, inWindow) {  try {  var allStr = "";  var curStr = "";  //alert("getXlsFromTbl");  if (inTblId != null && inTblId != "" && inTblId != "null") {  curStr = getTblData(inTblId, inWindow);  }   if (curStr != null) {  allStr += curStr;  }  else {  alert("你要导出的表不存在!");  return;  }   var fileName = getExcelFileName();  doFileExport(fileName, allStr);  }  catch(e) {  alert("导出发生异常:" + e.name + "->" + e.description + "!");  } }  function getTblData(inTbl, inWindow) {  var rows = 0;  //alert("getTblData is " + inWindow);  var tblDocument = document;  if (!!inWindow && inWindow != "") {  if (!document.all(inWindow)) {  return null;  }  else {  tblDocument = eval(inWindow).document;  }  }   var curTbl = tblDocument.getElementById(inTbl);  var outStr = "";  if (curTbl != null) {  for (var j = 0; j < curTbl.rows.length; j++) {  //alert("j is " + j);  for (var i = 0; i < curTbl.rows[j].cells.length; i++) {  //alert("i is " + i);  if (i == 0 && rows > 0) {  outStr += " \t";  rows -= 1;  }  outStr += curTbl.rows[j].cells[i].innerText + "\t";  if (curTbl.rows[j].cells[i].colSpan > 1) {  for (var k = 0; k < curTbl.rows[j].cells[i].colSpan - 1; k++) {  outStr += " \t";  }  }  if (i == 0) {  if (rows == 0 && curTbl.rows[j].cells[i].rowSpan > 1) {  rows = curTbl.rows[j].cells[i].rowSpan - 1;  }  }  }  outStr += "\r\n";  }  }  else {  outStr = null;  alert(inTbl + "不存在!");  }  return outStr; }  function getExcelFileName() {  var d = new Date();  var curYear = d.getYear();  var curMonth = "" + (d.getMonth() + 1);  var curDate = "" + d.getDate();  var curHour = "" + d.getHours();  var curMinute = "" + d.getMinutes();  var curSecond = "" + d.getSeconds();   if (curMonth.length == 1) {  curMonth = "0" + curMonth;  }  if (curDate.length == 1) {  curDate = "0" + curDate;  }  if (curHour.length == 1) {  curHour = "0" + curHour;  }  if (curMinute.length == 1) {  curMinute = "0" + curMinute;  }  if (curSecond.length == 1) {  curSecond = "0" + curSecond;  }   var fileName = "leo_zhang" + "_" + curYear + curMonth + curDate + "_" + curHour + curMinute + curSecond + ".csv";  //alert(fileName);  return fileName; }  function doFileExport(inName, inStr) {  var xlsWin = null;  if (!!document.all("glbHideFrm")) {  xlsWin = glbHideFrm;  }  else {  var width = 6;  var height = 4;  var openPara = "left=" + (window.screen.width / 2 - width / 2)  + ",top=" + (window.screen.height / 2 - height / 2)  + ",scrollbars=no,width=" + width + ",height=" + height;  xlsWin = window.open("", "_blank", openPara);  }   xlsWin.document.write(inStr);  xlsWin.document.close();  xlsWin.document.execCommand('Saveas', true, inName);  xlsWin.close(); }  </SCRIPT>]

⑶ java freemarker引擎 导出word文档

要生成的数据,在java后台必须是用Map格式,这个你检查一下有没有问题。如果有list,也要放到map里面去。

HashMap<String,Object>dataMap=newHashMap<String,Object>();
Configurationconf=newConfiguration();
Templatet=conf.getTemplate(fileName);
FiledocFile=newFile(filePath+"/"+docName);
out=newOutputStreamWriter(newFileOutputStream(docFile),"UTF-8");
t.process(dataMap,out);

⑷ 请问下java中导出图片怎么

package com.xolt;
import java.io.FileOutputStream;
import java.io.File;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.awt.image.BufferedImage;
import javax.imageio.*;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;;

public class TestPOI {

public static void main(String[] args) {
FileOutputStream fileOut = null;
BufferedImage bufferImg =null;
BufferedImage bufferImg1 = null;
try{

//先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
bufferImg = ImageIO.read(new File("C:/Documents and Settings/dingqi/Desktop/clip_image002.jpg"));
bufferImg1 = ImageIO.read(new File("C:/Documents and Settings/dingqi/Desktop/clip_image002.jpg"));
ImageIO.write(bufferImg,"jpg",byteArrayOut);
ImageIO.write(bufferImg1,"jpg",byteArrayOut1);

//创建一个工作薄
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet1 = wb.createSheet("poi picT");
//HSSFRow row = sheet1.createRow(2);
HSSFPatriarch patriarch = sheet1.createDrawingPatriarch();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,512,255,(short) 1,1,(short)10,20);
HSSFClientAnchor anchor1 = new HSSFClientAnchor(0,0,512,255,(short) 2,30,(short)10,60);
anchor1.setAnchorType(2);
//插入图片
patriarch.createPicture(anchor , wb.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
patriarch.createPicture(anchor1 , wb.addPicture(byteArrayOut1.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));

fileOut = new FileOutputStream("c:/workbook.xls");
//写入excel文件
wb.write(fileOut);
fileOut.close();

}catch(IOException io){
io.printStackTrace();
System.out.println("io erorr : "+ io.getMessage());
} finally
{
if (fileOut != null)
{

try {
fileOut.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}

poi中图片到到excel的方法 你需要准备poi包 试试看看

⑸ java 如何将html(包含表格,图片)转换为word

你用IE浏览器打开你的HTML文件,然后点击菜单栏 文件→使用 Microsoft Office Word 编辑,之后系统会自动打开 Word 并显示HTML文件的内容,这是保存即可。

如果找不到“使用 Microsoft Office Word 编辑”的话,点击菜单栏 工具→Internet 选项→程序→ HTML 编辑器 → Microsoft Office Word → 确定。

⑹ 用java怎么将word文档转成图片格式

可以使用Spire.Doc for Java在Java中利用代码进行转换。需要在 Java 程序中添加Free Spire.Doc.jar文件作为依赖项。可以从这个链接下载 JAR 文件;如果使用Maven,则可以通过在 pom.xml 文件中添加以下代码导入 JAR 文件。

repositories>
<repository>
<id>com.e-iceblue</id>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository></repositories><dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>5.2.3</version>
</dependency></dependencies>

Java代码如下:

import com.spire.doc.Document;

import com.spire.doc.FileFormat;

import com.spire.doc.documents.ImageType;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

public class ConvertWordToOtherFormats {

public static void main(String[] args) throws IOException {

//创建Document对象
Document doc = new Document();

//加载Word文档
doc.loadFromFile("C:\Users\Administrator\Desktop\sample.docx");

//将指定页保存为BufferedImage
BufferedImage image= doc.saveToImages(0, ImageType.Bitmap);

//将图片数据保存为PNG格式文档
File file= new File("output/ToPNG.png");
ImageIO.write(image, "PNG", file);

//将Word保存为SVG格式
doc.saveToFile("output/ToSVG.svg",FileFormat.SVG);

//将Word保存为RTF格式
doc.saveToFile("output/ToRTF.rtf",FileFormat.Rtf);

//将Word保存为XPS格式
doc.saveToFile("output/ToXPS.xps",FileFormat.XPS);

//将Word保存为XML格式
doc.saveToFile("output/ToXML.xml",FileFormat.Xml);

//将Word保存为TXT格式
doc.saveToFile("output/ToTXT.txt",FileFormat.Txt);
}

}

阅读全文

与java导出带富文本图片的word相关的资料

热点内容
爱心可爱图片头像 浏览:625
正常男生侧颜图片 浏览:382
毛线勾小女孩衣服图片 浏览:31
男士树枝衣服搭配图片 浏览:946
图片大全唯美我恨自己的文字 浏览:237
热量高的男生烫发发型图片 浏览:285
电脑邮件图片怎么发送 浏览:317
文字图片备忘录图片 浏览:792
警察执行任务高清图片 浏览:399
女仆动漫图片 浏览:965
2021年女士短发发型图片帅气 浏览:597
人间太热可爱图片 浏览:73
满塘睡莲高清图片 浏览:190
儿童手工可爱图片大全 浏览:667
班组长文字图片 浏览:999
柔胸图片动漫 浏览:862
一个在地上趴着玩儿的小女孩图片 浏览:134
如何把文字压在图片上 浏览:497
简单的葫芦烙画100种图片 浏览:971
贵气的男生图片 浏览:308