/**
* 读取DOC图片
* @param docPath
*/
public static void readDocPicture(String docPath){
try {
FileInputStream in = new FileInputStream(docPath);
HWPFDocument doc = new HWPFDocument(in);//载入文档
//取得文档中字符的总数
int length = doc.characterLength();
//创建图片容器
PicturesTable pTable = doc.getPicturesTable();
for(int i = 0; i < length-1; i++){
Range range = new Range(i, i+1, doc);
CharacterRun cr = range.getCharacterRun(0);
if(pTable.hasPicture(cr)){
//提取图片
Picture pic = pTable.extractPicture(cr, false);
String afileName = pic.suggestFullFileName();
OutputStream out = new FileOutputStream(new File("D:" + File.separator + afileName));
pic.writeImageContent(out);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
* 读取DOC图片
* @param docPath
*/
public static void readDocPicture(String docPath){
try {
FileInputStream in = new FileInputStream(docPath);
HWPFDocument doc = new HWPFDocument(in);//载入文档
//取得文档中字符的总数
int length = doc.characterLength();
//创建图片容器
PicturesTable pTable = doc.getPicturesTable();
for(int i = 0; i < length-1; i++){
Range range = new Range(i, i+1, doc);
CharacterRun cr = range.getCharacterRun(0);
if(pTable.hasPicture(cr)){
//提取图片
Picture pic = pTable.extractPicture(cr, false);
String afileName = pic.suggestFullFileName();
OutputStream out = new FileOutputStream(new File("D:" + File.separator + afileName));
pic.writeImageContent(out);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}