2013-03-24 56 views
2

我正在開發一個將採用.doc或.docx文件作爲輸入的應用程序,並將它們的單詞提取到數據庫表中。如何在Java中使用Apache POI從.doc和.docx文件中提取從右到左的文本?

我爲此目的嘗試了Apache POI,併成功地使用從左到右的文本格式(例如英文)來處理文檔。

下面是代碼:

// FilterDOC Method Which Tacke A Document As Input and Return A Generic 
// List Withs Its Words 

public static void parseDoc(File SelectedFile, FileReader in) { 
try { 
     // Create a POI File System object 
     POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
       SelectedFile)); 

    // Create a document for this file 
    HWPFDocument doc = new HWPFDocument(fs); 

    // Create a WordExtractor to read the text of the word document 
      WordExtractor we = new WordExtractor(doc); 

     String ExtractedText = we.getText(); 

    // Removing New Empty Lines 
    String RemoveEmptyLines = ExtractedText.replaceAll("[\n\r]", ""); 

    // Filtering document of any symbols 
    String[] Wordlist = RemoveEmptyLines 
       .split("[:\\,\\.\\}\\?\\{\\[\\]\\‘\\_\\*\\&\\%\\#\\$\\@\\!\\~\\/\\//\\|\\?\\「\\:-\\;\\W\\s+]"); 

    List<String> lines = new ArrayList<String>(); 

     for (String line : Wordlist) { 

      if (line != null && !line.trim().isEmpty() 
        && !line.equals("\\W\\s+")) { 
       lines.add(line.trim()); 

      } 

     } 

     // output the document 
    for (String string : lines) { 

      System.out.println(string);} 
        in.close(); 



    } 

      catch (IOException e){ 
      System.out.println("IO Exception !!"+ e.getMessage());  } 
} 

如何使用與文件相同的庫從右到左的文本格式(例如,阿拉伯語)?

+0

你能否澄清的問題是什麼,你所看到的?沒有文字?不正確的字符?方向錯誤? – Gagravarr 2013-03-25 07:09:00

回答

0

對於從右到讓設置:

sheet.setRightToLeft() 
+0

我輸入我的代碼 那麼我該如何使用該行? – 2013-03-24 22:50:41

相關問題