各位大侠
小弟现在有一个问题需要提问,  我从数据库中把内容取出来之后, 我想直接写入到word 中。 这里我使用了poi 但是poi 能操作excel 的字体和颜色, 对word 操作颜色和字体我没有发现, 最好也能操作表格。 各位大侠给出下主意。  别的建议也好(不使用poi 的)

解决方案 »

  1.   

    关注,我也只是用poi操作Excel,没操作过Word.
      

  2.   

    利用JAVA语言深度控制Word
    http://www.dlmu.net/pe/computer/ShowArticle.asp?ArticleID=4044
    希望对你有帮助
      

  3.   

    我现在也正用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(); } }
      

  4.   

    哥们, 您好, 看了您的帖子, 但是我这里跑不起来, 如果可能的话, 请您给我打包发下邮件可以吗? [email protected] 我的邮箱地址, 谢谢。  连dll文件都要给发下, 要不会跑不起来的。。
      

  5.   

    Jacob可以处理这个问题,但是这个空间受平台的限制,只能在Windows系统上,因为运行Jacob要拷一个它自带的dll,而想Linux、Solaris这样的系统中没有dll这个概念