示例#1
0
        public void LocalToFile(Program p, ConvertEquation ce)
        {
            // TeX in a text file to EPS
            ce.Convert(new EquationInputFileText(p.GetInputFolder("TeX.txt"), ClipboardFormats.cfTeX),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // MML in a text file to GIF
            ce.Convert(new EquationInputFileText(p.GetInputFolder("MathML.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // TeX in a text file to GIF
            ce.Convert(new EquationInputFileText(p.GetInputFolder("TeX.txt"), ClipboardFormats.cfTeX),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // MML in a text file to WMF
            ce.Convert(new EquationInputFileText(p.GetInputFolder("MathML.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));

            // Base 64 MTEF in a text file to EPS
            ce.Convert(new EquationInputFileText(p.GetInputFolder("Base64MTEF.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // Base 64 MTEF in a text file to GIF
            ce.Convert(new EquationInputFileText(p.GetInputFolder("Base64MTEF.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // Base 64 MTEF in a text file to WMF
            ce.Convert(new EquationInputFileText(p.GetInputFolder("Base64MTEF.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));
        }
示例#2
0
        static void Main(string[] args)
        {
            Program         p  = new Program();
            ConvertEquation ce = new ConvertEquation();

            p.LocalToClipboard(p, ce);
        }
示例#3
0
        static void Main(string[] args)
        {
            Program         p  = new Program();
            ConvertEquation ce = new ConvertEquation();

            /*
             * These routines:
             *		ClipboardToClipboard
             *		FileToClipboard
             *		LocalToClipboard
             * Place the following types on the clipboard:
             *		MathType EF
             *		MathML Presentation
             *		MathML
             *		application/mathml+xml
             *		CF_METAFILEPICT
             *		MathType Macro PICT
             *		Embed Source
             *		Object Descriptor
             */

            //p.ClipboardToClipboard(p, ce);
            //p.ClipboardToFile(p, ce);
            //p.ClipboardToLocal(p, ce);

            //p.FileToClipboard(p, ce);
            //p.FileToFile(p, ce);
            //p.FileToLocal(p, ce);

            //p.LocalToClipboard(p, ce);
            //p.LocalToFile(p, ce);
            //p.LocalToLocal(p, ce);
            //p.Temp(ce);
        }
示例#4
0
        public void FileToLocal(Program p, ConvertEquation ce)
        {
            // WMF file to MML text file
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "MathML2 (m namespace).tdl"));

            // WMF file to TeX text file
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "Texvc.tdl"));

            // WMF file to base64 MTEF text file
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF

            // GIF file to MML text file
            ce.Convert(new EquationInputFileGIF(p.GetInputFolder("Equation2.gif")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "MathML2 (m namespace).tdl"));

            // GIF file to base64 MTEF text file
            ce.Convert(new EquationInputFileGIF(p.GetInputFolder("Equation2.gif")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF

            // EPS file to MML text file
            ce.Convert(new EquationInputFileEPS(p.GetInputFolder("Equation3.eps")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "MathML2 (m namespace).tdl"));

            // EPS file to base64 MTEF text file
            ce.Convert(new EquationInputFileEPS(p.GetInputFolder("Equation3.eps")),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF
        }
示例#5
0
        public void ClipboardToLocal(Program p, ConvertEquation ce)
        {
            // copy MML text to the clipboard
            p.MessagePause("Copy MathML to the clipboard, then press any key");

            // clipboard MML to MML text file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "MathML2 (m namespace).tdl"));

            // clipboard MML to Base 64 MTEF text file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF

            // copy Base 64 MTEF text to clipboard
            p.MessagePause("Copy Base 64 MTEF to the clipboard, then press any key");

            // clipboard Base 64 MTEF text to TeX text file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "Texvc.tdl"));

            // clipboard Base 64 MTEF text to Base 64 MTEF text file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF

            // copy MathType equation to the clipboard from within Microsoft Word
            p.MessagePause("From MS Word, copy a MathType equation to the clipboard, then press any key");

            // clipboard Embedded Object to TeX text file
            ce.Convert(new EquationInputClipboardEmbeddedObject(),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "Texvc.tdl"));

            // clipboard Embedded Object to base64 MTEF text file
            ce.Convert(new EquationInputClipboardEmbeddedObject(),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF
        }
示例#6
0
        public void ClipboardToClipboard(Program p, ConvertEquation ce)
        {
            // copy MML text to clipboard
            p.MessagePause("Copy MathML to the clipboard, then press any key");

            // clipboard MML to clipboard
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");

            // copy Base 64 MTEF text to clipboard
            p.MessagePause("Copy Base 64 MTEF to the clipboard, then press any key");

            // clipboard Base 64 MTEF text to clipboard
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");

            // copy MathType equation to the clipboard from within Microsoft Word
            p.MessagePause("From MS Word, copy a MathType equation to the clipboard, then press any key");

            // clipboard Embedded Object to EPS file
            ce.Convert(new EquationInputClipboardEmbeddedObject(),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");
        }
示例#7
0
        public void Temp(ConvertEquation ce)
        {
            ce.Convert(new EquationInputFileWMF(@"C:\Temp\Object1.wmf"),
                       new EquationOutputFileText(@"C:\Temp\temp.txt", "MathML2 (m namespace).tdl"));

            ce.Convert(new EquationInputFileWMF(@"C:\Temp\FromMT.wmf"),
                       new EquationOutputFileText(@"C:\Temp\temp.txt", "MathML2 (m namespace).tdl"));
        }
示例#8
0
        public void LocalToClipboard(Program p, ConvertEquation ce)
        {
            // MML in a text file to clipboard text
            ce.Convert(new EquationInputFileText(p.GetInputFolder("MathML.txt"), ClipboardFormats.cfMML),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");

            // Base 64 MTEF in a text file to clipboard
            ce.Convert(new EquationInputFileText(p.GetInputFolder("Base64MTEF.txt"), ClipboardFormats.cfMML),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");
        }
示例#9
0
        public void ClipboardToFile(Program p, ConvertEquation ce)
        {
            // copy MML text to the clipboard
            p.MessagePause("Copy MathML to the clipboard, then press any key");

            // clipboard MML to EPS file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // clipboard MML to GIF file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // clipboard MML to WMF file
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));

            // copy Base 64 MTEF text to the clipboard
            p.MessagePause("Copy Base 64 MTEF to the clipboard, then press any key");

            // clipboard Base 64 MTEF text to EPS
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // clipboard Base 64 MTEF text to GIF
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // clipboard Base 64 MTEF text to WMF
            ce.Convert(new EquationInputClipboardText(ClipboardFormats.cfMML),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));

            // copy MathType equation to the clipboard from within Microsoft Word
            p.MessagePause("From MS Word, copy a MathType equation to the clipboard, then press any key");

            // clipboard Embedded Object to EPS file
            ce.Convert(new EquationInputClipboardEmbeddedObject(),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // clipboard Embedded Object to GIF file
            ce.Convert(new EquationInputClipboardEmbeddedObject(),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // clipboard Embedded Object to WMF file
            ce.Convert(new EquationInputClipboardEmbeddedObject(),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));
        }
示例#10
0
        public void LocalToLocal(Program p, ConvertEquation ce)
        {
            // TeX in a text file to MML text file
            ce.Convert(new EquationInputFileText(p.GetInputFolder("TeX.txt"), ClipboardFormats.cfTeX),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "MathML2 (m namespace).tdl"));

            // TeX in a text file to Base 64 MTEF in a text file
            ce.Convert(new EquationInputFileText(p.GetInputFolder("TeX.txt"), ClipboardFormats.cfTeX),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF

            // Base 64 MTEF in a text file to MML text file
            ce.Convert(new EquationInputFileText(p.GetInputFolder("Base64MTEF.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileText(p.GetOutputFile("txt"), "MathML2 (m namespace).tdl"));

            // Base 64 MTEF in a text file to Base 64 MTEF in a text file
            ce.Convert(new EquationInputFileText(p.GetInputFolder("Base64MTEF.txt"), ClipboardFormats.cfMML),
                       new EquationOutputFileText(p.GetOutputFile("txt"), ""));                     // specifying no translator outputs MTEF
        }
示例#11
0
        public void FileToClipboard(Program p, ConvertEquation ce)
        {
            // break after each of the following to inspect the clipboard
            // EPS file to clipboard text
            ce.Convert(new EquationInputFileEPS(p.GetInputFolder("Equation3.eps")),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");

            // GIF file to clipboard text
            ce.Convert(new EquationInputFileGIF(p.GetInputFolder("Equation2.gif")),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");

            // WMF file to clipboard text
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputClipboardText());
            p.MessagePause("Inspect the clipboard, then press any key");
        }
示例#12
0
        public void FileToFile(Program p, ConvertEquation ce)
        {
            // WMF file to EPS file
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // WMF file to GIF file
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // WMF file to WMF file
            ce.Convert(new EquationInputFileWMF(p.GetInputFolder("Equation1.wmf")),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));

            // GIF file to EPS file
            ce.Convert(new EquationInputFileGIF(p.GetInputFolder("Equation2.gif")),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // GIF file to GIF file
            ce.Convert(new EquationInputFileGIF(p.GetInputFolder("Equation2.gif")),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // GIF file to WMF file
            ce.Convert(new EquationInputFileGIF(p.GetInputFolder("Equation2.gif")),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));

            // EPS file to EPS file
            ce.Convert(new EquationInputFileEPS(p.GetInputFolder("Equation3.eps")),
                       new EquationOutputFileEPS(p.GetOutputFile("eps")));

            // EPS file to GIF file
            ce.Convert(new EquationInputFileEPS(p.GetInputFolder("Equation3.eps")),
                       new EquationOutputFileGIF(p.GetOutputFile("gif")));

            // EPS file to WMF file
            ce.Convert(new EquationInputFileEPS(p.GetInputFolder("Equation3.eps")),
                       new EquationOutputFileWMF(p.GetOutputFile("wmf")));
        }
示例#13
0
        public void LocalToClipboard(Program p, ConvertEquation ce)
        {
            Utils.killAllProcess("winword.exe");
            Utils.killAllProcess("mathtype.exe");
            object name = "e:\\yb3.doc";

            //create document
            Word.Application newapp = new Word.Application();
            //用于作为函数的默认参数
            object nothing = System.Reflection.Missing.Value;

            //create a word document
            Word.Document newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);
            //是否显示word程序界面
            newapp.Visible = false;

            Excel.Workbook  workbook  = null;
            Excel.Worksheet worksheet = null;
            string          path      = Utils.GetInputFolder("高中数学(必修2)(人教版A)01一章 空间几何体 (3).xls");
            object          missing   = System.Reflection.Missing.Value;

            Excel.Application excel = new Excel.Application();//lauch excel application
            if (excel == null)
            {
                Console.WriteLine("Can't access excel");
                return;
            }
            excel.Visible     = false;
            excel.UserControl = true;
            // 以只读的形式打开EXCEL文件
            workbook = excel.Application.Workbooks.Open(path, missing, true, missing, missing, missing,
                                                        missing, missing, missing, true, missing, missing, missing, missing, missing);
            //取得第一个工作薄
            worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);
            //取得总记录行数   (包括标题列)
            int iRowCount = worksheet.UsedRange.Rows.Count;
            int iColCount = worksheet.UsedRange.Columns.Count;

            //生成列头
            List <string> titles = new List <String>();

            for (int i = 0; i < iColCount; i++)
            {
                var txt = ((Excel.Range)worksheet.Cells[1, i + 1]).Text.ToString();
                titles.Add(txt.ToString() + ": ");
            }
            //生成行数据
            Excel.Range range;
            //从第二行开始
            int rowIdx = 2;
            int count  = 0;

            for (int iRow = rowIdx; iRow <= iRowCount; iRow++)
            {
                for (int iCol = 1; iCol <= iColCount; iCol++)
                {
                    //插入列头
                    newapp.Selection.Font.Color = Word.WdColor.wdColorBlue;
                    newapp.Selection.TypeText(titles[iCol - 1]);
                    //得到单元格内容
                    range = (Excel.Range)worksheet.Cells[iRow, iCol];
                    string   d            = range.Text.ToString();
                    string[] oneLevelData = d.Split(new string[] { "<math", "</math>" }, StringSplitOptions.None);

                    List <string> imgs = new List <string>();
                    foreach (string datas in oneLevelData)
                    {
                        if (datas.StartsWith(" xmlns="))
                        {
                            // MML in a text file to clipboard text
                            ce.Convert(new EquationInputFileText("<math" + datas + "</math>", ClipboardFormats.cfMML), new EquationOutputClipboardText());
                            count++;
                            try
                            {
                                newapp.Selection.Paste();
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                            finally
                            {
                                if (count == 9)
                                {
                                    Utils.killAllProcess("mathtype.exe");
                                    count = 0;
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine(datas);
                            Regex           regex   = new Regex(Common.HTML_IMG, RegexOptions.IgnoreCase);
                            MatchCollection matches = regex.Matches(datas.ToString());
                            foreach (Match match in matches)
                            {
                                imgs.Add(match.Groups["imgUrl"].Value);
                            }

                            //去除HTML标签
                            string para = Utils.NoHTML(datas);
                            if (para != null && para != "")
                            {
                                newapp.Selection.Font.Color = Word.WdColor.wdColorBlack;
                                //去除空格、插入文本
                                newapp.Selection.TypeText(para.Trim());
                            }
                        }
                    }
                    foreach (string s in imgs)
                    {
                        object SaveWithDocument = true;
                        object Anchor           = newdoc.Application.Selection.Range;
                        newapp.Selection.TypeParagraph();
                        //插入图片
                        newdoc.Application.ActiveDocument.InlineShapes.AddPicture(s, ref nothing, ref SaveWithDocument, ref Anchor);
                    }
                    newapp.Selection.TypeParagraph();
                }
                newapp.Selection.TypeParagraph();
                //清空粘贴板,否则会将前一次粘贴记录保留。
                Clipboard.SetDataObject("", true);
            }

            //保存文档
            newdoc.SaveAs(ref name, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
                          ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
                          ref nothing, ref nothing);
            //关闭文档
            object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;

            newdoc.Close(ref nothing, ref nothing, ref nothing);
            newapp.Application.Quit(ref saveOption, ref nothing, ref nothing);
            excel.Quit();
            excel  = null;
            newdoc = null;
            newapp = null;
            ShellExecute(IntPtr.Zero, "open", name.ToString(), "", "", 3);
            Console.WriteLine("Inspect the clipboard, then press any key");
        }
示例#14
0
        /// <summary>
        /// convert mathml to mathtype equation type into word
        /// </summary>
        /// <param name="p"></param>
        /// <param name="ce"></param>
        /// <param name="savepath">the file where to save</param>
        /// <param name="filename">the input file name</param>
        /// <returns></returns>
        public string MathML2MathTypeWord(Program p, ConvertEquation ce, string savepath, string file)
        {
            Utils.killAllProcess("winword.exe");
            Utils.killAllProcess("mathtype.exe");
            Utils.killAllProcess("excel.exe");

            object name = file.Substring(0, file.LastIndexOf(".")) + ".doc";

            //create document
            Word.Application newapp = new Word.Application();
            //create a word document
            Word.Document newdoc = newapp.Documents.Add(ref nothing, ref nothing, ref nothing, ref nothing);
            //是否显示word程序界面
            newapp.Visible = false;

            Excel.Workbook  workbook  = null;
            Excel.Worksheet worksheet = null;

            Excel.Application excel = new Excel.Application();//lauch excel application
            if (excel == null)
            {
                return(ResultCode.EXCEL_READ_ERROR);
            }
            excel.Visible     = false;
            excel.UserControl = true;
            // 以只读的形式打开EXCEL文件
            workbook = excel.Application.Workbooks.Open(file, nothing, true, nothing, nothing, nothing, nothing, nothing, nothing, true, nothing, nothing, nothing, nothing, nothing);
            //取得第一个工作薄
            worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);
            //取得总记录行数   (包括标题列)
            int iRowCount = worksheet.UsedRange.Rows.Count;
            int iColCount = worksheet.UsedRange.Columns.Count;
            //生成列头
            List <string> titles = new List <String>();

            for (int i = 0; i < iColCount; i++)
            {
                var txt = ((Excel.Range)worksheet.Cells[1, i + 1]).Text.ToString();
                titles.Add(txt.ToString() + ": ");
            }
            Console.WriteLine("Excel读取完成...");
            //生成行数据
            Excel.Range range;
            //从第二行开始
            int           rowIdx = 2;
            int           count  = 0;
            object        anchor = null;
            List <string> imgs   = new List <string>();

            for (int iRow = rowIdx; iRow <= iRowCount; iRow++)
            {
                for (int iCol = 1; iCol <= iColCount; iCol++)
                {
                    //插入列头
                    newapp.Selection.Font.Color = Word.WdColor.wdColorBlue;
                    newapp.Selection.TypeText(titles[iCol - 1]);
                    //得到单元格内容
                    range = (Excel.Range)worksheet.Cells[iRow, iCol];
                    string   d            = range.Text.ToString();
                    string[] oneLevelData = d.Split(new string[] { "<math", "</math>" }, StringSplitOptions.None);
                    try
                    {
                        newapp.Selection.Font.Color = Word.WdColor.wdColorBlack;
                        foreach (string datas in oneLevelData)
                        {
                            if (datas.StartsWith(" xmlns="))
                            {
                                string mathml = "<math" + datas + "</math>";
                                mathml = MathML.preproccessMathml(mathml);
                                Console.WriteLine("转换公式: " + mathml);
                                ce.Convert(new EquationInputFileText(mathml, ClipboardFormats.cfMML), new EquationOutputClipboardText());
                                count++;
                                WordUtils.moveLeft(newdoc, 1);
                                newapp.Selection.Paste();
                                if (count == 9)
                                {
                                    Utils.killAllProcess("mathtype.exe");
                                    count = 0;
                                }
                            }
                            else
                            {
                                //var html = HTMLUtils.HtmlClipboardData(datas);
                                //HTMLUtils.CopyHTMLToClipboard(html);
                                //object dataType = Word.WdPasteDataType.wdPasteHTML;
                                //newapp.Selection.PasteSpecial(ref nothing, ref nothing, ref nothing, ref nothing, ref dataType, ref nothing, ref nothing);

                                string[] tags = datas.Split(new string[] { "<img", "<IMG" }, StringSplitOptions.None);
                                foreach (string tag in tags)
                                {
                                    //regular expression extract img src resource
                                    string matchString = Regex.Match("<img " + tag, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;
                                    if (matchString != null && !"".Equals(matchString))
                                    {
                                        anchor = newdoc.Application.Selection.Range;
                                        //regular expression extract file name
                                        string imgfilename = Regex.Match(matchString, ".+/(.+)$", RegexOptions.IgnoreCase).Groups[1].Value;
                                        string imgpath     = savepath + imgfilename;
                                        imgs.Add(imgpath);
                                        //download the image from the url
                                        webClient.DownloadFile(matchString, imgpath);
                                        //add the picture into word
                                        newdoc.Application.ActiveDocument.InlineShapes.AddPicture(imgpath, true, true, ref anchor);
                                        newapp.Selection.Move();
                                        Console.WriteLine("插入图片: " + imgpath);
                                    }
                                    var newtag = tag;
                                    if (tag != null && (tag.StartsWith(" img_type") || tag.Contains("src")))
                                    {
                                        newtag = "<img " + tag;
                                    }
                                    string text = Utils.NoHTML(newtag);
                                    if (text != null && !"".Equals(text))
                                    {
                                        //去除空格、插入文本b
                                        newapp.Selection.TypeText(text.Trim());
                                        newapp.Selection.Move();
                                        Console.WriteLine("插入文本: " + text);
                                    }
                                }
                            }
                        }
                        newapp.Selection.TypeParagraph();
                    }
                    catch (Exception et)
                    {
                        Console.WriteLine(et);
                    }
                }
                newapp.Selection.TypeParagraph();
                //清空粘贴板,否则会将前一次粘贴记录保留。
                Clipboard.SetDataObject("", true);
            }

            try
            {
                object fileFormat = Word.WdSaveFormat.wdFormatDocument;
                newdoc.SaveAs(ref name, fileFormat, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
                              ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing,
                              ref nothing, ref nothing);
            }
            catch (Exception ex)
            {
                try
                {
                    newdoc.Close(ref nothing, ref nothing, ref nothing);
                }
                catch (Exception tt)
                {
                    Console.WriteLine(tt);
                }
                Console.WriteLine(ex);
            }
            finally
            {
                excel.Quit();
                newapp.Quit();
                excel  = null;
                newdoc = null;
                newapp = null;
                Utils.deleteFile(imgs);
            }
            return(ResultCode.SUCCESS);
        }