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

推荐订阅源

博客园 - Franky
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
人人都是产品经理
人人都是产品经理
罗磊的独立博客
博客园 - 聂微东
雷峰网
雷峰网
量子位
美团技术团队
V
V2EX
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
The Cloudflare Blog
爱范儿
爱范儿
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
Jina AI
Jina AI

博客园 - 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);
    }
}