SaveAs2 For Word 2010 不适用于装有 Word 2007 的客户端 PC [英] SaveAs2 For Word 2010 not working with Client PC having Word 2007

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

问题描述

我使用安装了 Office 2010 Professional 的 VB.Net (VS2010) 开发了一个 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:

Dim sFilePath as String = "C:ABCfile.doc"

Dim sFilePath as String = "C:ABCfile.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 行上出现错误,并且程序崩溃.我已经用谷歌搜索了足够多,但找不到解决方案.有人请尽快帮助我

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

另存为2
此方法出现在面向 .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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