Java2Word API

#This page shows how to use the elements of the API.

Introduction

This document will describe all elements of the Java2Word API and show how to use them. For each element, there are two sections "Description" and "Style - Superstylin".

"Description" is a short description of the element and has some sample code to illustrate the usage of the element.

The other section "Style - Superstylin" presents all possible styles applied to the elements with some examples as well.

We will start from the most popular/simple to the most complex.

The term "SuperStylin " means simply "Style". SuperStylin is the name I gave to the new Styling Framework. It is inspired on Groove Armada - Superstylin'

here is the link: http://www.youtube.com/watch?v=_z04eDMWOTw&feature=related

SuperStylin framework is still in development...

Remember that W2000 has been removed from the API. We will use only W2004 elements.



Document

Description

This is the main class of the API. Use this class to add other elements to the document. When you create an instance of Document.

 

IDocument
 myDoc 
=
new
 Document2004
();


myDoc
.
getBody
().
addEle
(
new
 Paragraph
(
"Hi! I am a paragraph"
));

The example above shows how to add one Paragraph to the body.

Body contains another two classes: Header, Footer.

Superstylin

Not implemented yet.

 


Heading

Description

Heading is the element utilized for creating hierarchy sections of the document. It is used to generate the document index. There are three levels of Headings: Heading1, Heading2 and Heading3.

See how to create a Heading1:

Heading1
 h1 
=
new
 Heading1
(
"Heading 111"
);

How to add it to the body of the Document:

myDoc
.
getBody
().
addEle
(
h1
);

Superstylin

  • Align (options: CENTER, LEFT(default), RIGHT, JUSTIFIED.

Element that will receive the style:

Heading1
 h1 
=
new
 Heading1
(
"Heading 111"
);

Create the new heading style object and configure it.

HeadingStyle
 headingStyle 
=
new
 HeadingStyle
();

 
headingStyle
. setAlign ( HeadingStyle . Align . CENTER );

Apply the style to the element:

h1
.
setStyle
(
headingStyle
);

 

  • Bold (boolean)
headingStyle
.
setItalic
(
true
);

  • Italic (boolean)
headingStyle
.
setBold
(
true
);

 


Paragraph

Description

The simplest way to create a paragraph is passing the content on the constructor:

Paragraph
 p01 
=
new 
Paragraph
(
"I am a paragraph"
);

Superstylin

If you want to superStylin your paragraph (or part of the paragraph), you have to use the new element called ParagraphPiece .

  • bold (boolean)
  • piece01
    .
    setStyle
    (
    style
    );
    
    
  • italic (boolean)
  • piece01
    .
    setStyle
    (
    style
    );
    
    
  • underline (boolean)
  • piece01
    .
    setUnderline
    (
    style
    );
    
    

ParagraphPiece should be utilized only inside a Paragraph.

Example of ParagraphPiece use:

ParagraphPieceStyle
 style 
=
new
 ParagraphPieceStyle
();

 

//create style object


style
. setBold ( true ); //set it up
style
. setBold ( true );

//create your Piece of Paragraph
ParagraphPiece piece01 = new ParagraphPiece ( "I love Java and Ruby" );

//apply the style to the Piece piece01 . setStyle ( style ); Paragraph p01 = new Paragraph ( piece02 );

Lets imagine the situation where you want to have part of the text in bold like this: I love Java and Ruby You want to make the word "ruby" in bold.

Class Paragraph has another constructor that accepts an array or varargs of Piece objects.

ParagrapPiecehStyle
 style 
=
new
 ParagraphPieceStyle
();

style
.
setBold
(
true
);

ParagraphPiece
 piece01 
=
new
 ParagraphPiece
(
"I love Java and "
);

ParagraphPiece
 piece02 
=
new
 ParagraphPiece
(
"Ruby"
);

piece02
.
setStyle
(
style
);

Paragraph
 p01 
=
new 
Paragraph
(
piece01
,
 piece02
);

Notice that paragraph has become just a wrapper to put together all little pieces of text. When you use the default constructor, the code creates one ParagraphPiece behind the scenes.

IMPORTANT: If you want to apply superStylin to the WHOLE paragraph, at the moment, you can only apply ALIGN. You have to use the class ParagraphStyle .

myPar
.
getStyle
().
setAlign
(
ParagraphStyle
.
Align
.
CENTER
);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值