POI API Implementation problem

hi..
I'm trying to read a .docx file using apache poi api methods.. But i'm facing a few problems..
Can anyone suggest me the changes to be made in this code??
    package apiole;
    import java.io.*;
    import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
    public class Apiole {
    public static void main(String[] args) throws IOException {
    File f = new File("D:\\vishal\\java_projects\\doc.docx");
    InputStream in = new FileInputStream(f);
    String test = extractText(in);
    System.out.print("text: "+test);
    }
    public static String extractText(InputStream in) {
    XWPFDocument doc = new XWPFDocument(in);
    XWPFWordExtractor ex = new XWPFWordExtractor(doc);
    String text = ex.getText();
    return text;
    }
    }

Replies

  • Vishal Sharma
    Vishal Sharma
    no response??? ๐Ÿ˜ฒ
    anyway, problem solved...........
  • Kaustubh Katdare
    Kaustubh Katdare
    Vishal0203
    no response??? ๐Ÿ˜ฒ
    anyway, problem solved...........
    Why not share the answer so that others who're facing the problem will know how to solve it? ๐Ÿ˜€

    I'm sorry to hear that the question didn't get any response.
  • Vishal Sharma
    Vishal Sharma
    The_Big_K
    Why not share the answer so that others who're facing the problem will know how to solve it? ๐Ÿ˜€

    I'm sorry to hear that the question didn't get any response.
    Okay!!
    So, the above program doesn't work because I've not imported another archive..

    import org.apache.poi.xwpf.usermodel.XWPFDocument;

    this is present in poi-ooxml-....-.jar (not mentioning the full name, its big ๐Ÿ˜› )
    you need to add this archive in the library (I used netbeans) as a part of project.
    This is the basic thing.. and the code that works fine is as below!

    package apiole;
     
    import java.io.*;
    import org.apache.poi.xwpf.usermodel.XWPFDocument;
    import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
     
    public class Apiole {
        public static void main(String[] args) throws IOException {
          File f = new File("D:\\vishal\\java_projects\\doc.docx");
          InputStream in = new FileInputStream(f);
          String test = extractText(in);
          System.out.print("text: "+test);
        }
       
        public static String extractText(InputStream in) throws IOException {
            XWPFDocument doc = new XWPFDocument(in);
        XWPFWordExtractor ex = new XWPFWordExtractor(doc);
        String text = ex.getText();
        return text;
        }
    }
    

You are reading an archived discussion.

Related Posts

So, finally countdown is over on Canonical website & another good news for Ubuntu lovers. Ubuntu has announced that they'll be releasing OS for Tablets named as Ubuntu For Tablets....
On Monday, Finally public version of Linux Kernel 3.8 is released with many positive changes which is keeping intel developers interested for next Kernel update i.e. Kernel 3.9 For overall...
Nvidia's Geforce GTX TITAN which is built with GK110 GPU (GK110 is said to be closest to graticular limit to present lithography technology) includes : 2,688 CUDA Cores 4,500 Giga...
If the mathematical calculations of Higgs Boson particle is correct, tem billion years from now, the universe will disappear at the speed of light, replaced by the strange alternative dimension,...
i need some information about surge current arrestors. . . . . .