jacob转换doc错误

时间:2015-06-09 03:07:42

标签: java jacob

我尝试将doc(docx)文件转换为最新jacob,jdk1.6的htmls,我的笔记本电脑是安装了Office 2007的Windows 7 X64专业版。     这是我的Java代码:

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // @Autowired
        String docfile = "d:\\CSMIS阿里云资源.docx";
        String htmlfile = "d:\\a.html";
        ActiveXComponent app = new ActiveXComponent("Word.Application");
        System.out.println("*******converting...*****");
        try {
            app.setProperty("Visible", new Variant(false));
            Dispatch docs = app.getProperty("Documents").toDispatch();
            Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method, 
                    new Object[]{docfile,new Variant(false),new Variant(true)}, 
                    new int[1]).toDispatch();
            Dispatch.invoke(doc, "SaveAs", Dispatch.Method, 
                    new Object[]{htmlfile,new Variant(8)}, new int[1]);
            Dispatch.call(doc, "Close", new Variant(false));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            app.invoke("Quit", new Variant[]{});
        }
        System.out.println("*********convert ended****");
    }

错误如下:

    An unexpected error has been detected by Java Runtime Environment:

    EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77c5df85, pid=7616, tid=6200


    Java VM: Java HotSpot(TM) Client VM (11.3-b02 mixed mode windows-x86)

    Problematic frame:
    C  [ntdll.dll+0x2df85]


    If you would like to submit a bug report, please visit:
    http://java.sun.com/webapps/bugreport/crash.jsp
    The crash happened outside the Java Virtual Machine in native code.
    See problematic frame for where to report the bug.


---------------  T H R E A D  ---------------

Current thread (0x0270f000):  JavaThread "main" [_thread_in_native, id=6200, stack(0x02460000,0x024b0000)]

siginfo: ExceptionCode=0xc0000005, writing address 0x0cc30000

Registers:
EAX=0x00000000, EBX=0x024af1b4, ECX=0x00000001, EDX=0x00000000
ESP=0x024af038, EBP=0x024af06c, ESI=0x765cb20c, EDI=0x0cc30000
EIP=0x77c5df85, EFLAGS=0x00010202

Top of Stack: (sp=0x024af038)
0x024af038:   024af0b4 7577521a 0cc30000 00000000
0x024af048:   00000004 00000001 765c6840 00683c14
0x024af058:   00000000 765c6892 00000000 00000007
0x024af068:   476cf088 024af484 757f00d4 024af1b0
0x024af078:   6825a95f 00000000 024af7a8 00000000
0x024af088:   00000000 76927190 0065d870 76836e8c
0x024af098:   00000006 024af0b0 00000000 769271a8
0x024af0a8:   76927190 0278fdb9 00000000 024af088 

Instructions: (pc=0x77c5df85)
0x77c5df75:   c8 c1 e0 10 03 c1 8b ca 83 e2 03 c1 e9 02 74 06
0x77c5df85:   f3 ab 85 d2 74 0a 88 07 83 c7 01 83 ea 01 75 f6 


Stack: [0x02460000,0x024b0000],  sp=0x024af038,  free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ntdll.dll+0x2df85]
C  [RPCRT4.dll+0xb00d4]
C  [OLEAUT32.dll+0x342c7]
C  [OLEAUT32.dll+0x34294]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  com.jacob.com.Dispatch.invokev(Ljava/lang/Object;Ljava/lang/String;III[Lcom/jacob/com/Variant;[I)Lcom/jacob/com/Variant;+0
j  com.jacob.activeX.ActiveXComponent.getProperty(Ljava/lang/String;)Lcom/jacob/com/Variant;+39
j  com.casco.test.Test.main([Ljava/lang/String;)V+41
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x0c9f1c00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=5744, stack(0x0d1f0000,0x0d240000)]
  0x0c9ef800 JavaThread "CompilerThread0" daemon [_thread_blocked, id=8212, stack(0x0d160000,0x0d1b0000)]
  0x0c9e2400 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=6492, stack(0x0d0d0000,0x0d120000)]
  0x0c9e2000 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=7140, stack(0x0cfd0000,0x0d020000)]
  0x0260fc00 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_blocked, id=8880, stack(0x0cf40000,0x0cf90000)]
  0x02602800 JavaThread "Attach Listener" daemon [_thread_blocked, id=8532, stack(0x0c990000,0x0c9e0000)]
  0x025f7c00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=8084, stack(0x0c900000,0x0c950000)]
  0x025bb400 JavaThread "Finalizer" daemon [_thread_blocked, id=3372, stack(0x0c870000,0x0c8c0000)]
  0x025ba000 JavaThread "Reference Handler" daemon [_thread_blocked, id=7424, stack(0x0c7e0000,0x0c830000)]
=>0x0270f000 JavaThread "main" [_thread_in_native, id=6200, stack(0x02460000,0x024b0000)]

