1

所以我有 Wonderware Archestra IDE 4.1。基本上是 2015 年服务器上最新最好的

我有一个名为 WordControls 的 C# 类库,它是在我的笔记本电脑上的 Visual Studio 2015 中创建的。当我构建它时,版本是一个同名的 dll 文件。

我将 dll 文件复制并粘贴到服务器的 Documents 文件夹中,它应该就像将鼠标移动到左上角并向下钻取一样简单:Galaxy -> Import -> Client Control

然后从那里选择我创建的 dll 文件,然后单击确定。然后在默认情况下再次单击确定。最后通过导入过程。除了将文件导入之外,我得到了一些稍微不同的东西:

“正在处理文件 WordControls.dll....从 1 个文件中导入了 0 个对象”

它无法导入dll,我不知道为什么。我之前在 2014 Archestra 和 Visual Studio 2013 上的工作中已经完成了它,所以我似乎无法弄清楚我做错了什么。

有没有人有使用 Archestra IDE 的客户端控制方面的经验?

当我查看 SMC 记录器时,我收到以下两个警告:

Microsoft.Office.Interop.Word,版本=15.0.0.0,文化=中性,PublicKeyToken=71e9bce111e9429c 依赖文件不存在。

在 C:\Users\vegeto18\Documents\WordControls.dll 中找不到控件。

除了我的程序确实使用 Microsoft.Office.Interop.Word 来处理 MS 文档并且服务器没有 MS Office(与Intouch 查看应用程序)。

第二部分我不确定如何解释,因为这是我从笔记本电脑复制 dll 并将其粘贴到该文件夹​​后所在的位置。

这将是我的代码:

    using System;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.Word;
    using System.IO;

    namespace WordControls
    {
        public partial class DocBrowser : Form
        {
            private System.Windows.Forms.WebBrowser webBrowser1;
            delegate void ConvertDocumentDelegate(string fileName);

            public DocBrowser()
            {
                InitializeComponent();

                // Create the webBrowser control on the UserControl. 
                // This code was moved from the designer for cut and paste
                // ease. 
                webBrowser1 = new System.Windows.Forms.WebBrowser();

                webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
                webBrowser1.Location = new System.Drawing.Point(0, 0);
                webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
                webBrowser1.Name = "webBrowser1";
                webBrowser1.Size = new System.Drawing.Size(532, 514);
                webBrowser1.TabIndex = 0;

                Controls.Add(webBrowser1);

                // set up an event handler to delete our temp file when we're done with it. 
                webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;

            }

            private void Form1_Load(object sender, EventArgs e)
            {
                var url = "http://qualityworkbench/ivscripts/qwbcgi.dll/docfetchraw?db=live&id=1090";

                LoadDocument(url);
            }

            string tempFileName = null;

            public void LoadDocument(string fileName)
            {
                // Call ConvertDocument asynchronously. 
                ConvertDocumentDelegate del = new ConvertDocumentDelegate(ConvertDocument);

                // Call DocumentConversionComplete when the method has completed. 
                del.BeginInvoke(fileName, DocumentConversionComplete, null);
            }

            void ConvertDocument(string fileName)
            {
                object m = System.Reflection.Missing.Value;
                object oldFileName = (object)fileName;            
                object readOnly = (object)false;
                Microsoft.Office.Interop.Word.Application ac = null;

                try
                {
                    // First, create a new Microsoft.Office.Interop.Word.ApplicationClass.
                    ac = new Microsoft.Office.Interop.Word.Application();

                    // Now we open the document.
                    Document doc = ac.Documents.Open(ref oldFileName, ref m, ref readOnly,
                        ref m, ref m, ref m, ref m, ref m, ref m, ref m,
                         ref m, ref m, ref m, ref m, ref m, ref m);

                    // Create a temp file to save the HTML file to. 
                    tempFileName = GetTempFile("html");

                    // Cast these items to object.  The methods we're calling 
                    // only take object types in their method parameters. 
                    object newFileName = (object)tempFileName;

                    // We will be saving this file as HTML format. 
                    object fileType = (object)WdSaveFormat.wdFormatHTML;

                    // Save the file. 
                    doc.SaveAs(ref newFileName, ref fileType,
                        ref m, ref m, ref m, ref m, ref m, ref m, ref m,
                        ref m, ref m, ref m, ref m, ref m, ref m, ref m);

                }
                finally
                {
                    // Make sure we close the application class. 
                    if (ac != null)
                        ac.Quit(ref readOnly, ref m, ref m);
                }
            }

            void DocumentConversionComplete(IAsyncResult result)
            {
                // navigate to our temp file. 
                webBrowser1.Navigate(tempFileName);
            }

            void webBrowser1_DocumentCompleted(object sender,
                WebBrowserDocumentCompletedEventArgs e)
            {
                if (tempFileName != string.Empty)
                {
                    // delete the temp file we created. 
                    File.Delete(tempFileName);

                    // set the tempFileName to an empty string. 
                    tempFileName = string.Empty;
                }
            }

            string GetTempFile(string extension)
            {
                // Uses the Combine, GetTempPath, ChangeExtension, 
                // and GetRandomFile methods of Path to 
                // create a temp file of the extension we're looking for. 
                return Path.Combine(Path.GetTempPath(),
                    Path.ChangeExtension(Path.GetRandomFileName(), extension));
            }

        }
    }
4

1 回答 1

1

我的代码没有问题,这是我的项目类型。我在 Visual Studio 上将其作为 Window Forms Application 编写。我应该使用窗口窗体用户控件。这最终解决了我的问题。

于 2016-06-10T13:17:37.083 回答