コード例 #1
0
ファイル: DocHelper.cs プロジェクト: changweihua/FirstLog
        /// <summary>
        /// 需要转换的Word文档路径
        /// </summary>
        /// <param name="fileName">完整路径</param>
        /// <returns>HTML页面路径</returns>
        private static string WordToHtml(object fileName)
        {
            Word.Application word     = new Word.Application();
            Type             wordType = word.GetType();

            Word.Documents docs = word.Documents;

            //打开文件
            Type docsType = docs.GetType();

            Word.Document doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs, new object[] { fileName, true, true });

            //转换格式,另存
            Type   docType          = doc.GetType();
            string wordSaveFileName = fileName.ToString();
            string htmlSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.LastIndexOf(".") + 1) + "html";
            object saveFileName     = (object)htmlSaveFileName;

            docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
            docType.InvokeMember("Close", BindingFlags.InvokeMethod, null, doc, null);

            //退出Word
            wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);

            return(saveFileName.ToString());
        }
コード例 #2
0
ファイル: WordUtil.cs プロジェクト: sunbirdwyk/wyk-base
        ///<summary>
        /// 将Word文件转换为HTML文件
        ///</summary>
        ///<param name="source_path">Word文件路径(绝对)</param>
        ///<param name="target_path">生成的Html文件路径(绝对),路径的目录结构必须存在,否则保存失败</param>
        ///<returns>是否执行成功</returns>
        public static bool toHtml(string source_path, string target_path)
        {
            Word.Application wordApp  = new Word.Application();
            Type             wordType = wordApp.GetType();

            Word.Documents docs     = wordApp.Documents;
            Type           docsType = docs.GetType();

            try
            {
                if (File.Exists(target_path))
                {
                    File.Delete(target_path);
                }
                Word.Document doc     = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs, new Object[] { source_path, true, true });
                Type          docType = doc.GetType();
                docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { target_path, Word.WdSaveFormat.wdFormatFilteredHTML });
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, wordApp, null);
                try
                {
                    wordApp.Quit();
                }
                catch { }
                Thread.Sleep(3000);
            }
        }
コード例 #3
0
ファイル: EKWord.cs プロジェクト: xiaocaiyuen/ShuCMS
        /// <summary>
        /// 获取word 无格式的text文本
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string WordToText(string path)
        {
            string wordText = "";

            Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();//ApplicationClass();
            Microsoft.Office.Interop.Word.Document    WordDoc;
            Microsoft.Office.Interop.Word.Documents   docs = WordApp.Documents;

            Object oMissing = System.Reflection.Missing.Value;
            Type   wordType = WordApp.GetType();

            object fileName = path;

            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);

            wordText = WordDoc.Content.Text;

            WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
            WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
            GC.Collect();

            return(wordText);
        }
コード例 #4
0
        /// <summary>
        /// Word转成Html
        /// </summary>
        /// <param name="path">要转换的文档的路径</param>
        /// <param name="savePath">转换成html的保存路径</param>
        /// <param name="wordFileName">转换成html的文件名字</param>
        public static void Word2Html(string path, string savePath, string wordFileName)
        {
            MyWord.Application word = new MyWord.Application();
            Type wordType           = word.GetType();

            MyWord.Documents docs     = word.Documents;
            Type             docsType = docs.GetType();

            MyWord.Document doc = (MyWord.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { (object)path, true, true });
            try
            {
                Type   docType         = doc.GetType();
                string strSaveFileName = System.IO.Path.Combine(savePath, $"{wordFileName}.html");
                object saveFileName    = (object)strSaveFileName;
                docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, MyWord.WdSaveFormat.wdFormatFilteredHTML });
                docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
                wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
            }
            catch
            { }
            finally
            {
                doc  = null;
                docs = null;
                word = null;
            }
        }
コード例 #5
0
        public void UpdateLabels()
        {
            object wordBasic = _app.GetType().InvokeMember("WordBasic",
                                                           System.Reflection.BindingFlags.GetProperty,
                                                           null, _app, null);

            //witchcraft?
            wordBasic.GetType().InvokeMember("MailMergePropagateLabel",
                                             System.Reflection.BindingFlags.InvokeMethod,
                                             null, wordBasic, null);
        }
コード例 #6
0
        public object RunMacro(string macroName, string args = null)
        {
            List <object> arguments = new List <object> {
                macroName
            };
            object result = null;

            if (!string.IsNullOrEmpty(args))
            {
                arguments.AddRange(args.Split(','));
            }
            result = application.GetType().InvokeMember("Run", BindingFlags.InvokeMethod, null, this.application, arguments.ToArray());
            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Word转成Html
        /// </summary>
        /// <param name="path">要转换的文档的路径</param>
        /// <param name="savePath">转换成html的保存路径</param>
        /// <param name="wordFileName">转换成html的文件名字</param>
        public static void Word2Html(string path, string savePath, string wordFileName)
        {
            Word.Application word     = new Word.Application();
            Type             wordType = word.GetType();

            Word.Documents docs     = word.Documents;
            Type           docsType = docs.GetType();

            Word.Document doc             = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { (object)path, true, true });
            Type          docType         = doc.GetType();
            string        strSaveFileName = savePath + wordFileName + ".html";
            object        saveFileName    = (object)strSaveFileName;

            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
            docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
        }
