나는 워드 문서에서 주로 이미지, 테이블 및 특수 텍스트 (수식 등)의 데이터를 추출해야하는 작업을 수행하고 있습니다.이미지, 표, 공식 등 .docx 파일에서 데이터를 추출하는 방법은 무엇입니까?
웹에서 다운로드 한 단어 파일에서 이미지를 저장할 수 있지만 오류가 발생하는 것보다 동일한 코드를 내 .docx 파일에 적용 할 때. 같은 대한
코드는 잘못된 형식 오류를주고있다
//create file inputstream to read from a binary file
FileInputStream fs=new FileInputStream(filename);
//create office word 2007+ document object to wrap the word file
XWPFDocument docx=new XWPFDocument(fs);
//get all images from the document and store them in the list piclist
List<XWPFPictureData> piclist=docx.getAllPictures();
//traverse through the list and write each image to a file
Iterator<XWPFPictureData> iterator=piclist.iterator();
System.out.println(piclist.size());
while(iterator.hasNext()){
XWPFPictureData pic=iterator.next();
byte[] bytepic=pic.getData();
int i=0;
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(bytepic));
//captureimage(imag,i,flag,j);
if(imag != null)
{
ImageIO.write(imag, "jpg", new File("D:/imagefromword"+i+".jpg"));
}else{
System.out.println("imag is empty");
}
입니다. 그러나 나는 doc 파일을 바꿀 수 없다. 두 번째 위의 코드에 대해 더 많은 이미지를 하나 가지고 있고 저장할 때마다 저장할 때마다 이미지를 저장하고 있습니다. 3 개의 이미지가 있다고 가정하면 3 개의 이미지를 저장하지만 3 개의 이미지는 모두 최신 이미지가됩니다.
도움이 될 것입니다.
오류의 스택 추적을 추가하십시오. – Jens