惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
爱范儿
爱范儿
Vercel News
Vercel News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
D
DataBreaches.Net
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
The Cloudflare Blog
宝玉的分享
宝玉的分享
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - N/A2011

Managing Hierarchical Data in MySQL php soapclient with wsse 转贴 MySQL Multiple Result Procs in PHP 转贴 jQuery Datepicker by Example 转贴 Using MySQL Stored Procedures with PHP mysql/mysqli/pdo php generate pdf ant + emma + junit Copy all files recursively from one folder to another RecursiveFileFinder 转贴: 怎样找第一份工作 PerformanceCounter in .net Trace in .net Logger in .net 转贴: 傅立叶级数(Fourier Series) 推导 CAS in .net Encrypting and Decrypting in .net Access Control List in .net User and Data Security in .net Unmanaged code in .net
open office (java)
N/A2011 · 2009-12-03 · via 博客园 - N/A2011

代码

import java.net.MalformedURLException;
import java.net.URISyntaxException;import com.sun.star.beans.*;
import com.sun.star.comp.helper.*;
import com.sun.star.frame.*;
import com.sun.star.lang.*;
import com.sun.star.text.*;
import com.sun.star.uno.*;
import com.sun.star.uno.Exception;
import com.sun.star.util.*;
import ooo.connector.BootstrapSocketConnector;public class Entry {
    
public static void main(String[] args) throws Exception, BootstrapException, URISyntaxException,
        MalformedURLException {
    
// connect to open office
    String oooExeFolder = "C:/Program Files/OpenOffice.org 3/program";
    XComponentContext xContext 
= BootstrapSocketConnector.bootstrap(oooExeFolder);
    com.sun.star.lang.XMultiComponentFactory xMCF 
= xContext.getServiceManager();
    Object oDesktop 
= xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
    XComponentLoader xCLoader 
= (com.sun.star.frame.XComponentLoader) UnoRuntime.queryInterface(
        com.sun.star.frame.XComponentLoader.
class, oDesktop);
    
// create document
    XComponent document = xCLoader.loadComponentFromURL("private:factory/swriter""_blank"0,
        
new PropertyValue[0]);
    XTextDocument xTextDocument 
= (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,
        document);
    XText xText 
= xTextDocument.getText();
    
// create a paragraph cursor
    XParagraphCursor xParagraphCursor = (XParagraphCursor) UnoRuntime.queryInterface(
        XParagraphCursor.
class, xText.createTextCursor());
    
// add some text
    xText.insertString(xText.getEnd(), "My First OpenOffice Document"false);
    
// style the paragraph
    XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
        xParagraphCursor);
    xPropertySet.setPropertyValue(
"ParaStyleName""Heading 1");
    
// add some text
    xText.insertString(xText.getEnd(), "rThis is the first line in my paragraph. "
        
+ "Some more text, just to add some text to this document. "false);
    xPropertySet.setPropertyValue(
"ParaStyleName""Text body");
    
// Add another heading paragraph
    xText.insertString(xText.getEnd(), "rSecond heading"false);
    xPropertySet.setPropertyValue(
"ParaStyleName""Heading 2");
    
// And another text body paragraph
    xText.insertString(xText.getEnd(), "rThis is the second normal paragraph."false);
    xPropertySet.setPropertyValue(
"ParaStyleName""Text body");
    
// save document
    XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
    PropertyValue[] storeProps 
= new PropertyValue[0];
    xStorable.storeAsURL(
"file:///C:/Documents and Settings/Ren/Desktop/wori.odt", storeProps);
    
// export document to pdf
    storeProps = new PropertyValue[1];
    storeProps[
0= new PropertyValue();
    storeProps[
0].Name = "FilterName";
    storeProps[
0].Value = "writer_pdf_Export";
    xStorable.storeToURL(
"file:///C:/Documents and Settings/Ren/Desktop/wori.pdf", storeProps);
    
// close document
    XCloseable xcloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document);
    xcloseable.close(
false);
    }
}