2010无法与具有Word

2010无法与具有Word

本文介绍了SaveAs2 For Word 2010无法与具有Word 2007的客户端PC一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用VB.Net(VS2010)开发了安装有Office 2010 Professional的WinForm应用程序,它是64位Windows 7平台.该程序将打开一个.doc和.rtf格式的文档,然后尝试将其保存为htm格式.我正在使用以下命令:

I have developed a WinForm Application with VB.Net (VS2010) having Office 2010 Professional Installed, and it is 64-bit Windows 7 Platform. The program opens a .doc and .rtf format document, and attempts to save it in htm format. I am using following commands:

将sFilePath设置为String ="C:\ ABC \ file.doc"

Dim sFilePath as String = "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和Office 2007的客户端PC上时,oDoc.SaveAs2行会出错,并且程序崩溃.我已经用Google搜索了很多,但是找不到解决方案.有人请尽快帮助我

All goes fine with development and running on development PC, but when I publish it for offline installation, and deploy it on Client PC having Windows XP with Office 2007, it gives error on oDoc.SaveAs2 line, and program crashes. I have googled enough but could not find a solution to it. Somebody please help me ASAP

推荐答案

来自MSDN

SaveAs2
此方法出现在以.NET Framework 4为目标的Word 2007项目中的IntelliSense中.但是,此属性不能在Word 2007项目中使用

SaveAs2
This method appears in IntelliSense in Word 2007 projects that target the .NET Framework 4. However, this property cannot be used in Word 2007 projects

顺便说一句,如果您在此站点上搜索,则会找到问题所在的响应

By the way, if you search on this site you find the response at your problem here

您可以使用以下代码检查在用户PC上安装的当前Word的版本:

You could check the version of the current Word installed on the user PC using this code:

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#代码很容易翻译.

Sorry for the C# code, but it's easy to translate.

这篇关于SaveAs2 For Word 2010无法与具有Word 2007的客户端PC一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:27