在Java中将Word文件另存为html [英] Save word file as html in java
问题描述
我尝试使用Java将Word文件另存为html.我将Word文件另存为xml,并且对我有用
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");
它将我的doc文件另存为xml文件到特定文件夹C:/myfolder中,然后我在C:/myfolder/AB_00040.xml中查看该xml文件
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
如果我想将相同的文件保存为html,我该怎么办.任何人帮助
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");
预先感谢
推荐答案
我用Zack Macomber的提示找到了答案,我使用宏将Word文件转换为html文件.我给出了该宏的编码.将宏的名称另存为"saveashtml"
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宏编码
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
这篇关于在Java中将Word文件另存为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!