Word文档无法从IIS打开 [英] Word document not opening from IIS

查看:222
本文介绍了Word文档无法从IIS打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从Visual Studio运行应用程序时,Word文档正在打开,但是如果我从IIS(Same Machine)word文档打开的相同代码未打开显示此错误消息



When i run the application from Visual Studio, word document is opening, but the same code if i open from IIS( Same Machine ) word document is not opening showing this error message

"Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 8000401a.". 





以下是我用来打开和更新word文档的代码。





Following is the code i am using to open and update the word document.

Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.Document aDoc = null;

if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/CMS/Lease/temp.doc")))
{
    object readOnly = false;
    object isVisible = false;


    wordApp.Visible = false;

    aDoc = wordApp.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing,
        ref missing, ref missing, ref missing);

    aDoc.Activate();

    DataTable dtLease = BusinessLayer.CMS.Lease_Report(Convert.ToInt32(txtRec1.Text.Trim()), 1);
    if (dtLease.Rows.Count > 0)
    {
        DataRow dr = dtLease.Rows[0];
        string SupName = string.Empty;
        if (dr["First_name"] != DBNull.Value && dr["Surname"] != DBNull.Value)
        {
            this.FindAndReplace(wordApp, "<deptrep>", (string)dr["First_name"] + " " + (string)dr["Surname"]);
        }</deptrep>

推荐答案

Microsoft不鼓励在服务器设置中使用Office互操作。请参阅: http://support.microsoft.com/default.aspx?scid = kb; EN-US; q257757 #kb2 [ ^ ]。



更好的选择是使用Open XML SDK。请查看我过去的答案:

Microsot office Interop [ ^ ],

Question将单词转换为PDF,无需官方或openoffice [ ^ ],

如何从MS Visual Studio 2010中的添加引用添加microsoft excel 15.0对象库 [ ^ ]。


参见这个答案:使用Open XML创建基本的Excel工作簿 [ ^ ]。



祝你好运,

-SA
Microsoft discouraged the use of Office interop in server settings. Please see: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^].

A better alternative would be using Open XML SDK. Please see my past answers:
Microsot office Interop[^],
Question Convert word to PDF without offce or openoffice[^],
How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

See also this answer: Creating basic Excel workbook with Open XML[^].

Good luck,
-SA






将Word文件保存在某个位置,然后使用ActiveXObject通过javascript打开word文件从那个位置。



Hi,

Save the Word file in some location and then open the word file through javascript using ActiveXObject from that location.

function fnopen(str)
{
    var myapp = new ActiveXObject("Excel.Application")
    if(myapp != null)
    {
        myapp.visible = true;
        var filename = "filelocationstring;+ str + " ";
        myapp.workbooks.open(filename);
        this.window.close();
    }
    else
    {
        return false;
    }
}





谢谢

BS



Thanks
BS


这篇关于Word文档无法从IIS打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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