2016-10-19 1 views
0

doc를 docx로 변환해야하지만 JODConveter (OpenOffice)를 사용하고 있지만 불행히도 내 코드는 2074로 오류 코드가 있습니다. errorCode 의미 및 어떻게 고칠 수 있습니다.JODConveter를 사용하여 docx 로의 변환이 errorCode로 실패 함 : 2074

내 코드는 아래 공유 :

OfficeManager officeManager = 
    new DefaultOfficeManagerConfiguration().setOfficeHome(
    new File("C:\\Program Files (x86)\\OpenOffice4")).buildOfficeManager(); 

officeManager.start(); 

OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); 

DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx"); 
docx.setStoreProperties(DocumentFamily.TEXT, 
         Collections.singletonMap("FilterName", 
               "MS Word 2007 XML")); 

converter.convert(new File("C:\\localFiles\\abc.doc"), 
        new File("C:\\localFiles\\abc_new.docx")); 

officeManager.stop(); 

을 그러나 나는 위의 코드는 완벽하게 잘 작동 PDF로 DOCX에서 내 예상 파일의 확장자를 변경하는 경우.

+0

@Brutal_JL 당신이 어떤 입력을 제공 할 수 있습니까? –

답변

0

Windows에있는 것처럼 분명히 충실하게 변환 결과를 줄 수있는보다 안정적인 솔루션이 있습니다.

Office (2007 또는 이후 버전)를 설치하거나 Microsoft에서 호환 기능 팩을 다운로드하여 설치해야합니다 (아직 수행하지 않은 경우). 그럼 당신은 쉽게 다음 명령을 사용하여 .DOCX하는 .DOC에서 변환 할 수 있습니다

< 입력 파일>와 < 출력 파일> 완전한 경로 이름 일 필요
"C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme <input file> <output file> 

.

명령은 쉽게 for를 사용하여 여러 문서에 적용 할 수

:

for %F in (*.doc) do "C:\Program Files\Microsoft Office\Office12\wordconv.exe" -oice -nme "%F" "%Fx" 

아니면 자바에서 명령을 호출 할 수 있습니다 :

Process p = Runtime.getRuntime().exec(
    new String[] { 
     "C:\Program Files\Microsoft Office\Office12\wordconv.exe", 
     "-oice", 
     "-nme", 
     "C:\\localFiles\\abc.doc", 
     "C:\\localFiles\\abc_new.docx" 
    }); 
int exitVal = p.waitFor(); 
+0

나중에 docx를 XWPFDocument 문서로 변환하여 사용자 정의 속성을 주입해야하므로 doc을 docx로 변환해야합니다. 나는 당신이 제공 한 명령이 코드에서 실행될 수 있는지 확실하지 않습니다. –

+0

추신 : Office를 내 Windows 컴퓨터에 설치했습니다. –

관련 문제