예제 #1
0
        public void Close(bool saveOnClose)
        {
            var saveOptions = saveOnClose ? WdSaveOptions.wdSaveChanges : WdSaveOptions.wdDoNotSaveChanges;

            _document.GetType()
            .InvokeMember("Close", BindingFlags.InvokeMethod, null, _document, new object[] { saveOptions });
        }
예제 #2
0
파일: wordHelp.cs 프로젝트: zxbe/EFX.Core
        public static bool WordToHtml(string wordFileName, string htmlFileName)
        {
            try
            {
                Object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = false;
                object    filename = wordFileName;
                _Document WordDoc  = WordApp.Documents.Open(ref filename, ref oMissing,
                                                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                // Type wordType = WordApp.GetType();
                // 打开文件
                Type docsType = WordApp.Documents.GetType();
                // 转换格式,另存为
                Type   docType      = WordDoc.GetType();
                object saveFileName = htmlFileName;
                docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc,
                                     new object[] { saveFileName, WdSaveFormat.wdFormatHTML });

                //保存
                WordDoc.Save();
                WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(false);
            }
        }