首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Word 2010的SaveAs2无法与安装了Word 2007的客户端PC配合使用

Word 2010的SaveAs2无法与安装了Word 2007的客户端PC配合使用
EN

Stack Overflow用户
提问于 2012-03-29 05:04:28
回答 1查看 6.1K关注 0票数 5

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

暗淡的字符串as sFilePath = "C:\ABC\file.doc“

代码语言:javascript
复制
        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行上显示错误,并且程序崩溃。我已经用谷歌搜索了很多,但还是找不到解决方案。谁能尽快帮帮我

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-29 05:19:27

From MSDN

SaveAs2

此方法出现在面向.NET Framework4的Word 2007项目的IntelliSense中。但是,不能在Word 2007项目中使用此属性

顺便说一句,如果你在这个网站上搜索,你会在你的问题here中找到答案

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

代码语言:javascript
复制
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#代码,很抱歉,但它很容易翻译。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9915617

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档