您的位置:首页 > 编程语言 > Java开发

永中Office二次开发_JAVA的二次开发2

2009-04-01 08:52 176 查看
概述:永中Office是使用JAVA开发,所以直接使用JAVA进行二次开发比较方便,但由于在客户端运行时一般使用VB、VC去调用,所以有必要将其封装成COM组件,以便其它语言调用。

今天继续先将JAVA的二次开发的第二部分调用实例进行说明:

(如果大家觉得好我就继续,如果觉得不好这第二篇文章就算结束了)

1.清除痕迹

public static boolean AcceptAllRevision(Document document)
{
document.acceptAllRevision();
return true;
}


2.在书签位置插入图片

public static boolean InsertPicToBookmark(Document document, String bookMarkName, String picPath, float width, float height)
{
BookMark bk = document.getBookmarks().get(bookMarkName);
if(bk == null)
return false;

InsertPicToTextRange(bk.getRange(), picPath, width, height, true);

return true;
}


3.在RANGE位置插入图片

public static boolean InsertPicToTextRange(TextRange range, String picPath, float width, float height, boolean isBefore)
{
if(width*height == 0)
{
if(isBefore)
range.insertPictureBefore(picPath);
else
range.insertPictureAfter(picPath);
}
else
{
if(isBefore)
range.insertPictureBefore(picPath, width, height);
else
range.insertPictureAfter(picPath, width, height);
}

return true;
}


4.书签位置插入文件

public static boolean InsertFileToBookmark(Document document, String bookMarkName, String filePath)
{
String t = filePath.toLowerCase();
if(!(t.contains(".doc") || t.contains(".rtf") || t.contains(".eio") || t.contains(".eit") || t.contains(".txt")))
return false;
BookMark bk = document.getBookmarks().get(bookMarkName);
if(bk == null)
return false;

document.setOffset(bk.getEndPosition());
document.insertDocument(2, filePath, null);

return true;
}


5.RANGE位置插入文件

public static boolean InsertFileToTextRange(Document document, TextRange range, String filePath)
{
String t = filePath.toLowerCase();
if(!(t.contains(".doc") || t.contains(".rtf") || t.contains(".eio") || t.contains(".eit") || t.contains(".txt")))
return false;
if(range==null)
return false;
document.setOffset(range.getEndOffset());
document.insertDocument(2, filePath, null);
return true;
}


6.插入表格

public static boolean InsertTableToDocument(Document document, TextRange range, String tableName, int rowCount, int columnCount)
{
if(range == null)
return false;

document.getTables().addTable(range, rowCount, columnCount, tableName, TableConstants.AUTOFIT_CONTENT, 0);

return true;
}


7.保护、解保护文档

public static boolean ProtectDocument(Document document, int protectType)
{
document.protect(protectType, DOCPASSWORD);
return true;
}

public static boolean UnprotectDocument(Document document)
{
document.unprotect(DOCPASSWORD);
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: