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

rigger21 2008-12-11 03:18:18
各位大侠
小弟现在有一个问题需要提问, 我从数据库中把内容取出来之后, 我想直接写入到word 中。 这里我使用了poi 但是poi 能操作excel 的字体和颜色, 对word 操作颜色和字体我没有发现, 最好也能操作表格。 各位大侠给出下主意。 别的建议也好(不使用poi 的)。。。
...全文
1878 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
東北扫地僧 2009-09-03
  • 打赏
  • 举报
回复
Jacob可以处理这个问题,但是这个空间受平台的限制,只能在Windows系统上,因为运行Jacob要拷一个它自带的dll,而想Linux、Solaris这样的系统中没有dll这个概念
lankeabc 2009-01-27
  • 打赏
  • 举报
回复
没用好,......,还要再学习.
rigger21 2009-01-04
  • 打赏
  • 举报
回复
哥们, 您好, 看了您的帖子, 但是我这里跑不起来, 如果可能的话, 请您给我打包发下邮件可以吗? rigger21@126.com 我的邮箱地址, 谢谢。 连dll文件都要给发下, 要不会跑不起来的。。
songnian1983 2008-12-24
  • 打赏
  • 举报
回复
我现在也正用poi将无规则的word读成meteData 。真好遇到过这个问题
通过属性来设置字体和颜色

给你个代码片段

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();

}

}


yangkaixin1226 2008-12-20
  • 打赏
  • 举报
回复
up
bobskay 2008-12-20
  • 打赏
  • 举报
回复
利用JAVA语言深度控制Word
http://www.dlmu.net/pe/computer/ShowArticle.asp?ArticleID=4044
希望对你有帮助
shihp 2008-12-11
  • 打赏
  • 举报
回复
关注,我也只是用poi操作Excel,没操作过Word.
wqisch 2008-12-11
  • 打赏
  • 举报
回复
没用过,帮顶
zh2208 2008-12-11
  • 打赏
  • 举报
回复
没用过。。纯支持。。

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