コード例 #8
0
ファイル: ExcelService.cs プロジェクト: sorrymeika/PhotoPrint
        public static string WordToHtml(object wordfilename)
        {
            //在此处放置用户代码以初始化页面
            word.Application word     = new word.Application();
            Type             wordtype = word.GetType();

            word.Documents docs = word.Documents;
            //打开文件
            Type docstype = docs.GetType();

            word.Document doc = (word.Document)docstype.InvokeMember("open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new object[] { wordfilename, true, true });
            //转换格式,另存为
            Type   doctype          = doc.GetType();
            string wordsavefilename = wordfilename.ToString();
            string strsavefilename  = wordsavefilename.Substring(0, wordsavefilename.LastIndexOf('.')) + ".html";
            object savefilename     = (object)strsavefilename;

            doctype.InvokeMember("saveas", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { savefilename, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
            doctype.InvokeMember("close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
            // 退出 word
            wordtype.InvokeMember("quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
            return(savefilename.ToString());
        }
コード例 #9
0
ファイル: DocHelper.cs プロジェクト: changweihua/FirstLog
        /// <summary>
        /// 需要转换的Word文档路径
        /// </summary>
        /// <param name="fileName">完整路径</param>
        /// <returns>HTML页面路径</returns>
        private static string WordToHtml(object fileName)
        {
            Word.Application word = new Word.Application();
            Type wordType = word.GetType();
            Word.Documents docs = word.Documents;

            //打开文件
            Type docsType = docs.GetType();
            Word.Document doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs, new object[] { fileName, true, true });

            //转换格式,另存
            Type docType = doc.GetType();
            string wordSaveFileName = fileName.ToString();
            string htmlSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.LastIndexOf(".") + 1) + "html";
            object saveFileName = (object)htmlSaveFileName;
            docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
            docType.InvokeMember("Close", BindingFlags.InvokeMethod, null, doc, null);

            //退出Word
            wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);

            return saveFileName.ToString();
        }
コード例 #10
0
        /// <summary>
        /// word转成html
        /// </summary>
        /// <param name="wordFileName"></param>
        private string WordToHtml(object wordFileName)
        {
            //在此处放置用户代码以初始化页面
            Word.Application word     = new Word.Application();
            Type             wordType = word.GetType();

            Word.Documents docs = word.Documents;
            //打开文件
            Type docsType = docs.GetType();

            Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });
            //转换格式,另存为
            Type   docType          = doc.GetType();
            string wordSaveFileName = wordFileName.ToString();
            string sExt             = wordSaveFileName.Substring(wordSaveFileName.LastIndexOf('.'));
            string strSaveFileName  = wordSaveFileName.Substring(0, wordSaveFileName.Length - sExt.Length) + ".html";
            object saveFileName     = (object)strSaveFileName;

            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
            docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
            //退出 Word
            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
            return(saveFileName.ToString());
        }
