日期:2014-05-18  浏览次数:20830 次

请问如何利用后绑定WORD的方式处理文档中的边框属性
C# code

            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            Document doc = null;

            object missing = System.Reflection.Missing.Value;

            object filename = System.Windows.Forms.Application.StartupPath + @"\EmrEditor.html";
            object readOnly = false;
            object isVisible = true;
            object index = 0;
            IDataObject data = null;

            try
            {
                doc = app.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);

                doc.ActiveWindow.Selection.WholeStory();
                doc.ActiveWindow.Selection.Copy();

                data = Clipboard.GetDataObject();
            }
            finally
            {
                if (doc != null)
                {
                    object docType = WdNewDocumentType.wdNewBlankDocument;

                    Document d = app.Documents.Add(ref missing, ref missing, ref docType, ref missing);

                    d.ActiveWindow.Selection.PasteAndFormat(WdRecoveryType.wdPasteDefault);

                    if (d.Tables.Count > 0)
                    {
                        d.Tables[1].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
                        d.Tables[1].Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone;
                    }

                    filename = @"d:\word.pdf";
                    object fileFormat = WdSaveFormat.wdFormatPDF;

                    d.SaveAs(ref filename, ref fileFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

                    d = null;

                    doc.Close(ref missing, ref missing, ref missing);
                    doc = null;

                    GC.Collect();

                    if (app != null)
                    {
                        object saveOptions = WdSaveOptions.wdDoNotSaveChanges;
                        app.Quit(ref saveOptions, ref missing, ref missing);
                        app = null;
                    }
                }
            }



  这段WINFORM中的代码主要作用是把程序目录下的HTML文档通过WORD打开后,并利用WORD自带的命令将文档最外层的边框去除,然后保存成PDF文档;但是,因为采用的是直接引用WORD组件的方式,所以在打包安装到客户机的时候要求客户机安装与开发机器上相同的OFFICE软件。
  现在的问题是,如果我想通过后绑定WORD的方法,即采用
C# code

            Type wordType = Type.GetTypeFromProgID("Word.Application");
            Object word = System.Activator.CreateInstance(wordType);
            Object documents = wordType.InvokeMember("Documents", BindingFlags.GetProperty, null, word, null);


这种方法来处理上面的程序的时候,导出成PDF文件可能在低版本的OFFICE上无实现,但想请问一下各位高人
C# code

                    if (d.Tables.Count > 0)
                    {
                        d.Tables[1].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
                        d.Tables[1].Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone;
                    }


这段代码如果利用后绑定的方法实现。

------解决方案--------------------
http://seanli888.blog.51cto.com/345958/112268
------解决方案--------------------
就知道 VSTO可以。
------解决方案--------------------
后期绑定是可以的,你可以检测一下word版