Other Threads:
  0x025b6c00 VMThread [stack: 0x0c750000,0x0c7a0000] [id=4720]
  0x0c9f2c00 WatcherThread [stack: 0x0d280000,0x0d2d0000] [id=9096]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 960K, used 351K [0x04710000, 0x04810000, 0x04bf0000)
  eden space 896K,  32% used [0x04710000, 0x04757dd0, 0x047f0000)
  from space 64K, 100% used [0x047f0000, 0x04800000, 0x04800000)
  to   space 64K,   0% used [0x04800000, 0x04800000, 0x04810000)
 tenured generation   total 4096K, used 652K [0x04bf0000, 0x04ff0000, 0x08710000)
   the space 4096K,  15% used [0x04bf0000, 0x04c931a0, 0x04c93200, 0x04ff0000)
 compacting perm gen  total 12288K, used 3551K [0x08710000, 0x09310000, 0x0c710000)
   the space 12288K,  28% used [0x08710000, 0x08a87d20, 0x08a87e00, 0x09310000)
No shared spaces configured.

Dynamic libraries:
0x00400000 - 0x00424000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin\javaw.exe
0x77c30000 - 0x77db0000     C:\windows\SysWOW64\ntdll.dll
0x76c30000 - 0x76d40000     C:\windows\syswow64\kernel32.dll
0x77150000 - 0x77197000     C:\windows\syswow64\KERNELBASE.dll
0x770b0000 - 0x77150000     C:\windows\syswow64\ADVAPI32.dll
0x76f00000 - 0x76fac000     C:\windows\syswow64\msvcrt.dll
0x75620000 - 0x75639000     C:\windows\SysWOW64\sechost.dll
0x75740000 - 0x75830000     C:\windows\syswow64\RPCRT4.dll
0x755c0000 - 0x75620000     C:\windows\syswow64\SspiCli.dll
0x755b0000 - 0x755bc000     C:\windows\syswow64\CRYPTBASE.dll
0x76650000 - 0x76750000     C:\windows\syswow64\USER32.dll
0x772b0000 - 0x77340000     C:\windows\syswow64\GDI32.dll
0x772a0000 - 0x772aa000     C:\windows\syswow64\LPK.dll
0x77010000 - 0x770ad000     C:\windows\syswow64\USP10.dll
0x76b30000 - 0x76b90000     C:\windows\system32\IMM32.DLL
0x75640000 - 0x7570c000     C:\windows\syswow64\MSCTF.dll
0x73f00000 - 0x73f2c000     C:\Windows\SysWOW64\nvinit.dll
0x0f000000 - 0x0f006000     C:\Program Files (x86)\NVIDIA Corporation\CoProcManager\detoured.dll
0x6bd20000 - 0x6bd4b000     C:\Program Files (x86)\NVIDIA Corporation\CoProcManager\nvd3d9wrap.dll
0x76d40000 - 0x76edd000     C:\windows\syswow64\SETUPAPI.dll
0x77800000 - 0x77827000     C:\windows\syswow64\CFGMGR32.dll
0x765c0000 - 0x7664f000     C:\windows\syswow64\OLEAUT32.dll
0x767e0000 - 0x7693c000     C:\windows\syswow64\ole32.dll
0x76ff0000 - 0x77002000     C:\windows\syswow64\DEVOBJ.dll
0x6db80000 - 0x6db9f000     C:\Program Files (x86)\NVIDIA Corporation\CoProcManager\nvdxgiwrap.dll
0x73ec0000 - 0x73eff000     C:\PROGRA~2\Citrix\ICACLI~1\RSHook.dll
0x73e70000 - 0x73eb1000     C:\Program Files (x86)\Citrix\ICA Client\ShellHook.dll
0x773b0000 - 0x77407000     C:\windows\syswow64\SHLWAPI.dll
0x75970000 - 0x765bb000     C:\windows\syswow64\SHELL32.dll
0x68000000 - 0x68038000     C:\windows\system32\QIPCAP.DLL
0x7c340000 - 0x7c396000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\msvcr71.dll
0x6d8b0000 - 0x6db06000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\client\jvm.dll
0x714f0000 - 0x71522000     C:\windows\system32\WINMM.dll
0x71bb0000 - 0x71bfc000     C:\windows\system32\apphelp.dll
0x6d340000 - 0x6d348000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\hpi.dll
0x77560000 - 0x77565000     C:\windows\syswow64\PSAPI.DLL
0x6d430000 - 0x6d459000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\jdwp.dll
0x6d750000 - 0x6d756000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\npt.dll
0x6d860000 - 0x6d86c000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\verify.dll
0x6d3e0000 - 0x6d3ff000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\java.dll
0x6d8a0000 - 0x6d8af000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\zip.dll
0x6d2b0000 - 0x6d2b7000     D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin\dt_socket.dll
0x77570000 - 0x775a5000     C:\windows\syswow64\WS2_32.dll
0x76ef0000 - 0x76ef6000     C:\windows\syswow64\NSI.dll
0x70350000 - 0x70360000     C:\windows\system32\NLAapi.dll
0x6aa80000 - 0x6aa90000     C:\windows\system32\napinsp.dll
0x6aa60000 - 0x6aa72000     C:\windows\system32\pnrpnsp.dll
0x73010000 - 0x7304c000     C:\windows\System32\mswsock.dll
0x71130000 - 0x71174000     C:\windows\system32\DNSAPI.dll
0x6aa50000 - 0x6aa58000     C:\windows\System32\winrnr.dll
0x6e8a0000 - 0x6e8ad000     C:\windows\system32\wshbth.dll
0x73af0000 - 0x73b0c000     C:\windows\system32\IPHLPAPI.DLL
0x73ae0000 - 0x73ae7000     C:\windows\system32\WINNSI.DLL
0x707c0000 - 0x707f8000     C:\windows\System32\fwpuclnt.dll
0x71120000 - 0x71126000     C:\windows\system32\rasadhlp.dll
0x727b0000 - 0x727b5000     C:\windows\System32\wshtcpip.dll
0x10000000 - 0x10018000     D:\Java\jdk1.6.0_07\bin\jacob.dll
0x76ba0000 - 0x76c23000     C:\windows\syswow64\CLBCatQ.DLL
0x73cf0000 - 0x73d07000     C:\windows\system32\CRYPTSP.dll
0x73cb0000 - 0x73ceb000     C:\windows\system32\rsaenh.dll
0x73d10000 - 0x73d1e000     C:\windows\system32\RpcRtRemote.dll

