導航:首頁 > 文字圖片 > java導出word圖片格式

java導出word圖片格式

發布時間:2023-03-22 14:25:36

A. 怎麼用java導出word文檔

java導出word大致有6種解決方案:
1:Jacob是Java-COM Bridge的縮寫,它在Java與微軟的COM組件之間構建一座橋梁。使用Jacob自帶的DLL動態鏈接庫,並通過JNI的方式實現了在Java平台上對COM程序的調用。DLL動態鏈接庫的生成需要windows平台的支持。該方案只能在windows平台實現,是其局限性。
2:Apache POI包括一系列的API,它們可以操作基於MicroSoft OLE 2 Compound Document Format的各種格式文件,可以通過這些API在Java中讀寫Excel、Word等文件。他的excel處理很強大,對於word還局限於讀取,目前只能實現一些簡單文件的操作,不能設置樣式。
3:Java2word是一個在java程序中調用 MS Office Word 文檔的組件(類庫)。該組件提供了一組簡單的介面,以便java程序調用他的服務操作Word 文檔。 這些服務包括: 打開文檔、新建文檔、查找文字、替換文字,插入文字、插入圖片、插入表格,在書簽處插入文字、插入圖片、插入表格等。填充數據到表格中讀取表格數據 ,1.1版增強的功能: 指定文本樣式,指定表格樣式。如此,則可動態排版word文檔。是一種不錯的解決方案。
4:iText是著名的開放源碼的站點sourceforge一個項目,是用於生成PDF文檔的一個java類庫。通過iText不僅可以生成PDF或rtf的文檔,而且可以將XML、Html文件轉化為PDF文件。功能強大。
5:JSP輸出樣式,該方案實現簡單,但是處理樣式有點缺陷,簡單的導出可以使用。
6:用XML做就很簡單了。Word從2003開始支持XML格式,大致的思路是先用office2003或者2007編輯好word的樣式,然後另存為xml,將xml翻譯為FreeMarker模板,最後用java來解析FreeMarker模板並輸出Doc。經測試這樣方式生成的word文檔完全符合office標准,樣式、內容控制非常便利,列印也不會變形,生成的文檔和office中編輯文檔完全一樣。

B. 如何用java導出一個很復雜的word文件,要求把輸入的值顯示到word文件

操作word好像沒這么復雜吧,直接把你生成的數據變成文件流寫入word文件

C. java 把office word,ppt轉化為圖片

從一個大神那裡學來的,已測試無誤
package com;

import java.awt.Dimension;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

import org.apache.poi.hslf.model.TextRun;
import org.apache.poi.hslf.usermodel.RichTextRun;
import org.apache.poi.hslf.usermodel.SlideShow;

public class ExportPPT {

public static void main(String[] args) {
// 讀入PPT文件
File file = new File("D:\\UPH.ppt");
doPPTtoImage(file);
}

public static boolean doPPTtoImage(File file) {
boolean isppt = checkFile(file);
if (!isppt) {
System.out.println("The image you specify don't exit!");
return false;
}
try {
FileInputStream is = new FileInputStream(file);
SlideShow ppt = new SlideShow(is);
is.close();
Dimension pgsize = ppt.getPageSize();
org.apache.poi.hslf.model.Slide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
TextRun[] truns = slide[i].getTextRuns();
for (int k = 0; k < truns.length; k++) {
RichTextRun[] rtruns = truns[k].getRichTextRuns();
for (int l = 0; l < rtruns.length; l++) {
rtruns[l].setFontIndex(1);
rtruns[l].setFontName("宋體");
}
}
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
BufferedImage.TYPE_INT_RGB);

Graphics2D graphics = img.createGraphics();
graphics.setPaint(Color.BLUE);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
slide[i].draw(graphics);

// 這里設置圖片的存放路徑和圖片的格式(jpeg,png,bmp等等),注意生成文件路徑
File path = new File("D:/images");
if (!path.exists()) {
path.mkdir();
}
FileOutputStream out = new FileOutputStream(path + "/" + (i + 1)
+ ".jpg");
javax.imageio.ImageIO.write(img, "jpeg", out);
out.close();
}
System.out.println("success!!");
return true;
} catch (FileNotFoundException e) {
System.out.println(e);
} catch (IOException e) {
}
return false;
}

// function 檢查文件是否為PPT
public static boolean checkFile(File file) {

boolean isppt = false;
String filename = file.getName();
String suffixname = null;
if (filename != null && filename.indexOf(".") != -1) {
suffixname = filename.substring(filename.lastIndexOf("."));
if (suffixname.equals(".ppt")) {
isppt = true;
}
return isppt;
} else {
return isppt;
}
}

}

