2015-05-12 98 views

回答

1

這樣做,我希望它會幫助你..!

public static void readMyDocument(String fileName){ 
    POIFSFileSystem fs = null; 
    try { 
     fs = new POIFSFileSystem(new FileInputStream(fileName)); 
     HWPFDocument doc = new HWPFDocument(fs); 

     /** Read the content **/ 
     readParagraphs(doc); 

     int pageNumber=1; 

     /** We will try reading the header for page 1**/ 
     readHeader(doc, pageNumber); 

     /** we will try reading the footer for page 1**/ 
     readFooter(doc, pageNumber); 


    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    } 

public static void readParagraphs(HWPFDocument doc) throws Exception{ 
    WordExtractor we = new WordExtractor(doc); 

    /**Get the total number of paragraphs**/ 
    String[] paragraphs = we.getParagraphText(); 
    System.out.println("Total Paragraphs: "+paragraphs.length); 

    for (int i = 0; i < paragraphs.length; i++) { 

     System.out.println("Length of paragraph "+(i +1)+": "+ paragraphs[i].length()); 
     System.out.println(paragraphs[i].toString()); 

    } 

} 

public static void readHeader(HWPFDocument doc, int pageNumber){ 
    HeaderStories headerStore = new HeaderStories(doc); 
    String header = headerStore.getHeader(pageNumber); 
    System.out.println("Header Is: "+header); 

} 

public static void readFooter(HWPFDocument doc, int pageNumber){ 
    HeaderStories headerStore = new HeaderStories(doc); 
    String footer = headerStore.getFooter(pageNumber); 
    System.out.println("Footer Is: "+footer); 

} 
+0

我需要將doc文件轉換爲html並帶註釋 – user1912427