VM Arguments:
jvm_args: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:8239 -Dfile.encoding=UTF-8 -Xbootclasspath/p:D:\Java\Myeclipse\Common\plugins\com.genuitec.eclipse.j2eedt.core_8.5.0.me201003231033\data\libraryset\EE_5\javaee.jar;D:\Java\Myeclipse\Common\plugins\com.genuitec.eclipse.j2eedt.core_8.5.0.me201003231033\data\libraryset\EE_5\jsf-impl.jar;D:\Java\Myeclipse\Common\plugins\com.genuitec.eclipse.j2eedt.core_8.5.0.me201003231033\data\libraryset\EE_5\jsf-api.jar;D:\Java\Myeclipse\Common\plugins\com.genuitec.eclipse.j2eedt.core_8.5.0.me201003231033\data\libraryset\EE_5\jstl-1.2.jar 
java_command: com.casco.test.Test
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=D:\Java\jdk1.6.0_07
PATH=D:\Java\Myeclipse\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\jre\bin;D:/Java/Myeclipse/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/bin/client;D:/Java/Myeclipse/Common/binary/com.sun.java.jdk.win32.x86_1.6.0.013/jre/bin;D:\csoft\app\60874\product\11.2.0\dbhome_1\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Lenovo\Fingerprint Manager Pro\;C:\Program Files\Condusiv Technologies\ExpressCache\;C:\Program Files (x86)\Common Files\Lenovo;C:\SWTOOLS\ReadyApps;D:\csoft\TortoiseSVN\bin;D:\Java\jdk1.6.0_07\bin;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\
USERNAME=60874
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows NT 6.1 Build 7601 Service Pack 1

CPU:total 4 (8 cores per cpu, 2 threads per core) family 6 model 5 stepping 1, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, ht

Memory: 4k page, physical 4194303k(2356048k free), swap 4194303k(4194303k free)

vm_info:用于windows-x86 JRE(1.6.0_13-b03)的Java HotSpot(TM)客户端虚拟机(11.3-b02),建于2009年3月9日01:15:24" java_re"使用MS VC ++ 7.1

时间:2015年6月9日星期二10:31:41 经过时间:1秒

1 个答案:

答案 0 :(得分:0)

如果要将doc / docx文件转换为HTML,可以尝试使用以下命令:

public static void wordToHtml(String docfile, String htmlfile)     
{     
    // word  
    ActiveXComponent app = new ActiveXComponent("Word.Application");     
    try    
    { //word  
        app.setProperty("Visible", new Variant(false));   
      Dispatch docs = app.getProperty("Documents").toDispatch();     
      //word  
        Dispatch doc = Dispatch.invoke(     
                docs,     
                "Open",     
                Dispatch.Method,     
                new Object[] { docfile, new Variant(false),     
                        new Variant(true) }, new int[1]).toDispatch();     
      //html  
        Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {     
                htmlfile, new Variant(8) }, new int[1]);     
      Variant f = new Variant(false);     
      Dispatch.call(doc, "Close", f);     
    }     
    catch (Exception e)     
    {     
        e.printStackTrace();     
    }     
    finally    
    {     
        app.invoke("Quit", new Variant[] {});     
    }     
}

已经使用了一段时间并且没有任何问题。

来源:http://html.programdevelop.com/628031/