コード例 #11
0
        public static ShortFormReport ReadWordFile(string wordFilePath)
        {
            if (FileHelper.FileInUsed(wordFilePath))
            {
                return(null);
            }
            ShortFormReport shortFormReport = new ShortFormReport();

            Word.Application wordApp = new Word.Application();
            object           unknow  = Type.Missing;

            wordApp.Visible       = false;
            wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
            Object file = wordFilePath;

            Word.Document doc = null;

            try
            {
                doc = wordApp.Documents.Open(ref file);
                string dataMenstrualCycle = doc.FormFields[11].Result;
                if (string.IsNullOrEmpty(dataMenstrualCycle))
                {
                    shortFormReport.DataMenstrualCycle = "0";
                }
                else if (dataMenstrualCycle.StartsWith("1 phase") || dataMenstrualCycle.StartsWith("phase 1") || dataMenstrualCycle.StartsWith("第一阶段") || dataMenstrualCycle.StartsWith("一期"))
                {
                    shortFormReport.DataMenstrualCycle = "1";// App.Current.FindResource("ReportContext_15").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("2 phase") || dataMenstrualCycle.StartsWith("phase 2") || dataMenstrualCycle.StartsWith("第二阶段") || dataMenstrualCycle.StartsWith("二期"))
                {
                    shortFormReport.DataMenstrualCycle = "2";//App.Current.FindResource("ReportContext_16").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("1 and 2 phase") || dataMenstrualCycle.StartsWith("第一和第二阶段") || dataMenstrualCycle.StartsWith("一期和二期"))
                {
                    shortFormReport.DataMenstrualCycle = "3";//App.Current.FindResource("ReportContext_17").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("dysmenorrhea") || dataMenstrualCycle.StartsWith("痛经"))
                {
                    shortFormReport.DataMenstrualCycle = "4";// App.Current.FindResource("ReportContext_18").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("missing") || dataMenstrualCycle.StartsWith("postmenopausal") || dataMenstrualCycle.StartsWith("postmenopause") || dataMenstrualCycle.StartsWith("绝经期"))
                {
                    shortFormReport.DataMenstrualCycle = "5";// App.Current.FindResource("ReportContext_19").ToString();
                    shortFormReport.DataMeanElectricalConductivity3        = "1";
                    shortFormReport.DataComparativeElectricalConductivity3 = "1";
                    shortFormReport.DataDivergenceBetweenHistograms3       = "1";
                }
                else if (dataMenstrualCycle.StartsWith("pregnancy") || dataMenstrualCycle.StartsWith("孕期"))
                {
                    shortFormReport.DataMenstrualCycle = "6";// App.Current.FindResource("ReportContext_20").ToString();
                    shortFormReport.DataMeanElectricalConductivity3        = "2";
                    shortFormReport.DataComparativeElectricalConductivity3 = "2";
                    shortFormReport.DataDivergenceBetweenHistograms3       = "2";
                }
                else if (dataMenstrualCycle.StartsWith("lactation") || dataMenstrualCycle.StartsWith("哺乳期"))
                {
                    shortFormReport.DataMenstrualCycle = "7";// App.Current.FindResource("ReportContext_21").ToString();
                    shortFormReport.DataMeanElectricalConductivity3        = "3";
                    shortFormReport.DataComparativeElectricalConductivity3 = "3";
                    shortFormReport.DataDivergenceBetweenHistograms3       = "3";
                }
                //shortFormReport.DataMenstrualCycle = doc.FormFields[11].Result;
                //shortFormReport.DataLeftChangesOfElectricalConductivity = doc.FormFields[15].Result;
                //shortFormReport.DataRightChangesOfElectricalConductivity = doc.FormFields[16].Result;
                //shortFormReport.DataLeftMammaryStruct = doc.FormFields[17].Result;
                //shortFormReport.DataRightMammaryStruct = doc.FormFields[18].Result;
                //shortFormReport.DataLeftLactiferousSinusZone = doc.FormFields[19].Result;
                //shortFormReport.DataRightLactiferousSinusZone = doc.FormFields[20].Result;
                //shortFormReport.DataLeftMammaryContour = doc.FormFields[21].Result;
                //shortFormReport.DataLeftMammaryContour = doc.FormFields[22].Result;

                //shortFormReport.DataLeftLocation = doc.FormFields[23].Result;
                //shortFormReport.DataRightLocation = doc.FormFields[24].Result;
                //shortFormReport.DataLeftNumber = doc.FormFields[25].Result;
                //shortFormReport.DataRightNumber = doc.FormFields[26].Result;
                //shortFormReport.DataLeftSize = doc.FormFields[27].Result;
                //shortFormReport.DataRightSize = doc.FormFields[28].Result;
                //shortFormReport.DataLeftShape = doc.FormFields[29].Result;
                //shortFormReport.DataRightShape = doc.FormFields[30].Result;
                //shortFormReport.DataLeftContourAroundFocus = doc.FormFields[31].Result;
                //shortFormReport.DataRightContourAroundFocus = doc.FormFields[32].Result;
                //shortFormReport.DataLeftInternalElectricalStructure = doc.FormFields[33].Result;
                //shortFormReport.DataRightInternalElectricalStructure = doc.FormFields[34].Result;
                //shortFormReport.DataLeftSurroundingTissues = doc.FormFields[35].Result;
                //shortFormReport.DataRightSurroundingTissues = doc.FormFields[36].Result;


                shortFormReport.DataLeftMeanElectricalConductivity1  = doc.FormFields[37].Result;
                shortFormReport.DataRightMeanElectricalConductivity1 = doc.FormFields[38].Result;
                shortFormReport.DataLeftMeanElectricalConductivity2  = doc.FormFields[39].Result;
                shortFormReport.DataRightMeanElectricalConductivity2 = doc.FormFields[40].Result;
                string dataMeanElectricalConductivity3 = doc.FormFields[41].Result;
                if (string.IsNullOrEmpty(dataMeanElectricalConductivity3))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "0";//"";
                }
                else if (dataMeanElectricalConductivity3.StartsWith("postmenopause") || dataMeanElectricalConductivity3.StartsWith("绝经后期"))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "1";// App.Current.FindResource("ReportContext_103").ToString();
                }
                else if (dataMeanElectricalConductivity3.StartsWith("pregnancy") || dataMeanElectricalConductivity3.StartsWith("妊娠"))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "2";// App.Current.FindResource("ReportContext_104").ToString();
                }
                else if (dataMeanElectricalConductivity3.StartsWith("lactation") || dataMeanElectricalConductivity3.StartsWith("哺乳期"))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "3";// App.Current.FindResource("ReportContext_105").ToString();
                }
                //ShortFormReport.DataMeanElectricalConductivity3 = doc.FormFields[41].Result;
                shortFormReport.DataLeftMeanElectricalConductivity3  = doc.FormFields[42].Result;
                shortFormReport.DataRightMeanElectricalConductivity3 = doc.FormFields[43].Result;

                shortFormReport.DataLeftComparativeElectricalConductivity1 = doc.FormFields[44].Result;
                //ShortFormReport.DataRightComparativeElectricalConductivity1 = doc.FormFields[44].Result;
                shortFormReport.DataLeftComparativeElectricalConductivity2 = doc.FormFields[45].Result;
                //ShortFormReport.DataRightComparativeElectricalConductivity2 = doc.FormFields[45].Result;
                shortFormReport.DataLeftComparativeElectricalConductivity3 = doc.FormFields[46].Result;
                //ShortFormReport.DataRightComparativeElectricalConductivity3 = doc.FormFields[46].Result;
                shortFormReport.DataLeftDivergenceBetweenHistograms1 = doc.FormFields[47].Result;
                //ShortFormReport.DataRightDivergenceBetweenHistograms1 = doc.FormFields[47].Result;
                shortFormReport.DataLeftDivergenceBetweenHistograms2 = doc.FormFields[48].Result;
                //ShortFormReport.DataRightDivergenceBetweenHistograms2 = doc.FormFields[48].Result;
                shortFormReport.DataLeftDivergenceBetweenHistograms3 = doc.FormFields[49].Result;
                //ShortFormReport.DataRightDivergenceBetweenHistograms3 = doc.FormFields[49].Result;

                shortFormReport.DataLeftPhaseElectricalConductivity  = doc.FormFields[54].Result;
                shortFormReport.DataRightPhaseElectricalConductivity = doc.FormFields[55].Result;

                shortFormReport.DataAgeElectricalConductivityReference = doc.FormFields[56].Result;

                string dataLeftAgeElectricalConductivity = doc.FormFields[57].Result;
                if (string.IsNullOrEmpty(dataLeftAgeElectricalConductivity))
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "0";// "";
                }
                else if (dataLeftAgeElectricalConductivity.StartsWith("<5"))
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataLeftAgeElectricalConductivity.StartsWith(">95"))
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }
                //ShortFormReport.DataLeftAgeElectricalConductivity = doc.FormFields[57].Result;
                string dataRightAgeElectricalConductivity = doc.FormFields[58].Result;
                if (string.IsNullOrEmpty(dataRightAgeElectricalConductivity))
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "0";// "";
                }
                else if (dataRightAgeElectricalConductivity.StartsWith("<5"))
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataRightAgeElectricalConductivity.StartsWith(">95"))
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }
                //ShortFormReport.DataRightAgeElectricalConductivity = doc.FormFields[58].Result;
                string dataExamConclusion = doc.FormFields[59].Result;
                if (string.IsNullOrEmpty(dataExamConclusion))
                {
                    shortFormReport.DataExamConclusion = "0";//"";
                }
                else if (dataExamConclusion.StartsWith("Pubertal Period") || dataExamConclusion.StartsWith("青春期"))
                {
                    shortFormReport.DataExamConclusion = "1";// App.Current.FindResource("ReportContext_116").ToString();
                }
                else if (dataExamConclusion.StartsWith("Early childbearing age") || dataExamConclusion.StartsWith("育龄早期"))
                {
                    shortFormReport.DataExamConclusion = "2";// App.Current.FindResource("ReportContext_117").ToString();
                }
                else if (dataExamConclusion.StartsWith("Childbearing age") || dataExamConclusion.StartsWith("育龄期"))
                {
                    shortFormReport.DataExamConclusion = "3";// App.Current.FindResource("ReportContext_118").ToString();
                }
                else if (dataExamConclusion.StartsWith("Perimenopausal period") || dataExamConclusion.StartsWith("围绝经期"))
                {
                    shortFormReport.DataExamConclusion = "4";// App.Current.FindResource("ReportContext_119").ToString();
                }
                else if (dataExamConclusion.StartsWith("Postmenopausal period") || dataExamConclusion.StartsWith("Postmenopause period") || dataExamConclusion.StartsWith("绝经期"))
                {
                    shortFormReport.DataExamConclusion = "5";// App.Current.FindResource("ReportContext_120").ToString();
                }

                //ShortFormReport.DataExamConclusion = doc.FormFields[59].Result;
                string dataLeftMammaryGland = doc.FormFields[60].Result;
                if (string.IsNullOrEmpty(dataLeftMammaryGland))
                {
                    shortFormReport.DataLeftMammaryGland = "0";// "";
                }
                else if (dataLeftMammaryGland.StartsWith("Ductal type") || dataLeftMammaryGland.StartsWith("导管型乳腺结构") || dataLeftMammaryGland.StartsWith("导管式结构"))
                {
                    shortFormReport.DataLeftMammaryGland = "5";// App.Current.FindResource("ReportContext_126").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with ductal component predominance") || dataLeftMammaryGland.StartsWith("混合型,导管型结构优势") || dataLeftMammaryGland.StartsWith("导管成分优先的"))
                {
                    shortFormReport.DataLeftMammaryGland = "4";// App.Current.FindResource("ReportContext_125").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type of mammary gland structure") || dataLeftMammaryGland.StartsWith("Mixed type of structure") || dataLeftMammaryGland.StartsWith("混合型乳腺结构") || dataLeftMammaryGland.StartsWith("混合式结构"))
                {
                    shortFormReport.DataLeftMammaryGland = "3";// App.Current.FindResource("ReportContext_124").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with amorphous component predominance") || dataLeftMammaryGland.StartsWith("混合型,无定型结构优势") || (dataLeftMammaryGland.Contains("无") && dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataLeftMammaryGland = "2";// App.Current.FindResource("ReportContext_123").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Amorphous type") || dataLeftMammaryGland.StartsWith("无定型乳腺结构") || (dataLeftMammaryGland.Contains("无") && !dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataLeftMammaryGland = "1";// App.Current.FindResource("ReportContext_122").ToString();
                }
                //ShortFormReport.DataLeftMammaryGland = doc.FormFields[60].Result;
                string dataLeftAgeRelated = doc.FormFields[61].Result;
                if (string.IsNullOrEmpty(dataLeftAgeRelated))
                {
                    shortFormReport.DataLeftAgeRelated = "0";//"";
                }
                else if (dataLeftAgeRelated.StartsWith("<5"))
                {
                    shortFormReport.DataLeftAgeRelated = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataLeftAgeRelated.StartsWith(">95"))
                {
                    shortFormReport.DataLeftAgeRelated = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataLeftAgeRelated = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }
                //ShortFormReport.DataLeftAgeRelated = doc.FormFields[61].Result;

                string dataRightMammaryGland = doc.FormFields[64].Result;
                if (string.IsNullOrEmpty(dataLeftMammaryGland))
                {
                    shortFormReport.DataRightMammaryGland = "0";// "";
                }
                else if (dataLeftMammaryGland.StartsWith("Ductal type") || dataLeftMammaryGland.StartsWith("导管型乳腺结构") || dataLeftMammaryGland.StartsWith("导管式结构"))
                {
                    shortFormReport.DataRightMammaryGland = "5";// App.Current.FindResource("ReportContext_126").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with ductal component predominance") || dataLeftMammaryGland.StartsWith("混合型,导管型结构优势") || dataLeftMammaryGland.StartsWith("导管成分优先的"))
                {
                    shortFormReport.DataRightMammaryGland = "4";// App.Current.FindResource("ReportContext_125").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type of mammary gland structure") || dataLeftMammaryGland.StartsWith("Mixed type of structure") || dataLeftMammaryGland.StartsWith("混合型乳腺结构") || dataLeftMammaryGland.StartsWith("混合式结构"))
                {
                    shortFormReport.DataRightMammaryGland = "3";// App.Current.FindResource("ReportContext_124").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with amorphous component predominance") || dataLeftMammaryGland.StartsWith("混合型,无定型结构优势") || (dataLeftMammaryGland.Contains("无") && dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataRightMammaryGland = "2";// App.Current.FindResource("ReportContext_123").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Amorphous type") || dataLeftMammaryGland.StartsWith("无定型乳腺结构") || (dataLeftMammaryGland.Contains("无") && !dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataRightMammaryGland = "1";// App.Current.FindResource("ReportContext_122").ToString();
                }
                //ShortFormReport.DataLeftMammaryGland = doc.FormFields[60].Result;
                string dataRightAgeRelated = doc.FormFields[65].Result;
                if (string.IsNullOrEmpty(dataRightAgeRelated))
                {
                    shortFormReport.DataRightAgeRelated = "0";// "";
                }
                else if (dataRightAgeRelated.StartsWith("<5"))
                {
                    shortFormReport.DataRightAgeRelated = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataRightAgeRelated.StartsWith(">95"))
                {
                    shortFormReport.DataRightAgeRelated = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataRightAgeRelated = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }

                //ShortFormReport.DataRightMammaryGland = doc.FormFields[64].Result;
                //ShortFormReport.DataRightAgeRelated = doc.FormFields[65].Result;
            }
            catch (Exception) {}
            finally
            {
                Type wordType = wordApp.GetType();
                try
                {
                    if (doc != null)
                    {
                        doc.Close();
                    }
                    if (wordApp != null)
                    {
                        wordApp.Quit();
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, wordApp, null);
                        doc     = null;
                        wordApp = null;
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                    catch (Exception) { }
                }
            }
            return(shortFormReport);
        }
コード例 #12
0
 /// <summary>
 /// word转换成pdf
 /// </summary>
 /// <param name="filePath"></param>
 public static void Word2Pdf(string filePath)
 {
     path = filePath;
     saveFileName = filePath + ".pdf";
     var word = new Word.Application();
     Type wordType = word.GetType();
     Word.Documents docs = word.Documents;
     var docsType = docs.GetType();
     var doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs,
         new Object[] { path, true, true });
     Type docType = doc.GetType();
     docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc,
         new object[] { saveFileName, Word.WdSaveFormat.wdFormatPDF });
     wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
 }
