2008-05-13
jcom生成一个word文件
关键字: jcom
jcom生成,你可以定义字体的样式
public synchronized void createWord(String filePath, String text,
String fontName, String fontSize, Boolean fontBold, int align) {
ReleaseManager rm = new ReleaseManager();
IDispatch docApp = null;
try {
docApp = new IDispatch(rm, "Word.Application");
IDispatch documents = (IDispatch) docApp.get("Documents");
documents.method("add", null);
IDispatch selection = ((IDispatch) docApp.get("Selection"));
IDispatch paragraphFormat = ((IDispatch) selection
.get("ParagraphFormat"));
paragraphFormat.put("Alignment", new Integer(align));// 对齐方式0:left,1:center,2:right
IDispatch font = ((IDispatch) selection.get("Font"));
font.put("name", fontName);
font.put("Size", fontSize);
font.put("Bold", fontBold);
selection.method("TypeText", new Object[] { text });
((IDispatch) docApp.get("ActiveDocument")).method("saveAs",
new Object[] { filePath, new Integer(0) });
} catch (JComException e) {
e.printStackTrace();
} finally {
try {
if (docApp != null) {
((IDispatch) docApp.get("ActiveDocument")).put("Saved",
new Boolean(true));
docApp.method("quit", null);
docApp = null;
}
rm.release();
rm = null;
} catch (JComException e) {
e.printStackTrace();
}
}
}
发表评论
- 浏览: 82079 次

- 详细资料
搜索本博客
我的相册
Image(029)
共 15 张
共 15 张
最新评论
-
hibernate annotation提供 ...
看了,没说怎么搞啊
-- by fourfire -
hibernate annotation提供 ...
晕..原来是这样.. 你去看看 http://docs.jboss.org/ej ...
-- by rain16881 -
hibernate annotation提供 ...
我也有这个问题
-- by rain16881 -
hibernate annotation提供 ...
自己搞定一个,为表增加comment的方法@Entity@Table(name= ...
-- by fourfire -
flex以remoteobject方式调 ...
配置方法类似,调用方法相同
-- by fourfire






评论排行榜