Save word file as html in java

隐身守侯 提交于 2019-12-09 01:40:43

问题


I try to save a word file as html using java. I save a word file as xml and its working for me

Runtime rt1 = Runtime.getRuntime();
rt1.exec("C:/Program Files/Microsoft Office/Office12/WINWORD.EXE /msaveasxml C:/myfolder/AB_00040.doc");

It save my doc file as xml file in the specific folder C:/myfolder and I view that xml file at C:/myfolder/AB_00040.xml

If i want to save the same file as html what can i do. Any one help

rt1.exec("C:/Program Files/Microsoft Office/Office12/WINWORD.EXE /msaveas??? C:/myfolder/AB_00040.doc");

Thanks in advance


回答1:


I found the answer with the hint of Zack Macomber i use a macro for convert word file to html file. I give the coding for that macro. Save the name of macro as "saveashtml"

Sub saveashtml()
Dim xmlname As String
xmlname = ActiveDocument.FullName
xmlname = Replace(xmlname, ".docx", ".html", , , vbTextCompare)
xmlname = Replace(xmlname, ".doc", ".html", , , vbTextCompare)
ActiveDocument.SaveAs FileName:=xmlname, FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
Application.Quit
End sub

You can execute this macro by

Runtime rt1 = Runtime.getRuntime();
rt1.exec("C:/Program Files/Microsoft Office/Office12/WINWORD.EXE /msaveashtml C:/myfolder/AB_00040.doc");

saveasxml macro coding

Sub saveasxml()
Dim xmlname As String
xmlname = ActiveDocument.FullName
xmlname = Replace(xmlname, ".docx", ".xml", , , vbTextCompare)
xmlname = Replace(xmlname, ".doc", ".xml", , , vbTextCompare)
ActiveDocument.SaveAs FileName:=xmlname, FileFormat:=wdFormatFlatXML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
End Sub


来源:https://stackoverflow.com/questions/13767796/save-word-file-as-html-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!