poi操作word,能控制字体和颜色

转帖、摘自:http://topic.csdn.net/u/20081211/15/64547f4c-6fc8-4a20-8131-ba18d7e7b902.html 

 

1 ,new doc :C://blank.doc
2 ,run application

-----------------------

public static void main(String[] args){
try{

FileInputStream in = new FileInputStream("C://blank.doc");
HWPFDocument doc = new HWPFDocument(in);
Range range = doc.getRange();
CharacterProperties props = new CharacterProperties();

// Set the font size in half points
Range currentRange = range;

// Slowly increase the font size
for (int x = 8; x <= 64; x += 4){
// Set the half point size of the font
props.setFontSize(x);
currentRange = currentRange.insertAfter(" Hello World!", props);
}

// Display Bold characters
props.setBold(true);
currentRange = currentRange.insertAfter(" Bold", props);

// Display Italic characters
props.setItalic(true);
currentRange = currentRange.insertAfter(" Italic", props);

// Display charcters with a Double Strikethrough
props.setDoubleStrikeThrough(true);
currentRange = currentRange.insertAfter(" Double Strikethrough",props);

// Insert an empty paragraph for readability
currentRange = currentRange.insertAfter(new ParagraphProperties(),0);

// Reset the character properties
props = new CharacterProperties();
props.setFontSize(32);

// Create a numbered list
HWPFList list = new HWPFList(true, doc.getStyleSheet());
int listID = doc.registerList(list);

// Insert a list entry
currentRange = currentRange.insertAfter(new ParagraphProperties(),listID, 1, 0);
props.setIco24(0xff0000);
currentRange = currentRange.insertAfter(" Blue list entry", props);

// Insert another list entry
currentRange = currentRange.insertAfter(new ParagraphProperties(),listID, 1, 0);
props.setIco24(0xff);
props.setFontSize(38);
props.setCapitalized(true);
currentRange = currentRange.insertAfter(" larger red capitalized",props);

// Last list entry
currentRange = currentRange.insertAfter(new ParagraphProperties(),listID, 1, 0);
props.setIco24(0);
props.setCapitalized(false);
props.setCharacterSpacing(150);
props.setOutline(true);
currentRange = currentRange.insertAfter(" Large character spacing",props);

// Write out the document
FileOutputStream out = new FileOutputStream("C://hello.doc");
doc.write(out);
out.flush();
out.close();

}

catch (Throwable t)

{

t.printStackTrace();

}

}

转帖、摘自:http://topic.csdn.net/u/20081211/15/64547f4c-6fc8-4a20-8131-ba18d7e7b902.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值