各位大侠
小弟现在有一个问题需要提问, 我从数据库中把内容取出来之后, 我想直接写入到word 中。 这里我使用了poi 但是poi 能操作excel 的字体和颜色, 对word 操作颜色和字体我没有发现, 最好也能操作表格。 各位大侠给出下主意。 别的建议也好(不使用poi 的)
小弟现在有一个问题需要提问, 我从数据库中把内容取出来之后, 我想直接写入到word 中。 这里我使用了poi 但是poi 能操作excel 的字体和颜色, 对word 操作颜色和字体我没有发现, 最好也能操作表格。 各位大侠给出下主意。 别的建议也好(不使用poi 的)
解决方案 »
- 鬼编程..GUI
- [Java编程]金额的中文大写形式
- jvm的问题.
- 请教关于MP4的TAG信息
- 问一个简单的问题,关于字符数组转换成字符串的.
- JAVA 初学者一个小问题
- 新手:最近用到JFrame,但是好象Frame也有同样的功能,请高手指点?
- 请教contentPane设置
- 請教Jtable的使用,如何編程插入一行,如何設置和取得任意單元格的數据?最好可以給個例程序.
- 初学者请大家帮忙!!!
- 如何在jsp页面实现分页功能,而点击删除之后页码不会乱掉
- 请教:什么原因Exception in thread "main" java.lang.NoSuchMethodError: Point.pointNum()I
http://www.dlmu.net/pe/computer/ShowArticle.asp?ArticleID=4044
希望对你有帮助
通过属性来设置字体和颜色给你个代码片段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(); } }