我用VB.Net (VS2010)开发了一个安装了Office2010专业版的WinForm应用程序,它是64位Windows7平台。该程序打开一个.doc和.rtf格式的文档,并尝试将其保存为htm格式。我使用以下命令:
暗淡的字符串as sFilePath = "C:\ABC\file.doc“
Dim oApp As New Microsoft.Office.Interop.Word.Application
Dim oDoc As New Microsoft.Office.Interop.Word.Document
Dim sTempFileName As String = System.IO.Path.GetTempFileName()
oDoc = oApp.Documents.Open(sFilePath)
oApp.Visible = False
oDoc = oApp.ActiveDocument
oDoc.SaveAs2(sTempFileName, FileFormat:=WdSaveFormat.wdFormatHTML,CompatibilityMode:=Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2007)
oDoc.Close()
oApp.Quit()
oDoc = Nothing
oApp = Nothing在开发PC上开发和运行一切正常,但当我将其发布为脱机安装,并将其部署到装有Windows XP和Office2007的客户端PC上时,它在oDoc.SaveAs2行上显示错误,并且程序崩溃。我已经用谷歌搜索了很多,但还是找不到解决方案。谁能尽快帮帮我
发布于 2012-03-29 05:19:27
From MSDN
SaveAs2
此方法出现在面向.NET Framework4的Word 2007项目的IntelliSense中。但是,不能在Word 2007项目中使用此属性
顺便说一句,如果你在这个网站上搜索,你会在你的问题here中找到答案
您可以使用以下代码检查安装在用户PC上的当前Word的版本:
string v = _myWordApp.Version;
switch(v)
{
case "7.0":
case "8.0":
case "9.0":
case "10.0":
_myWordDoc.SaveAs2000(ref _documentFile, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing);
break;
case "11.0":
case "12.0"
_myWordDoc.SaveAs(ref _documentFile, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing, ref _nothing);
case "14.0"
_myWordDoc.SaveAs2(ref _documentFile, ref WdSaveFormat.wdFormatHTML,
ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing, ref _nothing,
ref _nothing, ref _nothing, ref _nothing,
ref Microsoft.Office.Interop.Word.WdCompatibilityMode.wdWord2007);
break;
default:
errorText = "Not able to get Word Version"
break;
} 对于C#代码,很抱歉,但它很容易翻译。
https://stackoverflow.com/questions/9915617
复制相似问题