Ⅰ java使用jacob調用com組件實現把excel的圖表復制到word中
步驟一、先進入Excel表格,然後選中需要導入到Word文檔中的區域,按下 Ctrl+C 復制;
步驟二、打開Word,然後選擇菜單欄的「編輯」中的「選擇性粘貼」,在「形式」下面選中「Microsoft Office Excel 工作表 對象」然後確定;
此時,就已經把編輯好的Excel表格導入到Word中了,有的人這時肯定會說,這還不是和Word中表格沒什麼卻別啊!確實,就這樣用肉眼看,根本就看不錯這個表格和Word中做的表格有什麼不一樣之處;
區別肯定是有的,不信你雙擊表格看看,會是什麼效果,沒錯把,導入的表格和Excel中的表格一模一樣,當然,這個表格也可以自由拖動它的長和寬,還可以運用Excel中的公式呢!
Ⅱ java調用jacob組件出現的問題。
jacob 的 .jar 要在CLASSPATH中的。
Ⅲ jacob 問題,java 調用jacob,先操作word 轉pdf,再操作excel 轉pdf,這樣就會報錯
一個過程,讓jacob做一次釋放。。。。。。。。
Ⅳ java 操作 word jacob
這是word模板替換。這樣做,你先把那個word復制下來,然後在清空目標,然後在粘貼。我們用POI,jacob沒用過,具體思想是這樣。。
Ⅳ java web jacob 調用微軟語音庫獲取音頻流
生成 wav,然後網頁中嵌入
請參考生成wave的C#代碼
/// <summary>
/// 輸出WAV
/// </summary>
/// <param name="path">保存路徑</param>
/// <param name="str">要轉換的文本內容</param>
/// <returns></returns>
public bool WreiteToWAV(string path,string str,SpeechAudioFormatType SpAudioType)
{
SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
SpFileStream SpFileStream = new SpFileStream();
SpeechVoiceSpeakFlags SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpAudioFormat SpAudio = new DotNetSpeech.SpAudioFormat();
SpAudio.Type = SpAudioType;
SpFileStream.Format = SpAudio;
SpFileStream.Open(path, SpFileMode, false);
voice.AudioOutputStream = SpFileStream;
voice.Speak(str, SpFlags);
voice.WaitUntilDone(Timeout.Infinite);
SpFileStream.Close();
return File.Exists(path);
}
Ⅵ java如何使用Jacob對word文檔所有頁面架上水印
你這個是word文檔的問題,點擊頁眉,裡面有個首頁不同選項,把勾去掉,就好了。不是jacob的問題。
Ⅶ 如何利用Java-JACOB操作WORD文檔
1. 初始化com的線程,非常重要,否則第二次創建com對象的時候會出現can』t co-create object異常 (參見jacob的幫助文檔),完成操作com組件後要調用 realease方法
ComThread.InitSTA();// 初始化com的線程,非常重要!!使用結束後要調用 realease方法
2. 初始化word應用程序,新建一個空白文檔,取得文檔內容對象//Instantiate objWord //Declare word object
ActiveXComponent objWord = new ActiveXComponent("Word.Application");
//Assign a local word object
Dispatch wordObject = (Dispatch) objWord.getObject();
//Create a Dispatch Parameter to show the document that is opened
Dispatch.put((Dispatch) wordObject, "Visible", new Variant(true));// new Variant(true)表示word應用程序可見
Tip:設置一個對象的屬性的時候,利用Dispatch的put方法,給屬性賦值。上面這行語句相當於vb的 wordObject.Visible = true 語句
//Instantiate the Documents Property
Dispatch documents = objWord.getProperty("Documents").toDispatch(); //documents表示word的所有文檔窗口,(word是多文檔應用程序)
//Add a new word document, Current Active Document
Dispatch document = Dispatch.call(documents, "Add").toDispatch(); // 使用Add命令創建一個新文檔,用Open命令可以打開一個現有文檔
Tip:調用一個對象的方法的時候,利用Dispatch的call方法,上面的語句相當於vb的document = documents.Add() 語句。
Dispatch wordContent = Dispatch.get(document, "Content").toDispatch(); // 取得word文件的內容
Tip:取得一個對象的成員變數(屬性)時利用Dispatch的get方法,上面的語句相當於vb的wordContent = document.Content語句
3. 取得word文檔的內容後,可以對其內容進行操作
Dispatch.call(wordContent, "InsertAfter", "這里是一個段落的內容");//插入一個段落
4. 設置剛插入的段落的文字格式
Dispatch paragraphs = Dispatch.get(wordContent, "Paragraphs").toDispatch(); // 所有段落
int paragraphCount = Dispatch.get(paragraphs, "Count").toInt(); // 一共的段落數
// 找到剛輸入的段落,設置格式
Dispatch lastParagraph = Dispatch.call(paragraphs, "Item",
new Variant(paragraphCount)).
toDispatch(); // 最後一段
Dispatch lastParagraphRange = Dispatch.get(lastParagraph, "Range").
toDispatch();
Dispatch font = Dispatch.get(lastParagraphRange, "Font").toDispatch();
Dispatch.put(font, "Bold", new Variant(true)); // 設置為黑體
Dispatch.put(font, "Italic", new Variant(true)); // 設置為斜體
Dispatch.put(font, "Name", new Variant("宋體")); //
Dispatch.put(font, "Size", new Variant(12)); //小四
注意:如果想插入一個新的空白行,也需要設置段落的文字格式,否則新插入行的文字格式會於剛插入的段落的格式相同。
5. 將當前文檔保存
Dispatch.call(document, "SaveAs", new Variant("C:
abc.doc")); // 保存一個新文檔
6. 釋放COM線程
ComThread.Release();//釋放com線程。根據jacob的幫助文檔,com的線程回收不由java的垃圾回收器處理
完整測試代碼:(StudyJacob.java 附件中有本文章和java源文件)
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.jacob.com.ComThread;
public class StudyJacob {
public static void main(String[] args) {
ComThread.InitSTA();// 初始化com的線程,非常重要!!使用結束後要調用 realease方法
//Instantiate objWord //Declare word object
ActiveXComponent objWord = new ActiveXComponent("Word.Application");
//Assign a local word object
Dispatch wordObject = (Dispatch) objWord.getObject();
//Create a Dispatch Parameter to show the document that is opened
Dispatch.put((Dispatch) wordObject, "Visible", new Variant(true));// new Variant(true)表示word應用程序可見
//Instantiate the Documents Property
Dispatch documents = objWord.getProperty("Documents").toDispatch(); //documents表示word的所有文檔窗口,(word是多文檔應用程序)
//Add a new word document, Current Active Document
Dispatch document = Dispatch.call(documents, "Add").toDispatch(); // 使用Add命令創建一個新文檔,用Open命令可以打開一個現有文檔
Dispatch wordContent = Dispatch.get(document, "Content").toDispatch(); // 取得word文件的內容
Dispatch.call(wordContent, "InsertAfter", "這里是一個段落的內容");//插入一個段落
Dispatch paragraphs = Dispatch.get(wordContent, "Paragraphs").toDispatch(); // 所有段落
int paragraphCount = Dispatch.get(paragraphs, "Count").toInt(); // 一共的段落數
// 找到剛輸入的段落,設置格式
Dispatch lastParagraph = Dispatch.call(paragraphs, "Item",
new Variant(paragraphCount)).
toDispatch(); // 最後一段
Dispatch lastParagraphRange = Dispatch.get(lastParagraph, "Range").
toDispatch();
Dispatch font = Dispatch.get(lastParagraphRange, "Font").toDispatch();
Dispatch.put(font, "Bold", new Variant(true)); // 設置為黑體
Dispatch.put(font, "Italic", new Variant(true)); // 設置為斜體
Dispatch.put(font, "Name", new Variant("宋體")); //
Dispatch.put(font, "Size", new Variant(12)); //小四
Dispatch.call(document, "SaveAs", new Variant("C:
abc.doc")); // 保存一個新文檔
ComThread.Release();//釋放com線程。根據jacob的幫助文檔,com的線程回收不由java的垃圾回收器處理
}
}