81,091
社区成员
发帖
与我相关
我的任务
分享
/**
* 向 document 中插入文本内容
*
* @param textToInsert
* 插入的文本内容
*/
public void insertText(String textToInsert) {
// 在指定的位置插入文本内容
Dispatch.put(selection, "Text", textToInsert);
// 取消选中,应该就是移动光标
Dispatch format = Dispatch.get(selection, "ParagraphFormat").toDispatch();
// 设置段落格式为首行缩进2个字符
Dispatch.put(format, "CharacterUnitFirstLineIndent", new Variant(2));
Dispatch.call(selection, "MoveRight", new Variant(1), new Variant(1));
//moveRight(1);
Dispatch.call(selection, "TypeParagraph");// 插入一个空行
//Dispatch.call(selection, "MoveUp");
//moveDown(1);
}
/**
* 插入标题
* @param num 标题编号
* @param level 标题级别:-2:一级标题;-3:二级标题;-4:三级标题;-5:四级标题
* @param text 标题题目
*/
public void insertTitle(String num, int level, String text) {
Dispatch activeDocument = Dispatch.get(word, "ActiveDocument").toDispatch();
//Dispatch.call(selection, "TypeParagraph");// 插入一个空行
//moveDown(1);
Dispatch.put(selection, "Text", num + " " + text);
Dispatch style = Dispatch.call(activeDocument, "Styles", new Variant(level)).toDispatch();;
Dispatch.put(selection, "Style", style);
moveRight(1);
Dispatch.call(selection, "TypeParagraph");// 插入一个空行
//moveDown(1);
}
/**
* 向 document 中插入文本内容
*
* @param textToInsert
* 插入的文本内容
*/
public void insertText(String textToInsert) {
// 在指定的位置插入文本内容
Dispatch.put(selection, "Text", textToInsert);
// 取消选中,应该就是移动光标
Dispatch format = Dispatch.get(selection, "ParagraphFormat").toDispatch();
// 设置段落格式为首行缩进2个字符
Dispatch.put(format, "CharacterUnitFirstLineIndent", new Variant(2));
Dispatch.call(selection, "MoveRight", new Variant(1), new Variant(1));
//moveRight(1);
Dispatch.call(selection, "TypeParagraph");// 插入一个空行
//Dispatch.call(selection, "MoveUp");
//moveDown(1);
}
/**
* 插入标题
* @param num 标题编号
* @param level 标题级别:-2:一级标题;-3:二级标题;-4:三级标题;-5:四级标题
* @param text 标题题目
*/
public void insertTitle(String num, int level, String text) {
Dispatch activeDocument = Dispatch.get(word, "ActiveDocument").toDispatch();
//Dispatch.call(selection, "TypeParagraph");// 插入一个空行
//moveDown(1);
Dispatch.put(selection, "Text", num + " " + text);
Dispatch style = Dispatch.call(activeDocument, "Styles", new Variant(level)).toDispatch();;
Dispatch.put(selection, "Style", style);
moveRight(1);
Dispatch.call(selection, "TypeParagraph");// 插入一个空行
//moveDown(1);
}
[/quote]
谢谢~我去试试哈