- 浏览: 21711 次
- 性别:
- 来自: 广州
最新评论
-
Dead_knight:
由于默认的jsessionid冲突导致的
关于从一个应用系统登录到另外一个应用系统导致session错乱解决 -
zongpin:
LZ,您说的第二种方式我已经实现了,可是第一种(“第一种就是通 ...
birt在spring中的集成
这里收集一些自己写的和网上看到的代码,供参
1.这个是自己写的:
public void doExpWordSend(EgrandContext egrandContext, long flId)
throws IOException {
FlowInstance fl = this.flowInstanceService.load(egrandContext, flId);
long sendFormId = Long.parseLong(fl.getFlowFormID());
// 得到当前流程的form
SendForm sf = this.sendDao.load(new Long(sendFormId));
// 得到当前流程的办理信息
List flowCommentList = new ArrayList(fl.getFlowComments());
// 得到当前流程的发送记录
List flowSendLogList = new ArrayList(fl.getFlowSendLogs());
ComThread.InitMTA();// 初始化com线程
ActiveXComponent axc = new ActiveXComponent("Word.Application");// decalre
// word
// object
Dispatch wordObject = (Dispatch) axc.getObject();// assign a local word
// object
Dispatch.put(wordObject, "Visible", new Variant(true));
Dispatch documents = axc.getProperty("Documents").toDispatch();
Dispatch document = Dispatch.call(documents, "Add").toDispatch();// 创建文档
// 写word
Dispatch wordContent = Dispatch.get(document, "content").toDispatch();
Dispatch selection = Dispatch.get(wordObject, "Selection").toDispatch();
Dispatch paragraphFormat = Dispatch.get(selection, "ParagraphFormat")
.getDispatch();
Dispatch font = Dispatch.get(selection, "Font").toDispatch();// 字形格式化需要的对象
Dispatch.put(paragraphFormat, "Alignment", "1");// 设置标题的对齐方式(1:置中 2:靠右
// 3:靠左)
Dispatch.put(font, "Bold", "4");
Dispatch.put(font, "Size", "26");
Dispatch.put(font, "Color", "0,0,0,0"); // 字型颜色
// Dispatch.put(font, "Italic", "1"); //字型斜体
Dispatch.call(selection, "TypeText", "广州海洋地质局发文:" + sf.getSubject()); // 写入标题内容
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
Dispatch.put(paragraphFormat, "Alignment", "3"); // 设置正文的对齐方式(1:置中 2:靠右
// 3:靠左)
Dispatch.put(font, "Bold", "0");
Dispatch.put(font, "Size", "12");
Dispatch.put(selection, "Text", sf.getAuthor().getName()
+ sf.getAuthorOUName() + "创建于" + sf.getFileDateTime());
Dispatch.call(selection, "MoveRight");
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
/**
* 新建表格sendForm
*/
Dispatch tables = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch tablerange = Dispatch.get(selection, "Range").toDispatch();
Dispatch newTable = Dispatch.call(tables, "Add", tablerange,
new Variant(6), new Variant(4)).toDispatch();
// 往表格中填写内容。
Dispatch newtables = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch table = Dispatch.call(newtables, "Item", new Variant(1))
.toDispatch(); // 要填充的表格
this.puTableCellText(table, selection, 1, 1, "文件标题:");
this.puTableCellText(table, selection, 1, 2, sf.getSubject());
this.puTableCellText(table, selection, 2, 1, "关键字:");
this.puTableCellText(table, selection, 2, 2, sf.getKeyWord());
this.puTableCellText(table, selection, 2, 3, "文件密级:");
this.puTableCellText(table, selection, 2, 4, sf.getSecretLevel());
this.puTableCellText(table, selection, 3, 1, "主办单位:");
this.puTableCellText(table, selection, 3, 2, sf.getSponsor());
this.puTableCellText(table, selection, 3, 3, "拟稿人:");
this.puTableCellText(table, selection, 3, 4, sf.getAuthor().getName());
this.puTableCellText(table, selection, 4, 1, "文件日期:");
this.puTableCellText(table, selection, 4, 2, sf.getFileDateTime());
this.puTableCellText(table, selection, 4, 3, "文件印数:");
this.puTableCellText(table, selection, 4, 4, String.valueOf(sf.getCopys()));
this.puTableCellText(table, selection, 5, 1, "文件种类:");
this.puTableCellText(table, selection, 5, 2, sf.getDocumentType());
this.puTableCellText(table, selection, 5, 3, "紧急程度:");
this.puTableCellText(table, selection, 5, 4, sf.getEmergencyLevel());
this.puTableCellText(table, selection, 6, 1, "文件编号:");
this.puTableCellText(table, selection, 6, 2, sf.getFileID());
this.puTableCellText(table, selection, 6, 3, "给号日期:");
this.puTableCellText(table, selection, 6, 4, DateTimeUtils.formatDate(sf.getNumberedDate()));
Dispatch.call(selection, "EndKey", String.valueOf(6));
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
Dispatch.call(selection,"TypeText","办理信息");
/**
* 新建表格flowCommentList
*/
Dispatch tablerange2 = Dispatch.get(selection, "Range").toDispatch();
Dispatch newTable2 = Dispatch.call(tables, "Add", tablerange2,
new Variant(flowCommentList.size()==0? 1+1:flowCommentList.size()+1), new Variant(4)).toDispatch();
Dispatch newtables2 = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch table2 = Dispatch.call(newtables2, "Item", new Variant(2))
.toDispatch(); // 要填充的表格
// Dispatch cols2 = Dispatch.get(table2, "Columns").toDispatch(); // 表格的所有行
// Dispatch rows2 = Dispatch.get(table2, "Rows").toDispatch(); // 表格的所有列
// int colsCount2 = Dispatch.get(cols2, "Count").toInt();
// int rowsCount2 = Dispatch.get(rows2, "Count").toInt();
// Dispatch col2 = Dispatch.get(cols2, "First").toDispatch();
this.puTableCellText(table2, selection, 1, 1, "办理人");
this.puTableCellText(table2, selection, 1, 2, "办理环节");
this.puTableCellText(table2, selection, 1, 3, "办理意见");
this.puTableCellText(table2, selection, 1, 4, "办理时间");
for(int i=0;i<flowCommentList.size();i++){
FlowComment fc = (FlowComment) flowCommentList.get(i);
this.puTableCellText(table2, selection, i+2, 1, fc.getActor().getName());
this.puTableCellText(table2, selection, i+2, 2, fc.getNodeName());
this.puTableCellText(table2, selection, i+2, 3, fc.getCommentContent());
this.puTableCellText(table2, selection, i+2, 4, DateTimeUtils.formatDateTime(fc.getCommentDate()));
}
Dispatch.call(selection, "EndKey", String.valueOf(6));
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
Dispatch.call(selection,"TypeText","发送记录");
/**
* 新建表格flowSendLogList
*/
Dispatch tablerange3 = Dispatch.get(selection, "Range").toDispatch();
Dispatch newTable3 = Dispatch.call(tables, "Add", tablerange3,
new Variant(flowSendLogList.size()==0? 1+1:flowSendLogList.size()+1), new Variant(5)).toDispatch();
Dispatch newtables3 = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch table3 = Dispatch.call(newtables3, "Item", new Variant(3))
.toDispatch(); // 要填充的表格
this.puTableCellText(table3, selection, 1, 1, "发送人");
this.puTableCellText(table3, selection, 1, 2, "源环节");
this.puTableCellText(table3, selection, 1, 3, "发送日志");
this.puTableCellText(table3, selection, 1, 4, "发送说明");
this.puTableCellText(table3, selection, 1, 5, "发送时间");
for(int i=0;i<flowSendLogList.size();i++){
FlowSendLog fsl = (FlowSendLog) flowSendLogList.get(i);
this.puTableCellText(table3, selection, i+2, 1, fsl.getSender().getName());
this.puTableCellText(table3, selection, i+2, 2, fsl.getSourceNodeName());
this.puTableCellText(table3, selection, i+2, 3, "送"+fsl.getTodoer()+"("+fsl.getNodeName()+")");
this.puTableCellText(table3, selection, i+2, 4, fsl.getSendMemo());
this.puTableCellText(table3, selection, i+2, 5, DateTimeUtils.formatDateTime(fsl.getSendedDate()));
}
Dispatch.call(selection, "EndKey", String.valueOf(6));
Dispatch.call(document, "SaveAs", "c:\\gongwen.doc"); // 保存一个新文档
Dispatch.call(MsWordApp,"Quit");
ComThread.Release();// 释放com线程。
}
// 向table cell填充内容
public void puTableCellText(Dispatch table, Dispatch selection, int row,
int col, String text) {
Dispatch cell = Dispatch.call(table, "Cell", new Variant(row),
new Variant(col)).getDispatch();
Dispatch.call(cell, "Select");
Dispatch.put(selection, "Text", text);
Dispatch.call(selection, "MoveRight");
}
2.这个是网上找来的:
package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class MSWordManager {
// word文档
private Dispatch doc;
// word运行程序对象
private ActiveXComponent word;
// 所有word文档集合
private Dispatch documents;
// 选定的范围或插入点
private Dispatch selection;
private boolean saveOnExit = true;
/** *//**
*
* @param visible 为true表示word应用程序可见
*/
public MSWordManager(boolean visible) {
if (word == null) {
word = new ActiveXComponent("Word.Application");
word.setProperty("Visible", new Variant(visible));
}
if (documents == null)
documents = word.getProperty("Documents").toDispatch();
}
/** *//**
* 设置退出时参数
*
* @param saveOnExit boolean true-退出时保存文件,false-退出时不保存文件
*/
public void setSaveOnExit(boolean saveOnExit) {
this.saveOnExit = saveOnExit;
}
/** *//**
* 创建一个新的word文档
*
*/
public void createNewDocument() {
doc = Dispatch.call(documents, "Add").toDispatch();
selection = Dispatch.get(word, "Selection").toDispatch();
}
/** *//**
* 打开一个已存在的文档
*
* @param docPath
*/
public void openDocument(String docPath) {
closeDocument();
doc = Dispatch.call(documents, "Open", docPath).toDispatch();
selection = Dispatch.get(word, "Selection").toDispatch();
}
/** *//**
* 把选定的内容或插入点向上移动
*
* @param pos 移动的距离
*/
public void moveUp(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++)
Dispatch.call(selection, "MoveUp");
}
/** *//**
* 把选定的内容或者插入点向下移动
*
* @param pos 移动的距离
*/
public void moveDown(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++)
Dispatch.call(selection, "MoveDown");
}
/** *//**
* 把选定的内容或者插入点向左移动
*
* @param pos 移动的距离
*/
public void moveLeft(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++) {
Dispatch.call(selection, "MoveLeft");
}
}
/** *//**
* 把选定的内容或者插入点向右移动
*
* @param pos 移动的距离
*/
public void moveRight(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++)
Dispatch.call(selection, "MoveRight");
}
/** *//**
* 把插入点移动到文件首位置
*
*/
public void moveStart() {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
Dispatch.call(selection, "HomeKey", new Variant(6));
}
public void moveEnd() {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
Dispatch.call(selection, "EndKey", new Variant(6));
}
/** *//**
* 从选定内容或插入点开始查找文本
*
* @param toFindText 要查找的文本
* @return boolean true-查找到并选中该文本,false-未查找到文本
*/
public boolean find(String toFindText) {
if (toFindText == null || toFindText.equals(""))
return false;
// 从selection所在位置开始查询
Dispatch find = word.call(selection, "Find").toDispatch();
// 设置要查找的内容
Dispatch.put(find, "Text", toFindText);
// 向前查找
Dispatch.put(find, "Forward", "True");
// 设置格式
Dispatch.put(find, "Format", "True");
// 大小写匹配
Dispatch.put(find, "MatchCase", "True");
// 全字匹配
Dispatch.put(find, "MatchWholeWord", "True");
// 查找并选中
return Dispatch.call(find, "Execute").getBoolean();
}
/** *//**
* 把选定选定内容设定为替换文本
*
* @param toFindText 查找字符串
* @param newText 要替换的内容
* @return
*/
public boolean replaceText(String toFindText, String newText) {
if (!find(toFindText))
return false;
Dispatch.put(selection, "Text", newText);
return true;
}
/** *//**
* 全局替换文本
*
* @param toFindText 查找字符串
* @param newText 要替换的内容
*/
public void replaceAllText(String toFindText, String newText) {
while (find(toFindText)) {
Dispatch.put(selection, "Text", newText);
Dispatch.call(selection, "MoveRight");
}
}
/** *//**
* 在当前插入点插入字符串
*
* @param newText 要插入的新字符串
*/
public void insertText(String newText) {
Dispatch.put(selection, "Text", newText);
}
/** *//**
*
* @param toFindText 要查找的字符串
* @param imagePath 图片路径
* @return
*/
public boolean replaceImage(String toFindText, String imagePath) {
if (!find(toFindText))
return false;
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
"AddPicture", imagePath);
return true;
}
/** *//**
* 全局替换图片
*
* @param toFindText 查找字符串
* @param imagePath 图片路径
*/
public void replaceAllImage(String toFindText, String imagePath) {
while (find(toFindText)) {
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
"AddPicture", imagePath);
Dispatch.call(selection, "MoveRight");
}
}
/** *//**
* 在当前插入点插入图片
*
* @param imagePath 图片路径
*/
public void insertImage(String imagePath) {
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
"AddPicture", imagePath);
}
/** *//**
* 合并单元格
*
* @param tableIndex
* @param fstCellRowIdx
* @param fstCellColIdx
* @param secCellRowIdx
* @param secCellColIdx
*/
public void mergeCell(int tableIndex, int fstCellRowIdx, int fstCellColIdx,
int secCellRowIdx, int secCellColIdx) {
// 所有表格
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
.toDispatch();
Dispatch fstCell = Dispatch.call(table, "Cell",
new Variant(fstCellRowIdx), new Variant(fstCellColIdx))
.toDispatch();
Dispatch secCell = Dispatch.call(table, "Cell",
new Variant(secCellRowIdx), new Variant(secCellColIdx))
.toDispatch();
Dispatch.call(fstCell, "Merge", secCell);
}
/** *//**
* 在指定的单元格里填写数据
*
* @param tableIndex
* @param cellRowIdx
* @param cellColIdx
* @param txt
*/
public void putTxtToCell(int tableIndex, int cellRowIdx, int cellColIdx,
String txt) {
// 所有表格
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
.toDispatch();
Dispatch cell = Dispatch.call(table, "Cell", new Variant(cellRowIdx),
new Variant(cellColIdx)).toDispatch();
Dispatch.call(cell, "Select");
Dispatch.put(selection, "Text", txt);
}
/** *//**
* 在当前文档拷贝数据
*
* @param pos
*/
public void copy(String toCopyText) {
moveStart();
if (this.find(toCopyText)) {
Dispatch textRange = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(textRange, "Copy");
}
}
/** *//**
* 在当前文档粘帖剪贴板数据
*
* @param pos
*/
public void paste(String pos) {
moveStart();
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(textRange, "Paste");
}
}
/** *//**
* 在当前文档指定的位置拷贝表格
*
* @param pos 当前文档指定的位置
* @param tableIndex 被拷贝的表格在word文档中所处的位置
*/
public void copyTable(String pos,int tableIndex) {
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
.toDispatch();
Dispatch range = Dispatch.get(table, "Range").toDispatch();
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(textRange, "Paste");
}
}
/** *//**
* 在当前文档末尾拷贝来自另一个文档中的段落
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param tableIndex 被拷贝的段落在另一格文档中的序号(从1开始)
*/
public void copyParagraphFromAnotherDoc(String anotherDocPath,
int paragraphIndex) {
Dispatch wordContent = Dispatch.get(doc, "Content").toDispatch(); // 取得当前文档的内容
Dispatch.call(wordContent, "InsertAfter", "$selection$");// 插入特殊符定位插入点
copyParagraphFromAnotherDoc(anotherDocPath, paragraphIndex,
"$selection$");
}
/** *//**
* 在当前文档指定的位置拷贝来自另一个文档中的段落
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param tableIndex 被拷贝的段落在另一格文档中的序号(从1开始)
* @param pos 当前文档指定的位置
*/
public void copyParagraphFromAnotherDoc(String anotherDocPath,
int paragraphIndex, String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch paragraphs = Dispatch.get(doc2, "Paragraphs").toDispatch();
Dispatch paragraph = Dispatch.call(paragraphs, "Item",
new Variant(paragraphIndex)).toDispatch();
Dispatch range = Dispatch.get(paragraph, "Range").toDispatch();
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}
/** *//**
* 在当前文档指定的位置拷贝来自另一个文档中的表格
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param tableIndex 被拷贝的表格在另一格文档中的序号(从1开始)
* @param pos 当前文档指定的位置
*/
public void copyTableFromAnotherDoc(String anotherDocPath, int tableIndex,
String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch tables = Dispatch.get(doc2, "Tables").toDispatch();
Dispatch table = Dispatch.call(tables, "Item",
new Variant(tableIndex)).toDispatch();
Dispatch range = Dispatch.get(table, "Range").toDispatch();
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}
/** *//**
* 在当前文档指定的位置拷贝来自另一个文档中的图片
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param shapeIndex 被拷贝的图片在另一格文档中的位置
* @param pos 当前文档指定的位置
*/
public void copyImageFromAnotherDoc(String anotherDocPath, int shapeIndex,
String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch shapes = Dispatch.get(doc2, "InLineShapes").toDispatch();
Dispatch shape = Dispatch.call(shapes, "Item",
new Variant(shapeIndex)).toDispatch();
Dispatch imageRange = Dispatch.get(shape, "Range").toDispatch();
Dispatch.call(imageRange, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}
3.实践中遇到的一些bug和修正方式:
3-1).jacob-1.14.3.jar是在jdk1.5以上的环境运行,如果你要其运行在jkd1.4.2下,需改源码,重新编译,这里有个自己编译好的jacob-1.14.3.jar,这里不能上传附件,需要可以向我要qq:278698582。
3-2).在win2000,win2003下可能要装vcredist_x86.exe,下载地址:http://download.microsoft.com/download/e/1/c/e1c773de-73ba-494a-a5ba-f24906ecf088/vcredist_x86.exe
3-3)服务器上需要安装word
3-4)我在运行的程序的时候,第一次成功,第二次会导致程序崩溃,最体原因也不清楚,应该启用windows线程问题,最后解决方法是:wordObject.safeRelease();
axc.safeRelease();
ComThread.Release();// 释放com线程。
全部释放下,同时在public static ActiveXComponent axc = new ActiveXComponent("Word.Application");
启动线性时候axc.safeRelease();
axc = new ActiveXComponent("Word.Application");// decalre word
1.这个是自己写的:
public void doExpWordSend(EgrandContext egrandContext, long flId)
throws IOException {
FlowInstance fl = this.flowInstanceService.load(egrandContext, flId);
long sendFormId = Long.parseLong(fl.getFlowFormID());
// 得到当前流程的form
SendForm sf = this.sendDao.load(new Long(sendFormId));
// 得到当前流程的办理信息
List flowCommentList = new ArrayList(fl.getFlowComments());
// 得到当前流程的发送记录
List flowSendLogList = new ArrayList(fl.getFlowSendLogs());
ComThread.InitMTA();// 初始化com线程
ActiveXComponent axc = new ActiveXComponent("Word.Application");// decalre
// word
// object
Dispatch wordObject = (Dispatch) axc.getObject();// assign a local word
// object
Dispatch.put(wordObject, "Visible", new Variant(true));
Dispatch documents = axc.getProperty("Documents").toDispatch();
Dispatch document = Dispatch.call(documents, "Add").toDispatch();// 创建文档
// 写word
Dispatch wordContent = Dispatch.get(document, "content").toDispatch();
Dispatch selection = Dispatch.get(wordObject, "Selection").toDispatch();
Dispatch paragraphFormat = Dispatch.get(selection, "ParagraphFormat")
.getDispatch();
Dispatch font = Dispatch.get(selection, "Font").toDispatch();// 字形格式化需要的对象
Dispatch.put(paragraphFormat, "Alignment", "1");// 设置标题的对齐方式(1:置中 2:靠右
// 3:靠左)
Dispatch.put(font, "Bold", "4");
Dispatch.put(font, "Size", "26");
Dispatch.put(font, "Color", "0,0,0,0"); // 字型颜色
// Dispatch.put(font, "Italic", "1"); //字型斜体
Dispatch.call(selection, "TypeText", "广州海洋地质局发文:" + sf.getSubject()); // 写入标题内容
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
Dispatch.put(paragraphFormat, "Alignment", "3"); // 设置正文的对齐方式(1:置中 2:靠右
// 3:靠左)
Dispatch.put(font, "Bold", "0");
Dispatch.put(font, "Size", "12");
Dispatch.put(selection, "Text", sf.getAuthor().getName()
+ sf.getAuthorOUName() + "创建于" + sf.getFileDateTime());
Dispatch.call(selection, "MoveRight");
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
/**
* 新建表格sendForm
*/
Dispatch tables = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch tablerange = Dispatch.get(selection, "Range").toDispatch();
Dispatch newTable = Dispatch.call(tables, "Add", tablerange,
new Variant(6), new Variant(4)).toDispatch();
// 往表格中填写内容。
Dispatch newtables = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch table = Dispatch.call(newtables, "Item", new Variant(1))
.toDispatch(); // 要填充的表格
this.puTableCellText(table, selection, 1, 1, "文件标题:");
this.puTableCellText(table, selection, 1, 2, sf.getSubject());
this.puTableCellText(table, selection, 2, 1, "关键字:");
this.puTableCellText(table, selection, 2, 2, sf.getKeyWord());
this.puTableCellText(table, selection, 2, 3, "文件密级:");
this.puTableCellText(table, selection, 2, 4, sf.getSecretLevel());
this.puTableCellText(table, selection, 3, 1, "主办单位:");
this.puTableCellText(table, selection, 3, 2, sf.getSponsor());
this.puTableCellText(table, selection, 3, 3, "拟稿人:");
this.puTableCellText(table, selection, 3, 4, sf.getAuthor().getName());
this.puTableCellText(table, selection, 4, 1, "文件日期:");
this.puTableCellText(table, selection, 4, 2, sf.getFileDateTime());
this.puTableCellText(table, selection, 4, 3, "文件印数:");
this.puTableCellText(table, selection, 4, 4, String.valueOf(sf.getCopys()));
this.puTableCellText(table, selection, 5, 1, "文件种类:");
this.puTableCellText(table, selection, 5, 2, sf.getDocumentType());
this.puTableCellText(table, selection, 5, 3, "紧急程度:");
this.puTableCellText(table, selection, 5, 4, sf.getEmergencyLevel());
this.puTableCellText(table, selection, 6, 1, "文件编号:");
this.puTableCellText(table, selection, 6, 2, sf.getFileID());
this.puTableCellText(table, selection, 6, 3, "给号日期:");
this.puTableCellText(table, selection, 6, 4, DateTimeUtils.formatDate(sf.getNumberedDate()));
Dispatch.call(selection, "EndKey", String.valueOf(6));
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
Dispatch.call(selection,"TypeText","办理信息");
/**
* 新建表格flowCommentList
*/
Dispatch tablerange2 = Dispatch.get(selection, "Range").toDispatch();
Dispatch newTable2 = Dispatch.call(tables, "Add", tablerange2,
new Variant(flowCommentList.size()==0? 1+1:flowCommentList.size()+1), new Variant(4)).toDispatch();
Dispatch newtables2 = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch table2 = Dispatch.call(newtables2, "Item", new Variant(2))
.toDispatch(); // 要填充的表格
// Dispatch cols2 = Dispatch.get(table2, "Columns").toDispatch(); // 表格的所有行
// Dispatch rows2 = Dispatch.get(table2, "Rows").toDispatch(); // 表格的所有列
// int colsCount2 = Dispatch.get(cols2, "Count").toInt();
// int rowsCount2 = Dispatch.get(rows2, "Count").toInt();
// Dispatch col2 = Dispatch.get(cols2, "First").toDispatch();
this.puTableCellText(table2, selection, 1, 1, "办理人");
this.puTableCellText(table2, selection, 1, 2, "办理环节");
this.puTableCellText(table2, selection, 1, 3, "办理意见");
this.puTableCellText(table2, selection, 1, 4, "办理时间");
for(int i=0;i<flowCommentList.size();i++){
FlowComment fc = (FlowComment) flowCommentList.get(i);
this.puTableCellText(table2, selection, i+2, 1, fc.getActor().getName());
this.puTableCellText(table2, selection, i+2, 2, fc.getNodeName());
this.puTableCellText(table2, selection, i+2, 3, fc.getCommentContent());
this.puTableCellText(table2, selection, i+2, 4, DateTimeUtils.formatDateTime(fc.getCommentDate()));
}
Dispatch.call(selection, "EndKey", String.valueOf(6));
Dispatch.call(selection, "TypeParagraph"); // 空一行段落
Dispatch.call(selection,"TypeText","发送记录");
/**
* 新建表格flowSendLogList
*/
Dispatch tablerange3 = Dispatch.get(selection, "Range").toDispatch();
Dispatch newTable3 = Dispatch.call(tables, "Add", tablerange3,
new Variant(flowSendLogList.size()==0? 1+1:flowSendLogList.size()+1), new Variant(5)).toDispatch();
Dispatch newtables3 = Dispatch.get(wordContent, "Tables").toDispatch();
Dispatch table3 = Dispatch.call(newtables3, "Item", new Variant(3))
.toDispatch(); // 要填充的表格
this.puTableCellText(table3, selection, 1, 1, "发送人");
this.puTableCellText(table3, selection, 1, 2, "源环节");
this.puTableCellText(table3, selection, 1, 3, "发送日志");
this.puTableCellText(table3, selection, 1, 4, "发送说明");
this.puTableCellText(table3, selection, 1, 5, "发送时间");
for(int i=0;i<flowSendLogList.size();i++){
FlowSendLog fsl = (FlowSendLog) flowSendLogList.get(i);
this.puTableCellText(table3, selection, i+2, 1, fsl.getSender().getName());
this.puTableCellText(table3, selection, i+2, 2, fsl.getSourceNodeName());
this.puTableCellText(table3, selection, i+2, 3, "送"+fsl.getTodoer()+"("+fsl.getNodeName()+")");
this.puTableCellText(table3, selection, i+2, 4, fsl.getSendMemo());
this.puTableCellText(table3, selection, i+2, 5, DateTimeUtils.formatDateTime(fsl.getSendedDate()));
}
Dispatch.call(selection, "EndKey", String.valueOf(6));
Dispatch.call(document, "SaveAs", "c:\\gongwen.doc"); // 保存一个新文档
Dispatch.call(MsWordApp,"Quit");
ComThread.Release();// 释放com线程。
}
// 向table cell填充内容
public void puTableCellText(Dispatch table, Dispatch selection, int row,
int col, String text) {
Dispatch cell = Dispatch.call(table, "Cell", new Variant(row),
new Variant(col)).getDispatch();
Dispatch.call(cell, "Select");
Dispatch.put(selection, "Text", text);
Dispatch.call(selection, "MoveRight");
}
2.这个是网上找来的:
package com.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class MSWordManager {
// word文档
private Dispatch doc;
// word运行程序对象
private ActiveXComponent word;
// 所有word文档集合
private Dispatch documents;
// 选定的范围或插入点
private Dispatch selection;
private boolean saveOnExit = true;
/** *//**
*
* @param visible 为true表示word应用程序可见
*/
public MSWordManager(boolean visible) {
if (word == null) {
word = new ActiveXComponent("Word.Application");
word.setProperty("Visible", new Variant(visible));
}
if (documents == null)
documents = word.getProperty("Documents").toDispatch();
}
/** *//**
* 设置退出时参数
*
* @param saveOnExit boolean true-退出时保存文件,false-退出时不保存文件
*/
public void setSaveOnExit(boolean saveOnExit) {
this.saveOnExit = saveOnExit;
}
/** *//**
* 创建一个新的word文档
*
*/
public void createNewDocument() {
doc = Dispatch.call(documents, "Add").toDispatch();
selection = Dispatch.get(word, "Selection").toDispatch();
}
/** *//**
* 打开一个已存在的文档
*
* @param docPath
*/
public void openDocument(String docPath) {
closeDocument();
doc = Dispatch.call(documents, "Open", docPath).toDispatch();
selection = Dispatch.get(word, "Selection").toDispatch();
}
/** *//**
* 把选定的内容或插入点向上移动
*
* @param pos 移动的距离
*/
public void moveUp(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++)
Dispatch.call(selection, "MoveUp");
}
/** *//**
* 把选定的内容或者插入点向下移动
*
* @param pos 移动的距离
*/
public void moveDown(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++)
Dispatch.call(selection, "MoveDown");
}
/** *//**
* 把选定的内容或者插入点向左移动
*
* @param pos 移动的距离
*/
public void moveLeft(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++) {
Dispatch.call(selection, "MoveLeft");
}
}
/** *//**
* 把选定的内容或者插入点向右移动
*
* @param pos 移动的距离
*/
public void moveRight(int pos) {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
for (int i = 0; i < pos; i++)
Dispatch.call(selection, "MoveRight");
}
/** *//**
* 把插入点移动到文件首位置
*
*/
public void moveStart() {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
Dispatch.call(selection, "HomeKey", new Variant(6));
}
public void moveEnd() {
if (selection == null)
selection = Dispatch.get(word, "Selection").toDispatch();
Dispatch.call(selection, "EndKey", new Variant(6));
}
/** *//**
* 从选定内容或插入点开始查找文本
*
* @param toFindText 要查找的文本
* @return boolean true-查找到并选中该文本,false-未查找到文本
*/
public boolean find(String toFindText) {
if (toFindText == null || toFindText.equals(""))
return false;
// 从selection所在位置开始查询
Dispatch find = word.call(selection, "Find").toDispatch();
// 设置要查找的内容
Dispatch.put(find, "Text", toFindText);
// 向前查找
Dispatch.put(find, "Forward", "True");
// 设置格式
Dispatch.put(find, "Format", "True");
// 大小写匹配
Dispatch.put(find, "MatchCase", "True");
// 全字匹配
Dispatch.put(find, "MatchWholeWord", "True");
// 查找并选中
return Dispatch.call(find, "Execute").getBoolean();
}
/** *//**
* 把选定选定内容设定为替换文本
*
* @param toFindText 查找字符串
* @param newText 要替换的内容
* @return
*/
public boolean replaceText(String toFindText, String newText) {
if (!find(toFindText))
return false;
Dispatch.put(selection, "Text", newText);
return true;
}
/** *//**
* 全局替换文本
*
* @param toFindText 查找字符串
* @param newText 要替换的内容
*/
public void replaceAllText(String toFindText, String newText) {
while (find(toFindText)) {
Dispatch.put(selection, "Text", newText);
Dispatch.call(selection, "MoveRight");
}
}
/** *//**
* 在当前插入点插入字符串
*
* @param newText 要插入的新字符串
*/
public void insertText(String newText) {
Dispatch.put(selection, "Text", newText);
}
/** *//**
*
* @param toFindText 要查找的字符串
* @param imagePath 图片路径
* @return
*/
public boolean replaceImage(String toFindText, String imagePath) {
if (!find(toFindText))
return false;
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
"AddPicture", imagePath);
return true;
}
/** *//**
* 全局替换图片
*
* @param toFindText 查找字符串
* @param imagePath 图片路径
*/
public void replaceAllImage(String toFindText, String imagePath) {
while (find(toFindText)) {
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
"AddPicture", imagePath);
Dispatch.call(selection, "MoveRight");
}
}
/** *//**
* 在当前插入点插入图片
*
* @param imagePath 图片路径
*/
public void insertImage(String imagePath) {
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(),
"AddPicture", imagePath);
}
/** *//**
* 合并单元格
*
* @param tableIndex
* @param fstCellRowIdx
* @param fstCellColIdx
* @param secCellRowIdx
* @param secCellColIdx
*/
public void mergeCell(int tableIndex, int fstCellRowIdx, int fstCellColIdx,
int secCellRowIdx, int secCellColIdx) {
// 所有表格
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
.toDispatch();
Dispatch fstCell = Dispatch.call(table, "Cell",
new Variant(fstCellRowIdx), new Variant(fstCellColIdx))
.toDispatch();
Dispatch secCell = Dispatch.call(table, "Cell",
new Variant(secCellRowIdx), new Variant(secCellColIdx))
.toDispatch();
Dispatch.call(fstCell, "Merge", secCell);
}
/** *//**
* 在指定的单元格里填写数据
*
* @param tableIndex
* @param cellRowIdx
* @param cellColIdx
* @param txt
*/
public void putTxtToCell(int tableIndex, int cellRowIdx, int cellColIdx,
String txt) {
// 所有表格
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
// 要填充的表格
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
.toDispatch();
Dispatch cell = Dispatch.call(table, "Cell", new Variant(cellRowIdx),
new Variant(cellColIdx)).toDispatch();
Dispatch.call(cell, "Select");
Dispatch.put(selection, "Text", txt);
}
/** *//**
* 在当前文档拷贝数据
*
* @param pos
*/
public void copy(String toCopyText) {
moveStart();
if (this.find(toCopyText)) {
Dispatch textRange = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(textRange, "Copy");
}
}
/** *//**
* 在当前文档粘帖剪贴板数据
*
* @param pos
*/
public void paste(String pos) {
moveStart();
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(textRange, "Paste");
}
}
/** *//**
* 在当前文档指定的位置拷贝表格
*
* @param pos 当前文档指定的位置
* @param tableIndex 被拷贝的表格在word文档中所处的位置
*/
public void copyTable(String pos,int tableIndex) {
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex))
.toDispatch();
Dispatch range = Dispatch.get(table, "Range").toDispatch();
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(textRange, "Paste");
}
}
/** *//**
* 在当前文档末尾拷贝来自另一个文档中的段落
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param tableIndex 被拷贝的段落在另一格文档中的序号(从1开始)
*/
public void copyParagraphFromAnotherDoc(String anotherDocPath,
int paragraphIndex) {
Dispatch wordContent = Dispatch.get(doc, "Content").toDispatch(); // 取得当前文档的内容
Dispatch.call(wordContent, "InsertAfter", "$selection$");// 插入特殊符定位插入点
copyParagraphFromAnotherDoc(anotherDocPath, paragraphIndex,
"$selection$");
}
/** *//**
* 在当前文档指定的位置拷贝来自另一个文档中的段落
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param tableIndex 被拷贝的段落在另一格文档中的序号(从1开始)
* @param pos 当前文档指定的位置
*/
public void copyParagraphFromAnotherDoc(String anotherDocPath,
int paragraphIndex, String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch paragraphs = Dispatch.get(doc2, "Paragraphs").toDispatch();
Dispatch paragraph = Dispatch.call(paragraphs, "Item",
new Variant(paragraphIndex)).toDispatch();
Dispatch range = Dispatch.get(paragraph, "Range").toDispatch();
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}
/** *//**
* 在当前文档指定的位置拷贝来自另一个文档中的表格
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param tableIndex 被拷贝的表格在另一格文档中的序号(从1开始)
* @param pos 当前文档指定的位置
*/
public void copyTableFromAnotherDoc(String anotherDocPath, int tableIndex,
String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch tables = Dispatch.get(doc2, "Tables").toDispatch();
Dispatch table = Dispatch.call(tables, "Item",
new Variant(tableIndex)).toDispatch();
Dispatch range = Dispatch.get(table, "Range").toDispatch();
Dispatch.call(range, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}
/** *//**
* 在当前文档指定的位置拷贝来自另一个文档中的图片
*
* @param anotherDocPath 另一个文档的磁盘路径
* @param shapeIndex 被拷贝的图片在另一格文档中的位置
* @param pos 当前文档指定的位置
*/
public void copyImageFromAnotherDoc(String anotherDocPath, int shapeIndex,
String pos) {
Dispatch doc2 = null;
try {
doc2 = Dispatch.call(documents, "Open", anotherDocPath)
.toDispatch();
Dispatch shapes = Dispatch.get(doc2, "InLineShapes").toDispatch();
Dispatch shape = Dispatch.call(shapes, "Item",
new Variant(shapeIndex)).toDispatch();
Dispatch imageRange = Dispatch.get(shape, "Range").toDispatch();
Dispatch.call(imageRange, "Copy");
if (this.find(pos)) {
Dispatch textRange = Dispatch.get(selection, "Range")
.toDispatch();
Dispatch.call(textRange, "Paste");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (doc2 != null) {
Dispatch.call(doc2, "Close", new Variant(saveOnExit));
doc2 = null;
}
}
}
3.实践中遇到的一些bug和修正方式:
3-1).jacob-1.14.3.jar是在jdk1.5以上的环境运行,如果你要其运行在jkd1.4.2下,需改源码,重新编译,这里有个自己编译好的jacob-1.14.3.jar,这里不能上传附件,需要可以向我要qq:278698582。
3-2).在win2000,win2003下可能要装vcredist_x86.exe,下载地址:http://download.microsoft.com/download/e/1/c/e1c773de-73ba-494a-a5ba-f24906ecf088/vcredist_x86.exe
3-3)服务器上需要安装word
3-4)我在运行的程序的时候,第一次成功,第二次会导致程序崩溃,最体原因也不清楚,应该启用windows线程问题,最后解决方法是:wordObject.safeRelease();
axc.safeRelease();
ComThread.Release();// 释放com线程。
全部释放下,同时在public static ActiveXComponent axc = new ActiveXComponent("Word.Application");
启动线性时候axc.safeRelease();
axc = new ActiveXComponent("Word.Application");// decalre word
相关推荐
本文主要探讨如何使用Java-JACOB来创建和操作Word文档。 首先,使用JACOB之前,确保你的系统中已经安装了Microsoft Office,并且配置了相应的COM组件。JACOB本身是一个开源项目,可以在SourceForge上找到...
提供的几个HTML文件分别涵盖了不同的操作示例,如“使用Jacob输出word文档”展示了如何创建一个新的Word文档并写入内容,而“java操作word宏”则涉及如何执行Word文档中的宏。 总之,Jacob为Java开发者提供了强大的...
在这个“Jacob操作Word完整代码实例”中,我们将深入探讨如何使用Jacob来实现对Word文档的各种操作。 首先,为了使用Jacob,你需要在你的项目中添加Jacob的jar文件。这个库通常可以从其官方网站或者其他开源仓库...
总结来说,这个项目是一个基于Java和Jacob的桌面应用,主要用于操作Word文档,如创建表格和设置字体。项目采用了三层架构,进行了代码重构,且经过了实际测试,保证了功能的稳定性和可靠性。如果你需要进一步了解...
Java使用Jacob库通过Word模板生成Word文档是一种常见的技术实践,特别是在需要自定义生成大量结构化报告的场景下。本项目实例提供了一个完整的解决方案,可以直接在MyEclipse环境中运行。下面将详细讲解这个项目的...
在编程实践中,通过JACOB调用Word宏的代码,可以将Word文档处理的自动化操作集成到Java应用中。这不仅适用于文档自动生成,还适用于与Word交互的多种自动化任务,例如邮件合并、文档内容更新等。开发者应熟练掌握...
Java使用Jacob库通过模板生成Word文档是一个常见的技术实践,尤其在企业级应用中,这种技术常用于批量生成报告、合同等文档。Jacob全称为Java Advanced COM Bridge,它为Java提供了与COM组件交互的能力,让我们可以...
具体来说,就是通过JACOB创建一个指向Word应用程序的引用,然后通过该引用操作Word文档,最后保存为PDF格式。 #### 二、示例代码分析 下面是一段具体的Java代码示例,用于演示如何使用JACOB将Word文档转换为PDF...
标题中的“jacob操作实例+lib”指的是使用Jacob库在Java中进行Microsoft Office文档操作的实践案例和相关库文件。Jacob(Java and .NET Bridge)是一个开源Java库,它允许Java应用程序调用.NET组件,包括对Microsoft...
总的来说,Java通过jacob库操作Microsoft Word是一种跨平台技术的实践,使得Java开发者能够利用COM接口处理Word文档,实现自动化办公、数据导入导出、报告生成等功能。不过,需要注意的是,这种方法仅适用于Windows...
标题中的“Jawin”和“Jacob”是两个在IT领域中用于与Microsoft Office应用程序交互的库,特别是针对Word文档处理。Jawin是一个Java接口,它允许Java应用程序调用Windows API,从而能够操作Microsoft Office应用程序...
在Word文档生成的场景中,我们可以使用Jacob来创建、操作或者修改Word文档。例如,通过Jacob,你可以打开一个现有的Word文档,插入新的文本、图片,设置样式,甚至执行复杂的宏命令。 2. **FreeMarker**:...
**Jacob API文档及使用方法** Jacob(Java COM Bridge)是一个开源Java库,它允许Java程序与...对于需要在Java项目中与Windows原生应用程序交互的场景,如自动化办公文档处理、PDF操作等,Jacob是一个值得考虑的工具。
### jacob调用Word代码详解 #### 一、前言 在进行自动化办公或文档处理时,经常会遇到需要与Microsoft Word交互的需求。...通过以上内容的学习与实践,可以熟练掌握使用JACOB进行Word文档操作的方法,提高工作效率。
总结,Java操作Word文档,特别是在合同制作中使用书签插值,是一个实用且高效的技术。通过Apache POI或JACOB库,可以实现文本动态替换,自动化文档生成,显著提升工作效率。在实践中,结合具体的业务需求,可以构建...
总结,JACOB作为一个连接Java与COM的强大工具,为开发者提供了灵活的接口,使得在Java平台上操作Windows应用程序成为可能。通过深入学习其源码和实践应用,开发者可以更好地理解和利用这一技术,提升工作效率,解决...
总结,"jacob乱码原因解释"涉及到的关键知识点包括:文件编码理解,Java I/O操作,Jacob API的正确使用,Office文档元数据处理,字符集兼容性,以及潜在的兼容性问题。理解和解决这些问题对于顺利进行Office到HTML的...
3. **与Word交互**: 使用Jacob操作Word文档,包括打开、创建、保存文档,插入文本,设置样式,处理表格和图片等。 4. **与Excel交互**: 如何读取和写入Excel数据,创建和操作工作表,应用公式,图表处理等。 5. **...
在实际应用中,使用Jacob读取或操作Word文档时需注意以下几点: 1. **兼容性问题**:确保使用的JRE版本与Jacob DLL的版本兼容。 2. **性能考量**:虽然Jacob提供了便利,但频繁的跨语言调用可能会影响性能,特别是...
- 数据提取:从Word文档中提取特定信息,如表格数据,保存到其他格式文件。 - 定时任务:通过Windows任务计划程序定期运行VBA宏,完成定期备份、邮件发送等功能。 VBA编程API对于提升Word的使用效率、自动化重复性...