我正在开发一个将.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 :(得分:0)
对于权利集合:
sheet.setRightToLeft()