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

推荐订阅源

Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
WordPress大学
WordPress大学
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
博客园 - 司徒正美
J
Java Code Geeks
博客园 - 叶小钗
美团技术团队
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Cloudflare Blog
腾讯CDC
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
I
InfoQ
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
博客园_首页
D
Docker
U
Unit 42
Attack and Defense Labs
Attack and Defense Labs
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Help Net Security
A
About on SuperTechFans
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
P
Privacy International News Feed
P
Proofpoint News Feed
F
Full Disclosure
G
Google Developers Blog
小众软件
小众软件
Security Latest
Security Latest
The GitHub Blog
The GitHub Blog
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
Vercel News
Vercel News

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