【问题标题】:SaveAs2 For Word 2010 not working with Client PC having Word 2007SaveAs2 For Word 2010 不适用于具有 Word 2007 的客户端 PC
【发布时间】:2012-03-28 21:04:27
【问题描述】:

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

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 行上出现错误,并且程序崩溃。我已经用谷歌搜索了足够多的东西,但找不到解决方案。有人请尽快帮助我

【问题讨论】:

    标签: vb.net visual-studio-2010 ms-word ms-office


    【解决方案1】:

    From MSDN

    另存为2
    此方法出现在以 .NET Framework 4 为目标的 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# 代码感到抱歉,但它很容易翻译。

    【讨论】:

    • 感谢基于 Office 版本的Save 方法的澄清!我得到了RPC_E_SERVERFAULT,因为我使用了不正确的SaveAs 方法。
    猜你喜欢
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多