Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How to write code for writing fields into word documents using POI

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to write code for writing fields into word documents using POI

    Hello All,

    I tried

    package com.hcl;
    import java.io.*;

    import org.apache.poi.hwpf.HWPFDocument;
    import org.apache.poi.hwpf.usermodel.*;
    import org.apache.poi.poifs.filesystem.*;

    public class WordDocCreation {

    public static void main(String[] args) throws IOException
    {
    File file = new File("E:\\kalpana\\test1.doc");

    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
    HWPFDocument doc =new HWPFDocument(fs);

    Range range = doc.getRange();

    CharacterRun run = range.insertBefore("1. Hello World!!! It works well!!!");
    run.setBold(true);
    run.setItalic(true);
    run.setCapitalized(true);
    OutputStream out = new FileOutputStream("sample2.doc");
    doc.write(out);
    out.flush();
    out.close();
    }
    }

    But it gives an error as

    Exception in thread "main" java.lang.NoSuchMethodError: org.apache.poi.poifs.filesystem.POIFSFileSystem.ge tRoot()Lorg/apache/poi/poifs/filesystem/DirectoryNode;
    at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocume nt.java:146)
    at com.hcl.WordDocCreation.main(WordDocCreation.java: 15)



    Please suggest me...............
    Looking forward for ur reply.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: How to write code for writing fields into word documents using POI

    I'm moving this thread. Please read this: This Forum is for Saying Hi, not for Asking Technical Questions (READ BEFORE POSTING)

    Also, please use the highlight tags when posting code.

    Does the method you're trying to use actually exist? Are you sure? Check the parameters, capitalization, everything.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need Help Writing Exception code.
    By USCPaddler in forum Exceptions
    Replies: 4
    Last Post: November 10th, 2011, 05:45 PM
  2. java code to split text documents into paragraphs and sentences
    By draksha in forum Java Theory & Questions
    Replies: 5
    Last Post: August 17th, 2011, 05:06 AM
  3. writing java code help
    By jaisan72980 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 12th, 2011, 02:39 PM
  4. Reading the size (height and width) of word documents
    By pradeep_das in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 7th, 2010, 09:58 AM
  5. Trouble writing some code...help?
    By bChEos in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 7th, 2010, 07:54 PM