各位大侠
小弟现在有一个问题需要提问, 我从数据库中把内容取出来之后, 我想直接写入到word 中。 这里我使用了poi 但是poi 能操作excel 的字体和颜色, 对word 操作颜色和字体我没有发现, 最好也能操作表格。 各位大侠给出下主意。 别的建议也好(不使用poi 的)
小弟现在有一个问题需要提问, 我从数据库中把内容取出来之后, 我想直接写入到word 中。 这里我使用了poi 但是poi 能操作excel 的字体和颜色, 对word 操作颜色和字体我没有发现, 最好也能操作表格。 各位大侠给出下主意。 别的建议也好(不使用poi 的)
解决方案 »
- 请问如何从文件中读double数据?
- 怎样在jtable的单元格中画一条对角线?
- 怎么样往一个已有的xml文档中追加内容呀
- 请问如何在一个非空文件后,追加写数据(用 FileWriter)
- 如何包*.jar包到入JBuilder中??
- 那里能下载java,j2ee的视频教程啊!指点一二。
- 我是新手,请多指教!
- 为什么这段代码要拉一下窗体才会现出按扭,要如何解决!
- 请高手们顺便进来看一眼,两个小问题!
- java求助关于arraylist 的问题
- 如何在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(); } }