Skip to content

Instantly share code, notes, and snippets.

@sjyun
Created December 9, 2013 14:50
Show Gist options
  • Save sjyun/7873365 to your computer and use it in GitHub Desktop.
Save sjyun/7873365 to your computer and use it in GitHub Desktop.
poi를 이용해서 좌측컬럼 읽기
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.TableRow;
public class WordPoi {
/*
* @Param String word file Path
* @Return Map
* */
public static Map<String, String> ReadLeftWordColumn(String docPath){
final File target = new File(docPath);
InputStream fis;
Map<String, String> fields = new HashMap<>();
try {
fis = new FileInputStream(target);
HWPFDocument doc = new HWPFDocument(fis);
Range range = doc.getRange();
TableIterator itr = new TableIterator(range);
while(itr.hasNext()){
Table table = itr.next();
for (int i = 0; i < table.numRows(); i++) {
TableRow row = table.getRow(i);
TableCell cell = row.getCell(0);
System.out.println( cell.getParagraph(0).text() );
fields.put(cell.getParagraph(0).text(), "String");
}
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
return fields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment