/**
*
* 通过WordExtractor读取Word文件<br>
* @param is
* @return
* @throws IOException
* @author:珞珈搬砖工
* @date:last updated time 2016年9月7日
*/
public static WordExtractor extract(InputStream is) throws IOException{
WordExtractor extractor = new WordExtractor(is);
return extractor;
}
/**
*
* 通过HWPFDocument读取Word文件<br>
* @param is
* @return
* @throws IOException
* @author:珞珈搬砖工
* @date:last updated time 2016年9月7日
*/
public static HWPFDocument read(InputStream is)throws IOException{
HWPFDocument doc = new HWPFDocument(is);
return doc;
}
/**
*
* 通过HWPFDocument的文件模板导出<br>
* @param path
* @param dataMap
* @throws Exception
* @author:珞珈搬砖工
* @date:last updated time 2016年9月7日
*/
public static void write(String path,Map<String,String> dataMap) throws Exception {
HWPFDocument doc = new HWPFDocument(new FileInputStream(path));
Range range = doc.getRange();
for(String key:dataMap.keySet()){
String replace = String.format("${%s}",key);
range.replaceText(replace , dataMap.get(key));
}
doc.write(new FileOutputStream(path));
}