コード例 #13
0
 public static List<string> GetWordContent(string filePath)
 {
     try
     {
         List<string> allContent = new List<string>();
         string content = string.Empty;
         path = filePath;
         var word = new Word.Application();
         Type wordType = word.GetType();
         Word.Documents docs = word.Documents;
         var docsType = docs.GetType();
         var doc = (Word.Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, docs,
             new Object[] { path, true, true });
         for (int i = 0; i < doc.Paragraphs.Count; i++)
         {
             if (content.Length <= 300)
                 content += doc.Paragraphs[i+1].Range.Text;
             else
             {
                 allContent.Add(content);
                 content = "";
                 content += doc.Paragraphs[i+1].Range.Text;
             }
         }
         if (allContent.Count == 0)
             allContent.Add(content);
         Type docType = doc.GetType();
         docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc,
             new object[] { saveFileName, Word.WdSaveFormat.wdFormatPDF });
         wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);
         return allContent;
     }
     catch(Exception e)
     {
         return null;
     }
 }
コード例 #14
0
ファイル: WordTools.cs プロジェクト: mydipcom/MEIKReport
        public static ShortFormReport ReadWordFile(string wordFilePath)
        {
            
            if (FileHelper.FileInUsed(wordFilePath))
            {
                return null;
            }
            ShortFormReport shortFormReport = new ShortFormReport();
            Word.Application wordApp = new Word.Application();
            object unknow = Type.Missing;
            wordApp.Visible = false;
            wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
            Object file = wordFilePath;
            Word.Document doc = null;
                        
            try
            {
                doc = wordApp.Documents.Open(ref file);
                string dataMenstrualCycle = doc.FormFields[11].Result;
                if (string.IsNullOrEmpty(dataMenstrualCycle))
                {
                    shortFormReport.DataMenstrualCycle = "0";
                }
                else if (dataMenstrualCycle.StartsWith("1 phase") || dataMenstrualCycle.StartsWith("phase 1") || dataMenstrualCycle.StartsWith("第一阶段") || dataMenstrualCycle.StartsWith("一期"))
                {
                    shortFormReport.DataMenstrualCycle = "1";// App.Current.FindResource("ReportContext_15").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("2 phase") || dataMenstrualCycle.StartsWith("phase 2") || dataMenstrualCycle.StartsWith("第二阶段") || dataMenstrualCycle.StartsWith("二期"))
                {
                    shortFormReport.DataMenstrualCycle = "2";//App.Current.FindResource("ReportContext_16").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("1 and 2 phase") || dataMenstrualCycle.StartsWith("第一和第二阶段") || dataMenstrualCycle.StartsWith("一期和二期"))
                {
                    shortFormReport.DataMenstrualCycle = "3";//App.Current.FindResource("ReportContext_17").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("dysmenorrhea") || dataMenstrualCycle.StartsWith("痛经"))
                {
                    shortFormReport.DataMenstrualCycle = "4";// App.Current.FindResource("ReportContext_18").ToString();
                }
                else if (dataMenstrualCycle.StartsWith("missing") || dataMenstrualCycle.StartsWith("postmenopausal") || dataMenstrualCycle.StartsWith("postmenopause") || dataMenstrualCycle.StartsWith("绝经期"))
                {
                    shortFormReport.DataMenstrualCycle = "5";// App.Current.FindResource("ReportContext_19").ToString();
                    shortFormReport.DataMeanElectricalConductivity3 = "1";
                    shortFormReport.DataComparativeElectricalConductivity3 = "1";
                    shortFormReport.DataDivergenceBetweenHistograms3 = "1";
                }
                else if (dataMenstrualCycle.StartsWith("pregnancy") || dataMenstrualCycle.StartsWith("孕期"))
                {
                    shortFormReport.DataMenstrualCycle = "6";// App.Current.FindResource("ReportContext_20").ToString();
                    shortFormReport.DataMeanElectricalConductivity3 = "2";
                    shortFormReport.DataComparativeElectricalConductivity3 = "2";
                    shortFormReport.DataDivergenceBetweenHistograms3 = "2";
                }
                else if (dataMenstrualCycle.StartsWith("lactation") || dataMenstrualCycle.StartsWith("哺乳期"))
                {
                    shortFormReport.DataMenstrualCycle = "7";// App.Current.FindResource("ReportContext_21").ToString();
                    shortFormReport.DataMeanElectricalConductivity3 = "3";
                    shortFormReport.DataComparativeElectricalConductivity3 = "3";
                    shortFormReport.DataDivergenceBetweenHistograms3 = "3";
                }
                //shortFormReport.DataMenstrualCycle = doc.FormFields[11].Result;
                //shortFormReport.DataLeftChangesOfElectricalConductivity = doc.FormFields[15].Result;
                //shortFormReport.DataRightChangesOfElectricalConductivity = doc.FormFields[16].Result;
                //shortFormReport.DataLeftMammaryStruct = doc.FormFields[17].Result;
                //shortFormReport.DataRightMammaryStruct = doc.FormFields[18].Result;
                //shortFormReport.DataLeftLactiferousSinusZone = doc.FormFields[19].Result;
                //shortFormReport.DataRightLactiferousSinusZone = doc.FormFields[20].Result;
                //shortFormReport.DataLeftMammaryContour = doc.FormFields[21].Result;
                //shortFormReport.DataLeftMammaryContour = doc.FormFields[22].Result;

                //shortFormReport.DataLeftLocation = doc.FormFields[23].Result;
                //shortFormReport.DataRightLocation = doc.FormFields[24].Result;
                //shortFormReport.DataLeftNumber = doc.FormFields[25].Result;
                //shortFormReport.DataRightNumber = doc.FormFields[26].Result;
                //shortFormReport.DataLeftSize = doc.FormFields[27].Result;
                //shortFormReport.DataRightSize = doc.FormFields[28].Result;
                //shortFormReport.DataLeftShape = doc.FormFields[29].Result;
                //shortFormReport.DataRightShape = doc.FormFields[30].Result;
                //shortFormReport.DataLeftContourAroundFocus = doc.FormFields[31].Result;
                //shortFormReport.DataRightContourAroundFocus = doc.FormFields[32].Result;
                //shortFormReport.DataLeftInternalElectricalStructure = doc.FormFields[33].Result;
                //shortFormReport.DataRightInternalElectricalStructure = doc.FormFields[34].Result;
                //shortFormReport.DataLeftSurroundingTissues = doc.FormFields[35].Result;
                //shortFormReport.DataRightSurroundingTissues = doc.FormFields[36].Result;


                shortFormReport.DataLeftMeanElectricalConductivity1 = doc.FormFields[37].Result;
                shortFormReport.DataRightMeanElectricalConductivity1 = doc.FormFields[38].Result;
                shortFormReport.DataLeftMeanElectricalConductivity2 = doc.FormFields[39].Result;
                shortFormReport.DataRightMeanElectricalConductivity2 = doc.FormFields[40].Result;
                string dataMeanElectricalConductivity3 = doc.FormFields[41].Result;
                if (string.IsNullOrEmpty(dataMeanElectricalConductivity3))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "0";//"";
                }
                else if (dataMeanElectricalConductivity3.StartsWith("postmenopause") || dataMeanElectricalConductivity3.StartsWith("绝经后期"))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "1";// App.Current.FindResource("ReportContext_103").ToString();
                }
                else if (dataMeanElectricalConductivity3.StartsWith("pregnancy") || dataMeanElectricalConductivity3.StartsWith("妊娠"))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "2";// App.Current.FindResource("ReportContext_104").ToString();
                }
                else if (dataMeanElectricalConductivity3.StartsWith("lactation") || dataMeanElectricalConductivity3.StartsWith("哺乳期"))
                {
                    shortFormReport.DataMeanElectricalConductivity3 = "3";// App.Current.FindResource("ReportContext_105").ToString();
                }
                //ShortFormReport.DataMeanElectricalConductivity3 = doc.FormFields[41].Result;
                shortFormReport.DataLeftMeanElectricalConductivity3 = doc.FormFields[42].Result;
                shortFormReport.DataRightMeanElectricalConductivity3 = doc.FormFields[43].Result;

                shortFormReport.DataLeftComparativeElectricalConductivity1 = doc.FormFields[44].Result;
                //ShortFormReport.DataRightComparativeElectricalConductivity1 = doc.FormFields[44].Result;
                shortFormReport.DataLeftComparativeElectricalConductivity2 = doc.FormFields[45].Result;
                //ShortFormReport.DataRightComparativeElectricalConductivity2 = doc.FormFields[45].Result;
                shortFormReport.DataLeftComparativeElectricalConductivity3 = doc.FormFields[46].Result;
                //ShortFormReport.DataRightComparativeElectricalConductivity3 = doc.FormFields[46].Result;
                shortFormReport.DataLeftDivergenceBetweenHistograms1 = doc.FormFields[47].Result;
                //ShortFormReport.DataRightDivergenceBetweenHistograms1 = doc.FormFields[47].Result;
                shortFormReport.DataLeftDivergenceBetweenHistograms2 = doc.FormFields[48].Result;
                //ShortFormReport.DataRightDivergenceBetweenHistograms2 = doc.FormFields[48].Result;
                shortFormReport.DataLeftDivergenceBetweenHistograms3 = doc.FormFields[49].Result;
                //ShortFormReport.DataRightDivergenceBetweenHistograms3 = doc.FormFields[49].Result;

                shortFormReport.DataLeftPhaseElectricalConductivity = doc.FormFields[54].Result;
                shortFormReport.DataRightPhaseElectricalConductivity = doc.FormFields[55].Result;

                shortFormReport.DataAgeElectricalConductivityReference = doc.FormFields[56].Result;

                string dataLeftAgeElectricalConductivity = doc.FormFields[57].Result;
                if (string.IsNullOrEmpty(dataLeftAgeElectricalConductivity))
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "0";// "";
                }
                else if (dataLeftAgeElectricalConductivity.StartsWith("<5"))
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataLeftAgeElectricalConductivity.StartsWith(">95"))
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else 
                {
                    shortFormReport.DataLeftAgeElectricalConductivity = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }
                //ShortFormReport.DataLeftAgeElectricalConductivity = doc.FormFields[57].Result;
                string dataRightAgeElectricalConductivity = doc.FormFields[58].Result;
                if (string.IsNullOrEmpty(dataRightAgeElectricalConductivity))
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "0";// "";
                }
                else if (dataRightAgeElectricalConductivity.StartsWith("<5"))
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataRightAgeElectricalConductivity.StartsWith(">95"))
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataRightAgeElectricalConductivity = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }
                //ShortFormReport.DataRightAgeElectricalConductivity = doc.FormFields[58].Result;
                string dataExamConclusion = doc.FormFields[59].Result;
                if (string.IsNullOrEmpty(dataExamConclusion))
                {
                    shortFormReport.DataExamConclusion = "0";//"";
                }
                else if (dataExamConclusion.StartsWith("Pubertal Period") || dataExamConclusion.StartsWith("青春期"))
                {
                    shortFormReport.DataExamConclusion = "1";// App.Current.FindResource("ReportContext_116").ToString();
                }
                else if (dataExamConclusion.StartsWith("Early childbearing age") || dataExamConclusion.StartsWith("育龄早期"))
                {
                    shortFormReport.DataExamConclusion = "2";// App.Current.FindResource("ReportContext_117").ToString();
                }
                else if (dataExamConclusion.StartsWith("Childbearing age") || dataExamConclusion.StartsWith("育龄期"))
                {
                    shortFormReport.DataExamConclusion = "3";// App.Current.FindResource("ReportContext_118").ToString();
                }
                else if (dataExamConclusion.StartsWith("Perimenopausal period") || dataExamConclusion.StartsWith("围绝经期"))
                {
                    shortFormReport.DataExamConclusion = "4";// App.Current.FindResource("ReportContext_119").ToString();
                }
                else if (dataExamConclusion.StartsWith("Postmenopausal period") || dataExamConclusion.StartsWith("Postmenopause period") || dataExamConclusion.StartsWith("绝经期"))
                {
                    shortFormReport.DataExamConclusion = "5";// App.Current.FindResource("ReportContext_120").ToString();
                }
                
                //ShortFormReport.DataExamConclusion = doc.FormFields[59].Result;
                string dataLeftMammaryGland=doc.FormFields[60].Result;
                if (string.IsNullOrEmpty(dataLeftMammaryGland))
                {
                    shortFormReport.DataLeftMammaryGland = "0";// "";
                }
                else if (dataLeftMammaryGland.StartsWith("Ductal type") || dataLeftMammaryGland.StartsWith("导管型乳腺结构") || dataLeftMammaryGland.StartsWith("导管式结构"))
                {
                    shortFormReport.DataLeftMammaryGland = "5";// App.Current.FindResource("ReportContext_126").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with ductal component predominance") || dataLeftMammaryGland.StartsWith("混合型,导管型结构优势") || dataLeftMammaryGland.StartsWith("导管成分优先的"))
                {
                    shortFormReport.DataLeftMammaryGland = "4";// App.Current.FindResource("ReportContext_125").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type of mammary gland structure") || dataLeftMammaryGland.StartsWith("Mixed type of structure") || dataLeftMammaryGland.StartsWith("混合型乳腺结构") || dataLeftMammaryGland.StartsWith("混合式结构"))
                {
                    shortFormReport.DataLeftMammaryGland = "3";// App.Current.FindResource("ReportContext_124").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with amorphous component predominance") || dataLeftMammaryGland.StartsWith("混合型,无定型结构优势") || ( dataLeftMammaryGland.Contains("无") && dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataLeftMammaryGland = "2";// App.Current.FindResource("ReportContext_123").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Amorphous type") || dataLeftMammaryGland.StartsWith("无定型乳腺结构") || (dataLeftMammaryGland.Contains("无") && !dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataLeftMammaryGland = "1";// App.Current.FindResource("ReportContext_122").ToString();
                }
                //ShortFormReport.DataLeftMammaryGland = doc.FormFields[60].Result;
                string dataLeftAgeRelated = doc.FormFields[61].Result;
                if (string.IsNullOrEmpty(dataLeftAgeRelated))
                {
                    shortFormReport.DataLeftAgeRelated = "0";//"";
                }
                else if (dataLeftAgeRelated.StartsWith("<5"))
                {
                    shortFormReport.DataLeftAgeRelated = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataLeftAgeRelated.StartsWith(">95"))
                {
                    shortFormReport.DataLeftAgeRelated = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataLeftAgeRelated = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }
                //ShortFormReport.DataLeftAgeRelated = doc.FormFields[61].Result;

                string dataRightMammaryGland = doc.FormFields[64].Result;
                if (string.IsNullOrEmpty(dataLeftMammaryGland))
                {
                    shortFormReport.DataRightMammaryGland = "0";// "";
                }
                else if (dataLeftMammaryGland.StartsWith("Ductal type") || dataLeftMammaryGland.StartsWith("导管型乳腺结构") || dataLeftMammaryGland.StartsWith("导管式结构"))
                {
                    shortFormReport.DataRightMammaryGland = "5";// App.Current.FindResource("ReportContext_126").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with ductal component predominance") || dataLeftMammaryGland.StartsWith("混合型,导管型结构优势") || dataLeftMammaryGland.StartsWith("导管成分优先的"))
                {
                    shortFormReport.DataRightMammaryGland = "4";// App.Current.FindResource("ReportContext_125").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type of mammary gland structure") || dataLeftMammaryGland.StartsWith("Mixed type of structure") || dataLeftMammaryGland.StartsWith("混合型乳腺结构") || dataLeftMammaryGland.StartsWith("混合式结构"))
                {
                    shortFormReport.DataRightMammaryGland = "3";// App.Current.FindResource("ReportContext_124").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Mixed type with amorphous component predominance") || dataLeftMammaryGland.StartsWith("混合型,无定型结构优势") || (dataLeftMammaryGland.Contains("无") && dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataRightMammaryGland = "2";// App.Current.FindResource("ReportContext_123").ToString();
                }
                else if (dataLeftMammaryGland.StartsWith("Amorphous type") || dataLeftMammaryGland.StartsWith("无定型乳腺结构") || (dataLeftMammaryGland.Contains("无") && !dataLeftMammaryGland.Contains("混合")))
                {
                    shortFormReport.DataRightMammaryGland = "1";// App.Current.FindResource("ReportContext_122").ToString();
                }
                //ShortFormReport.DataLeftMammaryGland = doc.FormFields[60].Result;
                string dataRightAgeRelated = doc.FormFields[65].Result;
                if (string.IsNullOrEmpty(dataRightAgeRelated))
                {
                    shortFormReport.DataRightAgeRelated = "0";// "";
                }
                else if (dataRightAgeRelated.StartsWith("<5"))
                {
                    shortFormReport.DataRightAgeRelated = "1";// App.Current.FindResource("ReportContext_111").ToString();
                }
                else if (dataRightAgeRelated.StartsWith(">95"))
                {
                    shortFormReport.DataRightAgeRelated = "3";// App.Current.FindResource("ReportContext_113").ToString();
                }
                else
                {
                    shortFormReport.DataRightAgeRelated = "2";// App.Current.FindResource("ReportContext_112").ToString();
                }

                //ShortFormReport.DataRightMammaryGland = doc.FormFields[64].Result;
                //ShortFormReport.DataRightAgeRelated = doc.FormFields[65].Result;
                                

            }
            catch(Exception){}
            finally
            {
                Type wordType = wordApp.GetType();
                try
                {
                    if (doc != null)
                    {
                        doc.Close();
                    }
                    if (wordApp != null)
                    {
                        wordApp.Quit();
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, wordApp, null);
                        doc = null;
                        wordApp = null;
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                    catch (Exception) { }
                }
            }
            return shortFormReport;
        }
コード例 #15
0
ファイル: EKWord.cs プロジェクト: xiaocaiyuen/ShuCMS
        /// <summary>
        /// Word转HTMl
        /// </summary>
        /// <param name="path">word文件路径 带盘符</param>
        /// <returns></returns>
        public static string WordToHtml(string wordPath)
        {
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            Type wordType = word.GetType();

            Microsoft.Office.Interop.Word.Documents docs = word.Documents;
            Object oMissing = System.Reflection.Missing.Value;
            // 打开文件
            Type docsType = docs.GetType();

            //应当先把文件上传至服务器然后再解析文件为html
            string filePath = wordPath;

            Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open",
                                                                                                                       System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { filePath, true, true });

            // 转换格式,另存为html
            Type docType = doc.GetType();

            //被转换的html文档保存的位置
            string saveFileName = "";
            string ext          = EKFileUpload.getExtend(wordPath).ToLower();

            if (ext == "doc")
            {
                saveFileName = wordPath.Replace(".doc", "");
            }
            else if (ext == "docx")
            {
                saveFileName = wordPath.Replace(".docx", "");
            }
            else
            {
            }

            //另存为html页面
            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
                                 null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });

            // 退出 Word
            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);

            //doc.Close(ref oMissing, ref oMissing, ref oMissing);
            try
            {
                docs.Close(ref oMissing, ref oMissing, ref oMissing);
                word.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
            catch (Exception ex)
            {
                new MS_LogBLL().AddLogAdmin(MS_LogBLL.LogLevel.ERROR, "word转换失败" + ex.Message);
            }
            GC.Collect();

            //读取html 页面
            string html = "";

            //特别处理.有"."号的的文件名.直接读.  不用加.htm
            if (saveFileName.Contains("."))
            {
                html = EKFile.ReadFile(saveFileName);
            }
            else
            {
                html = EKFile.ReadFile(saveFileName + ".htm");
            }

            //补全图片地址
            html = EKHtml.ImageWebRoot(html, "http://" + System.Web.HttpContext.Current.Request.Url.Authority + "/files/temp/", "<img[\\s\\S]+?src=\"(?<url>.+?)\">");

            //保存页面图片
            html = EKHtml.SaveImage(html, DateTime.Now, "<img[\\s\\S]+?src=\"(?<url>.+?)\">");

            //删除临时文件.也可保留
            if (saveFileName.Contains("."))
            {
                EKFile.DeleteFile(saveFileName);
            }
            else
            {
                EKFile.DeleteFile(saveFileName + ".htm");
            }
            //删除目录
            if (EKFile.ExistsDirectory(saveFileName + ".files"))
            {
                EKFile.DeleteDirectoryAnd(saveFileName + ".files");
                EKFile.DeleteDirectory(saveFileName + ".files");
            }
            EKFile.DeleteFile(wordPath);

            return(html);
        }