| | | | |

Reading data from the .Doc file by using Apache POI api

this program simply explains how to read data from the MS wordfile(.DOC) line by line using Apache POI, what is Apache POI and what is the need i already explain in previous post, you can find that post here

for executing this program we need to download Apache POI api and make jar files  in classpath.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package multidocument;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;

/**
*
* @author vijay
*/
public class NewDocReader {
public static void main(String args[]) throws FileNotFoundException, IOException
{

File docFile=new File(“c:\multi\multi.doc”);   // file object was created
FileInputStream finStream=new FileInputStream(docFile.getAbsolutePath()); // file input stream with docFile
HWPFDocument doc=new HWPFDocument(finStream);// throws IOException and need to import org.apache.poi.hwpf.HWPFDocument;
WordExtractor wordExtract=new WordExtractor(doc); // import  org.apache.poi.hwpf.extractor.WordExtractor
String [] dataArray =wordExtract.getParagraphText();
// dataArray stores the each line from the document
for(int i=0;i<dataArray.length;i++)
{
System.out.println(“n–”+dataArray[i]);
// printing lines from the array
}
finStream.close(); //closing fileinputstream
}
}

Similar Posts

3 Comments

  1. Hi to all,
    I want to convert an .doc file to html format using POI in java.Here I am able to get an text and tables but Images are showing in a correct positions…
    is there any way to do this?

    Please respond to this…..

  2. Hi Kalyan,
    I am also tried for that but i didn’t get it finding number of pages and images Positions..

Leave a Reply

Your email address will not be published. Required fields are marked *