在JAVA中 TextArea中有一段文字 我要把这段文字保存到一个Word文档中 有什么方法可以实现再进一步 一个Panel上面用g.drawXX()这种方法画出来的图样 我想以图片的形式保存到一个Word文档中(相当于在Word中插入一幅图片的效果) 用什么方法可以实现

解决方案 »

  1.   

    http://jakarta.apache.org/poi/index.html
      

  2.   

    poi可以实现word的读写,楼主去试一下吧
      

  3.   

    给一个例程:
    /* ====================================================================
       Licensed to the Apache Software Foundation (ASF) under one or more
       contributor license agreements.  See the NOTICE file distributed with
       this work for additional information regarding copyright ownership.
       The ASF licenses this file to You under the Apache License, Version 2.0
       (the "License"); you may not use this file except in compliance with
       the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
    ==================================================================== */
            package org.apache.poi.hwpf;import junit.framework.*;public class AllTests
      extends TestCase
    {  public AllTests(String s)
      {
        super(s);
      }  public static Test suite()
      {
        TestSuite suite = new TestSuite();
        suite.addTestSuite(org.apache.poi.hwpf.model.TestCHPBinTable.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.
                           TestDocumentProperties.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.
                           TestFileInformationBlock.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestFontTable.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestPAPBinTable.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestPlexOfCps.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestSectionTable.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestStyleSheet.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestTextPieceTable.class);
        suite.addTestSuite(org.apache.poi.hwpf.model.TestListTables.class);
        return suite;
      }
    }
      

  4.   

    自己写肯定很麻烦,有现成的项目poi可以用http://jakarta.apache.org/poi/index.html
      

  5.   

    这是我写的一段代码 把一个字符串写到Word中import java.io.*;import org.apache.poi.poifs.filesystem.DirectoryEntry;
    import org.apache.poi.poifs.filesystem.DocumentEntry;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class WriteWordDemo
    {   
    public static void main(String[] args)
        {   
            WriteWord write = new WriteWord();
           
            write.writeWordFile("D:\\a.doc", "aaaa\naaaaaa\naaaaaaaa\naaaa");
        }
    }   class WriteWord
    {
    public boolean writeWordFile(String path, String content) 
        {   
            boolean w = false;   
            try 
            {   
    byte b[] = content.getBytes();   
                   
                ByteArrayInputStream bais = new ByteArrayInputStream(b);   
          
                POIFSFileSystem fs = new POIFSFileSystem();   
                DirectoryEntry directory = fs.getRoot();   
          
                DocumentEntry de = directory.createDocument("WordDocument", bais);   
          
                FileOutputStream ostream = new FileOutputStream(path);   
          
                fs.writeFilesystem(ostream);   
                   
                bais.close();   
                ostream.close();   
          
            } 
            catch (IOException e) 
            {   
                e.printStackTrace();   
            }   
          
            return w;   
        }
    }为什么打开的时候提示"需要安装转换器才能正确显示该文件"?
    怎么写才能正常显示啊?