Java如何操作OpenOffice创建一个.doc文件,并且向这个文件输入值呢?
求高手指点。
求高手指点。
解决方案 »
- 本人想用JAVA编写个类似QQ的即时通讯软件,应该学些什么呢?望各位前辈能指点一下,晚辈在这里先拜谢了~~
- 怪了!!jsp 值转换出问题
- web开发用什么编码好?gbk?gb2312?utf-8?
- 404错误?servlet生成不了!
- Tomcat下怎样动态编译类?
- 请问大家谁有做过java邮件服务器
- JBUILDER发布项目时候的怪问题!~进来有分!
- 我如果不把jsp网页程序放在root目录下,请问我哪做的不对啊?
- 数据库问题!帮忙看看!!
- 如何得到当前jsp页面的名字?(可给100)
- java 初始化问题
- 过滤器中用request.getRequestDisPatcher().forward()问题,在线求解
throws java.lang.Exception {
String loadUrl = "private:factory/" + docType;
mxRemoteServiceManager = this.getRemoteServiceManager();
Object desktop = mxRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", mxRemoteContext);
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime
.queryInterface(XComponentLoader.class, desktop);
PropertyValue[] loadProps = new PropertyValue[0];
return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0,
loadProps);
} 4.得到 XTextDocument XComponent xEmptyWriterComponent = newDocComponent("swriter"); XTextDocument mxDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,
xEmptyWriterComponent);5. 得到一个文档的引用XText mxDocText = mxDoc.getText();6. 得到文档的属性列表 XPropertySet mxDocProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, mxDoc); 7. 建立光标,用来插入新的内容。XTextCursor mxDocCursor = mxDocText.createTextCursor(); XSentenceCursor xSentenceCursor = (XSentenceCursor) UnoRuntime
.queryInterface(XSentenceCursor.class, mxDocCursor);
XWordCursor xWordCursor = (XWordCursor) UnoRuntime.queryInterface(
XWordCursor.class, mxDocCursor); 8.得到光标属性列表 XPropertySet xCursorProps = (XPropertySet) UnoRuntime .queryInterface(XPropertySet.class, mxDocCursor);9.设置插入文字格式 xCursorProps.setPropertyValue("CharFontName", "宋体");
xCursorProps.setPropertyValue("CharWeight", new Float(FontWeight.BOLD));
xCursorProps.setPropertyValue("CharHeight", new Float(10.5));
// 居中显示
xCursorProps.setPropertyValue("ParaAdjust", com.sun.star.style.ParagraphAdjust.CENTER);10.在该光标处插入信息mxDocText.insertString(xSentenceCursor, “Hello World", true); 11. 保存的关键代码 protected void storeDocComponent(XComponent xDoc, String storeUrl)
throws java.lang.Exception { XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
XStorable.class, xDoc);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "FilterName";
storeProps[0].Value = "MS Word 97"; openOfficeJavaLogger.debug("... store \"" + xDoc.toString() + "\" to \"" + storeUrl
+ "\"."); xStorable.storeAsURL(storeUrl, storeProps);
}这篇教程写的不错,分享一下呵呵