D. 求JAVA WORD 轉圖片 方法 有代碼更好!

給你說個思路吧!
用java將word轉換為圖片,道理就是用java讀取word然後寫到圖片上,就像生成驗證碼似的
其中會遇到的瓶頸是:1、word裡面插入的圖片,這個你要分開來判斷。2、對於word多少頁生成一張圖片。還是整個word生成一個圖片。
希望可以幫到你。

E. 怎麼用java導出word

java導出word代碼如下:

package com.bank.util;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
public class WordTools {
public void createDocContext(String file) throws DocumentException,
IOException {
// 設置紙張大小
Document document = new Document(PageSize.A4);
// 建立一個書寫器(Writer)與document對象關聯,通過書寫器(Writer)可以將文檔寫入到磁碟中
RtfWriter2.getInstance(document, new FileOutputStream(file));
document.open();
// 設置中文字體
BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 標題字體風格
Font titleFont = new Font(bfChinese, 12, Font.BOLD);
// 正文字體風格
Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
Paragraph title = new Paragraph("標題");
// 設置標題格式對齊方式
title.setAlignment(Element.ALIGN_CENTER);
title.setFont(titleFont);
document.add(title);
String contextString = "iText是一個能夠快速產生PDF文件的java類庫。"
+ " \n"// 換行
+ "iText的java類對於那些要產生包含文本,"
+ "表格,圖形的只讀文檔是很有用的。它的類庫尤其與java Servlet有很好的給合。"
+ "使用iText與PDF能夠使你正確的控制Servlet的輸出。";
Paragraph context = new Paragraph(contextString);
// 正文格式左對齊
context.setAlignment(Element.ALIGN_LEFT);
context.setFont(contextFont);
// 離上一段落(標題)空的行數
context.setSpacingBefore(5);
// 設置第一行空的列數
context.setFirstLineIndent(20);
document.add(context);
//利用類FontFactory結合Font和Color可以設置各種各樣字體樣式
/**
* Font.UNDERLINE 下劃線,Font.BOLD 粗體
*/
Paragraph underline = new Paragraph("下劃線的實現", FontFactory.getFont(
FontFactory.HELVETICA_BOLDOBLIQUE, 18, Font.UNDERLINE,
new Color(0, 0, 255)));
document.add(underline);

// 設置 Table 表格
Table aTable = new Table(3);
int width[] = {25,25,50};
aTable.setWidths(width);//設置每列所佔比例
aTable.setWidth(90); // 占頁面寬度 90%
aTable.setAlignment(Element.ALIGN_CENTER);//居中顯示
aTable.setAlignment(Element.ALIGN_MIDDLE);//縱向居中顯示
aTable.setAutoFillEmptyCells(true); //自動填滿
aTable.setBorderWidth(1); //邊框寬度
aTable.setBorderColor(new Color(0, 125, 255)); //邊框顏色
aTable.setPadding(0);//襯距,看效果就知道什麼意思了
aTable.setSpacing(0);//即單元格之間的間距
aTable.setBorder(2);//邊框
//設置表頭
/**
* cell.setHeader(true);是將該單元格作為表頭信息顯示;
* cell.setColspan(3);指定了該單元格佔3列;
* 為表格添加表頭信息時,要注意的是一旦表頭信息添加完了之後, \
* 必須調用 endHeaders()方法,否則當表格跨頁後,表頭信息不會再顯示
*/
Cell haderCell = new Cell("表格表頭");
haderCell.setHeader(true);
haderCell.setColspan(3);
aTable.addCell(haderCell);
aTable.endHeaders();
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.GREEN);
Cell cell = new Cell(new Phrase("這是一個測試的 3*3 Table 數據", fontChinese ));
cell.setVerticalAlignment(Element.ALIGN_TOP);
cell.setBorderColor(new Color(255, 0, 0));
cell.setRowspan(2);
aTable.addCell(cell);
aTable.addCell(new Cell("#1"));
aTable.addCell(new Cell("#2"));
aTable.addCell(new Cell("#3"));
aTable.addCell(new Cell("#4"));
Cell cell3 = new Cell(new Phrase("一行三列數據", fontChinese ));
cell3.setColspan(3);
cell3.setVerticalAlignment(Element.ALIGN_CENTER);
aTable.addCell(cell3);
document.add(aTable);
document.add(new Paragraph("\n"));
//添加圖片
// Image img=Image.getInstance("http://127.0.0.1:8080/testSystem/images/1_r1_c1.png");
// img.setAbsolutePosition(0, 0);
// img.setAlignment(Image.RIGHT);//設置圖片顯示位置
// img.scaleAbsolute(12,35);//直接設定顯示尺寸
// img.scalePercent(50);//表示顯示的大小為原尺寸的50%
// img.scalePercent(25, 12);//圖像高寬的顯示比例
// img.setRotation(30);//圖像旋轉一定角度
// document.add(img);
document.close();
}
public static void main(String[] args){
WordTools b=new WordTools();
try {
b.createDocContext("d:/demo.doc");
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

F. java poi導出word 可以設置格式嗎

  1. 讀取word 2003及word 2007需要的jar包

  2. 讀取 2003 版本(.doc)的word文件相對來說比較簡單,只需要 poi-3.5-beta6-.jar 和 poi-scratchpad-3.5-beta6-.jar 兩個 jar 包即可, 而 2007 版本(.docx)就麻煩多,我說的這個麻煩不是我們寫代碼的時候麻煩,是要導入的 jar 包比較的多,有如下 7 個之多:

  3. 1. openxml4j-bin-beta.jar

  4. 2. poi-3.5-beta6-.jar

  5. 3. poi-ooxml-3.5-beta6-.jar

  6. 4 .dom4j-1.6.1.jar

  7. 5. geronimo-stax-api_1.0_spec-1.0.jar

  8. 6. ooxml-schemas-1.0.jar

  9. 7. xmlbeans-2.3.0.jar

  10. 其中 4-7 是 poi-ooxml-3.5-beta6-.jar 所依賴的 jar 包(在 poi-bin-3.5-beta6-.tar.gz 中的 ooxml-lib 目錄下可以找到)。

  11. 2.換行符號

  12. 硬換行:文件中換行,如果是鍵盤中使用鍵余了"enter"的換行。

  13. 軟換行:文件中一行的字元數容量有限,當字元數量超過一定值時,會自動切到下行顯示。

  14. 對頌派程序來說,硬換行才是可以識別的、確定的換行,軟換行與字體大小、縮進有野亮賀關。

  15. 3.讀取的注意事項

  16. 值得注意的是: POI 在讀取不會讀取 word 文件中的圖片信息; 還有就是對於 2007 版的 word(.docx), 如果 word 文件中有表格,所有表格中的數據都會在讀取出來的字元串的最後。

  17. 4.讀取word文本內容代碼

1 import java.io.File;

2 import java.io.FileInputStream;

3 import java.io.InputStream;

4

5 import org.apache.poi.POIXMLDocument;

6 import org.apache.poi.POIXMLTextExtractor;

7 import org.apache.poi.hwpf.extractor.WordExtractor;

8 import org.apache.poi.openxml4j.opc.OPCPackage;

9 import org.apache.poi.xwpf.extractor.XWPFWordExtractor;

10

11 public class Test {

12 public static void main(String[] args) {

13 try {

14 InputStream is = new FileInputStream(new File("2003.doc"));

15 WordExtractor ex = new WordExtractor(is);

16 String text2003 = ex.getText();

17 System.out.println(text2003);

18

19 OPCPackage opcPackage = POIXMLDocument.openPackage("2007.docx");

20 POIXMLTextExtractor extractor = new XWPFWordExtractor(opcPackage);

21 String text2007 = extractor.getText();

22 System.out.println(text2007);

23

24 } catch (Exception e) {

25 e.printStackTrace();

26 }

27 }

28 }

G. 有什麼方法可以用java 將word或者Excel文件轉換成圖片文件

可以用openoffice將word轉化為pdf,再使用swftools把pdf轉換為swf

閱讀全文

與java導出word圖片格式相關的資料

熱點內容
喜歡簡單的圖片 瀏覽:576
比耶女孩圖片頭像 瀏覽:899
工業熱風機圖片與價格 瀏覽:575
女生背影圖片背書包 瀏覽:828
男生把女生攬在懷里的圖片 瀏覽:243
萌兔子圖片可愛頭像卡通 瀏覽:632
最瘦小女孩子圖片 瀏覽:780
查男生腹肌圖片 瀏覽:516
自製視頻怎麼分成一張張的圖片 瀏覽:427
生氣文字的圖片 瀏覽:960
小班科學牆面布置圖片簡單大方 瀏覽:959
用黑卡紙刻畫的簡單圖片大全 瀏覽:991
高中男孩發型圖片 瀏覽:790
我的妲己可愛圖片 瀏覽:51
吳尊頭像圖片高清帥氣 瀏覽:163
如何看關於原神的一些圖片 瀏覽:515
真實的美女背影圖片 瀏覽:100
跟閨蜜逛街買衣服的圖片 瀏覽:259
日本動漫房間圖片 瀏覽:740
18女孩發型圖片大全 瀏覽:874