2

我尝试使用 java 将 word 文件保存为 html。我将 word 文件另存为 xml,它对我有用

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

它将我的 doc 文件保存为特定文件夹 C:/myfolder 中的 xml 文件,我在 C:/myfolder/AB_00040.xml 中查看该 xml 文件

如果我想将相同的文件保存为 html,我该怎么办。任何一个帮助

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

提前致谢

4

1 回答 1

5

我在 Zack Macomber 的提示下找到了答案,我使用宏将 word 文件转换为 html 文件。我给出了那个宏的编码。将宏名称另存为“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

您可以通过以下方式执行此宏

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

saveasxml 宏编码

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
于 2012-12-10T12:14:48.293 回答