Beispiel #1
0
        //保存文件
        public static bool SaveFile(string filePath, MyNode myNode)
        {
            try
            {
                //初始化
                object fileobj = filePath;
                object unknow  = System.Reflection.Missing.Value;
                //打开word程序,创建一个新的word文档,但是还没有保存到硬盘中
                ApplicationClass wordApp = new ApplicationClass();
                _Document        doc     = wordApp.Documents.Add(ref unknow, ref unknow, ref unknow, ref unknow);

                //这里开始写文件
                //深度优先遍历
                //saveNode(doc, myNode,1);


                //保存word文档
                doc.SaveAs(ref fileobj, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);
                doc.Close(ref unknow, ref unknow, ref unknow);
                wordApp.Documents.Save(ref unknow, ref unknow);
                wordApp.Quit(ref unknow, ref unknow, ref unknow);
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #2
0
        //保存新文件
        public void SaveDocument(string filePath)
        {
            object fileName = filePath;
            object format   = WdSaveFormat.wdFormatDocument;//保存格式
            object miss     = System.Reflection.Missing.Value;

            while (true)
            {
                try
                {
                    wordDoc.SaveAs(ref fileName, ref format, ref miss,
                                   ref miss, ref miss, ref miss, ref miss,
                                   ref miss, ref miss, ref miss, ref miss,
                                   ref miss, ref miss, ref miss, ref miss,
                                   ref miss);
                    break;
                }
                catch (COMException ex)
                {
                    if (System.Windows.Forms.MessageBox.Show("发生错误,错误码为:" + ex.ErrorCode.ToString() + "\r\n请检查" + fileName + "是否已经打开\r\n是否重试", "发生错误", System.Windows.Forms.MessageBoxButtons.RetryCancel) == System.Windows.Forms.DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }
            //关闭wordDoc,wordApp对象
            object SaveChanges    = WdSaveOptions.wdSaveChanges;
            object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat;
            object RouteDocument  = false;

            wordDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            wordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
        }
Beispiel #3
0
        public bool save(string str)
        {
            if (this.word == null)
            {
                return(false);
            }

            //Save the file, use default values except for filename.  The
            //DocumentBeforeSave event will fire.
            object fileName = str; //+= "_new";

            try
            {
                _Document doc      = word.ActiveDocument;
                object    optional = Missing.Value;

                doc.SaveAs(ref fileName,
                           ref optional, ref optional, ref optional,
                           ref optional, ref optional, ref optional,
                           ref optional, ref optional, ref optional,
                           ref optional, ref optional, ref optional,
                           ref optional, ref optional, ref optional);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 动态生成Word文档并填充内容
        /// </summary>
        /// <param name="dir">文档目录</param>
        /// <param name="fileName">文档名</param>
        /// <returns>返回自定义信息</returns>
        public static bool CreateWordFile(string dir, string fileName)
        {
            try
            {
                Object oMissing = System.Reflection.Missing.Value;

                if (!Directory.Exists(dir))
                {
                    //创建文件所在目录
                    Directory.CreateDirectory(dir);
                }

                //创建Word文档(Microsoft.Office.Interop.Word)
                _Application WordApp = new Application();
                //WordApp.Visible = true;
                _Document WordDoc = WordApp.Documents.Add(
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                //保存
                object filename = dir + fileName;
                WordDoc.SaveAs(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);
                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);
            }
        }
Beispiel #5
0
        public void CreateDocument(string docFilePath, Image image)
        {
            _Application oWord = new Microsoft.Office.Interop.Word.Application();
            //Nếu tạo một Document
            _Document oDoc = oWord.Documents.Add();

            //Nếu mở một Document
            //Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Open(docFilePath, ReadOnly: false, Visible: true);

            //Để xem điều gì đang xảy ra trong khi điền tập tài liệu từ Visible = true
            oWord.Visible = true;

            //Chèn ảnh từ mảng byte vào MS Word, sử dụng Clipboard để dán Image vào tài liệu
            Object oMissing = System.Reflection.Missing.Value;

            Clipboard.SetDataObject(image);
            var oPara = oDoc.Content.Paragraphs.Add(ref oMissing);

            oPara.Range.Paste();
            oPara.Range.InsertParagraphAfter();

            //Nếu tạo document
            oDoc.SaveAs(docFilePath);
            //Nếu mở một document
            //oDoc.Save();
            oDoc.Close();
            oWord.Quit();
        }
Beispiel #6
0
 private void SaveAs(string SaveAsPath)
 {
     System.IO.FileInfo fileInfo = new System.IO.FileInfo(SaveAsPath);
     if (fileInfo.Extension.ToLower().Equals(".pdf"))
     {
         base.ConvertToPdf(SaveAsPath);
     }
     else
     {
         object    obj      = SaveAsPath;
         _Document arg_C9_0 = this.WordApp.ActiveDocument;
         object    value    = System.Reflection.Missing.Value;
         object    value2   = System.Reflection.Missing.Value;
         object    value3   = System.Reflection.Missing.Value;
         object    value4   = System.Reflection.Missing.Value;
         object    value5   = System.Reflection.Missing.Value;
         object    value6   = System.Reflection.Missing.Value;
         object    value7   = System.Reflection.Missing.Value;
         object    value8   = System.Reflection.Missing.Value;
         object    value9   = System.Reflection.Missing.Value;
         object    value10  = System.Reflection.Missing.Value;
         object    value11  = System.Reflection.Missing.Value;
         object    value12  = System.Reflection.Missing.Value;
         object    value13  = System.Reflection.Missing.Value;
         object    value14  = System.Reflection.Missing.Value;
         object    value15  = System.Reflection.Missing.Value;
         arg_C9_0.SaveAs(ref obj, ref value, ref value2, ref value3, ref value4, ref value5, ref value6, ref value7, ref value8, ref value9, ref value10, ref value11, ref value12, ref value13, ref value14, ref value15);
     }
 }
Beispiel #7
0
        //保存新文件
        public void SaveDocument(string filePath)
        {
            object fileName = filePath;
            object format   = WdSaveFormat.wdFormatDocument;//保存格式

            //object miss =System.Reflection.Missing.Value;
            try
            {
                wordDoc.SaveAs(ref fileName, ref miss, ref miss,
                               ref miss, ref miss, ref miss, ref miss,
                               ref miss, ref miss, ref miss, ref miss,
                               ref miss, ref miss, ref miss, ref miss,
                               ref miss);
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
            //关闭wordDoc,wordApp对象
            object SaveChanges    = WdSaveOptions.wdSaveChanges;
            object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat;
            object RouteDocument  = false;

            wordDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            wordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
        }
Beispiel #8
0
        private void makePlanBTN_Click(object sender, EventArgs e)
        {
            var dialogResult = MessageBox.Show(@"Вы действительно хотите составить план за " + monthTB.Text.ToLower() + @" " + yearTB.Text + @" года?",
                                               @"Создание плана", MessageBoxButtons.YesNo);

            if (dialogResult != DialogResult.Yes)
            {
                return;
            }
            _Application application = new Application();
            _Document    document    = application.Documents.Add();
            Paragraph    paragraph   = document.Content.Paragraphs.Add();

            application.Visible = true;

            paragraph.Range.Font.Bold = 0;
            paragraph.Range.Font.Size = 14;
            paragraph.Range.Font.Name = "Times New Roman";
            paragraph.Alignment       = WdParagraphAlignment.wdAlignParagraphLeft;
            paragraph.Range.Text      = $"Дата: {monthTB.Text.ToLower()} {yearTB.Text} год\n" +
                                        $"Количество заказов: {numOrdersTB.Text}\n" +
                                        $"Доход: {incomeTB.Text} руб.\n" +
                                        $"Расход: {consumptionTB.Text} руб.\n" +
                                        $"Чистый заработок: {Convert.ToInt32(incomeTB.Text) - Convert.ToInt32(consumptionTB.Text)} руб.";
            document.SaveAs(Environment.CurrentDirectory + "\\Планы\\" + monthTB.Text.ToLower() + "_" + yearTB.Text, WdSaveFormat.wdFormatDocumentDefault);
        }
Beispiel #9
0
        //保存新文件

        public void SaveDocument(string filePath)

        {
            object fileName = filePath;

            object format = WdSaveFormat.wdFormatDocument;//保存格式

            object miss = System.Reflection.Missing.Value;

            wordDoc.SaveAs(ref fileName, ref format, ref miss,

                           ref miss, ref miss, ref miss, ref miss,

                           ref miss, ref miss, ref miss, ref miss,

                           ref miss, ref miss, ref miss, ref miss,

                           ref miss);

            //关闭wordDocwordApp对象

            object SaveChanges = WdSaveOptions.wdSaveChanges;

            object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat;

            object RouteDocument = false;

            wordDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);

            wordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
        }
Beispiel #10
0
        public Word._Application oWord = new Word.Application(); // создаем документ Ворд

        public void OpenSaveDocMethod(string pathopen, string pathsave, MyDelegateWord temp)
        {
            // Берем шаблон присваиваем закладкам параметры и сохраняем его
            _Document oDoc = oWord.Documents.Add(Environment.CurrentDirectory + pathopen);

            temp.DynamicInvoke(oDoc);
            oDoc.SaveAs(Environment.CurrentDirectory + pathsave);
            oDoc.Close();
        }
Beispiel #11
0
        // 保存新文件
        public void SaveDocument(string filePath)
        {
            wordApp.Visible = false;  //不可见直接保存

            wordDoc.SaveAs(filePath); //保存

            wordDoc.Close(true);      //关闭

            wordApp.Quit();           //释放Word进程
        }
Beispiel #12
0
        public void SaveAs(string fileName)
        {
            object obj_FileName = fileName;

            if (m_Document != null)
            {
                m_Document.SaveAs(ref obj_FileName, 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, ref missing);
            }
        }
Beispiel #13
0
 public static void saveFile()
 {
     try
     {
         oDoc.SaveAs(path + filename);
         oDoc.Close();
         oWord.Quit();
         //realease from memory and call the GC
         releaseObject(oDoc);
         releaseObject(oWord);
     }catch (Exception e)
     {
         Console.WriteLine("Error saving the Word Doc: " + filename);
     }
 }
Beispiel #14
0
        // Вывод текста в ворд файл
        private void сохранитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (label27.Text != "")
            {
                oWord = new Word.Application();

                // Считывает шаблон и сохраняет измененный в новом
                _Document oDoc = GetDoc(Environment.CurrentDirectory + "\\pattern.docx");
                oDoc.SaveAs(FileName: Environment.CurrentDirectory + "\\РЕЦЕНЗИЯ.docx");
                string Filename = @"РЕЦЕНЗИЯ.docx";
                Process.Start(Filename);

                oDoc.Close();
            }
            else
            {
                MessageBox.Show("Чтобы «Сохранить WORD» необходимо сформировать очет - Ctr+G", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #15
0
        private void method(object sender, EventArgs e)
        {
            int i = 0;

            foreach (Bookmark bookmark in oDoc.Bookmarks)
            {
                //bookmark.Range.Font.Underline = WdUnderline.wdUnderlineSingle;
                string   text  = Controls["TextBox" + i].Text;
                CheckBox check = Controls["Check" + i] as CheckBox;
                if (check.Checked)
                {
                    String str = RusNumber.Str(int.Parse(text)).TrimEnd(' ');
                    text = text + " (" + str + ")";
                }
                bookmark.Range.Text = text;
                i++;
            }
            oDoc.SaveAs(Environment.CurrentDirectory + "\\" + name + ".docx");
            oDoc.Close();
            Close();
        }
Beispiel #16
0
 /// <summary>
 /// 保存新文件
 /// </summary>
 /// <param name="filePath">文件路径</param>
 public void SaveDocument(string filePath)
 {
     try
     {
         object fileName = filePath;
         object miss     = System.Reflection.Missing.Value;
         wordDoc.SaveAs(ref fileName, ref miss, ref miss,
                        ref miss, ref miss, ref miss, ref miss,
                        ref miss, ref miss, ref miss, ref miss,
                        ref miss, ref miss, ref miss, ref miss,
                        ref miss);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.Dispose();
     }
 }
Beispiel #17
0
 public void ChangeDebuug(string file)
 {
     try
     {
         if (base.LoadSourceFile(file))
         {
             this.WordApp.ActiveDocument.ActiveWindow.View.Type            = WdViewType.wdPrintView;
             this.WordApp.ActiveDocument.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
             object    obj      = file;
             object    obj2     = WdSaveFormat.wdFormatDocumentDefault;
             _Document arg_E8_0 = this.WordApp.ActiveDocument;
             object    value    = System.Reflection.Missing.Value;
             object    value2   = System.Reflection.Missing.Value;
             object    value3   = System.Reflection.Missing.Value;
             object    value4   = System.Reflection.Missing.Value;
             object    value5   = System.Reflection.Missing.Value;
             object    value6   = System.Reflection.Missing.Value;
             object    value7   = System.Reflection.Missing.Value;
             object    value8   = System.Reflection.Missing.Value;
             object    value9   = System.Reflection.Missing.Value;
             object    value10  = System.Reflection.Missing.Value;
             object    value11  = System.Reflection.Missing.Value;
             object    value12  = System.Reflection.Missing.Value;
             object    value13  = System.Reflection.Missing.Value;
             object    value14  = System.Reflection.Missing.Value;
             arg_E8_0.SaveAs(ref obj, ref obj2, ref value, ref value2, ref value3, ref value4, ref value5, ref value6, ref value7, ref value8, ref value9, ref value10, ref value11, ref value12, ref value13, ref value14);
         }
     }
     catch (System.Exception var_2_F2)
     {
     }
     finally
     {
         base.Dispose();
     }
 }
Beispiel #18
0
        // Convert method
        public static void Convert(string input, string output, WdSaveFormat format)
        {
            // Create an instance of Word.exe
            _Application oWord = new Word.Application
            {
                // Make this instance of word invisible (Can still see it in the taskmgr).
                Visible = false
            };
            // Interop requires objects.
            object oMissing  = System.Reflection.Missing.Value;
            object isVisible = true;
            object readOnly  = true;    // Does not cause any word dialog to show up
            //object readOnly = false;  // Causes a word object dialog to show at the end of the conversion
            object oInput  = input;
            object oOutput = output;
            object oFormat = format;

            // Load a document into our instance of word.exe
            _Document oDoc = oWord.Documents.Open(
                ref oInput, ref oMissing, ref readOnly, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing
                );

            // Make this document the active document.
            oDoc.Activate();

            // Save this document using Word
            oDoc.SaveAs(ref oOutput, ref oFormat, 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
                        );

            // Always close Word.exe.
            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
        }
Beispiel #19
0
        private static void createJFJZYYDLYXZXWord(DataModel model, string folderPath, string date)
        {
            string templatePath = getTemplateFullPath();

            if (!Directory.Exists(templatePath))
            {
                Directory.CreateDirectory(templatePath);
            }
            string toPath = folderPath + "\\" + model.HospitalName;

            if (!Directory.Exists(toPath))
            {
                Directory.CreateDirectory(toPath);
            }

            object oMissing = System.Reflection.Missing.Value;
            //创建一个Word应用程序实例
            _Application oWord = new Application();

            //设置为不可见
            oWord.Visible = false;
            //模板文件地址,这里假设在X盘根目录
            object oTemplate = templatePath + "\\" + model.HospitalName + ".dot";
            //以模板为基础生成文档
            _Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

            //声明书签数组
            object[] oBookMark = new object[54];
            //赋值书签名
            oBookMark[0] = "PatientID";
            oBookMark[1] = "Sex";
            oBookMark[2] = "Age";
            oBookMark[3] = "SampleNo";
            oBookMark[4] = "PatientName";

            oBookMark[5] = "Division";
            oBookMark[6] = "AdministrativeOffice";
            oBookMark[7] = "ClinicalDiagnosis";
            oBookMark[8] = "OutpatientNo";
            oBookMark[9] = "Samples";

            oBookMark[10] = "SampleProject";

            oBookMark[11] = "ProjectENName1";
            oBookMark[12] = "ProjectCNName1";
            oBookMark[13] = "Result1";
            oBookMark[14] = "ReferenceValue1";

            oBookMark[15] = "ProjectENName2";
            oBookMark[16] = "ProjectCNName2";
            oBookMark[17] = "Result2";
            oBookMark[18] = "ReferenceValue2";

            oBookMark[19] = "ProjectENName3";
            oBookMark[20] = "ProjectCNName3";
            oBookMark[21] = "Result3";
            oBookMark[22] = "ReferenceValue3";

            oBookMark[23] = "ProjectENName4";
            oBookMark[24] = "ProjectCNName4";
            oBookMark[25] = "Result4";
            oBookMark[26] = "ReferenceValue4";

            oBookMark[27] = "ProjectENName5";
            oBookMark[28] = "ProjectCNName5";
            oBookMark[29] = "Result5";
            oBookMark[30] = "ReferenceValue5";

            oBookMark[31] = "ProjectENName6";
            oBookMark[32] = "ProjectCNName6";
            oBookMark[33] = "Result6";
            oBookMark[34] = "ReferenceValue6";

            oBookMark[35] = "Remark";
            oBookMark[36] = "Doctor";
            oBookMark[37] = "Ratifyer";
            oBookMark[38] = "MainInspectioner";
            oBookMark[39] = "Auditer";

            oBookMark[40] = "SamplingTime";
            oBookMark[41] = "ReportTime";
            oBookMark[42] = "MainInspectionLab";
            oBookMark[43] = "Phone";

            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model.PatientID;
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model.Sex;
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model.Age;
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model.SampleNo;
            oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model.PatientName;

            oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model.Division;
            oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = model.AdministrativeOffice;
            oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = model.ClinicalDiagnosis;
            oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = model.OutpatientNo;
            oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text = model.Samples;

            oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model.SampleProject;

            oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model.Remark;
            oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model.Doctor;
            oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model.Ratifyer;
            oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model.MainInspectioner;
            oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model.Auditer;
            oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model.SamplingTime;
            oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model.ReportTime;
            oDoc.Bookmarks.get_Item(ref oBookMark[42]).Range.Text = model.MainInspectionLab;
            oDoc.Bookmarks.get_Item(ref oBookMark[43]).Range.Text = AppManager.Instance.Phone;

            if (model.PList.Count > 0)
            {
                ProjectModel pModel = model.PList[0];
                oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = pModel.ProjectENName;
                oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = pModel.ProjectCNName;
                oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = pModel.Result;
                oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = pModel.ReferenceValue;
                model.PList.Remove(pModel);
            }

            if (model.PList.Count > 0)
            {
                ProjectModel pModel = model.PList[0];
                oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = pModel.ProjectENName;
                oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = pModel.ProjectCNName;
                oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = pModel.Result;
                oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = pModel.ReferenceValue;
                model.PList.Remove(pModel);
            }
            if (model.PList.Count > 0)
            {
                ProjectModel pModel = model.PList[0];
                oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = pModel.ProjectENName;
                oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = pModel.ProjectCNName;
                oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = pModel.Result;
                oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = pModel.ReferenceValue;
                model.PList.Remove(pModel);
            }
            if (model.PList.Count > 0)
            {
                ProjectModel pModel = model.PList[0];
                oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = pModel.ProjectENName;
                oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = pModel.ProjectCNName;
                oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = pModel.Result;
                oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = pModel.ReferenceValue;
                model.PList.Remove(pModel);
            }
            if (model.PList.Count > 0)
            {
                ProjectModel pModel = model.PList[0];
                oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = pModel.ProjectENName;
                oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = pModel.ProjectCNName;
                oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = pModel.Result;
                oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = pModel.ReferenceValue;
                model.PList.Remove(pModel);
            }
            if (model.PList.Count > 0)
            {
                ProjectModel pModel = model.PList[0];
                oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = pModel.ProjectENName;
                oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = pModel.ProjectCNName;
                oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = pModel.Result;
                oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = pModel.ReferenceValue;
                model.PList.Remove(pModel);
            }


            object filename = toPath + "\\" + model.PatientName + "_" + date + ".docx";

            oDoc.SaveAs(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);

            oWord.Quit(WdSaveOptions.wdDoNotSaveChanges);
        }
        static void Main(string[] args)
        {
            object optional         = Missing.Value;
            object endOfDocBookmark = "\\endofdoc";             /* \endofdoc is a predefined bookmark */

            // start Word
            _Application word = new Application();

            word.Visible = false;

            // create new document
            _Document document = word.Documents.Add(ref optional, ref optional, ref optional, ref optional);

            // insert a paragraph at the beginning of the document
            Paragraph paragraph1 = document.Content.Paragraphs.Add(ref optional);

            paragraph1.Range.Text        = "Heading 1";
            paragraph1.Range.Font.Bold   = 1;
            paragraph1.Format.SpaceAfter = 24;             // 24 pt spacing after paragraph
            paragraph1.Range.InsertParagraphAfter();

            // insert another paragraph
            object    range      = document.Bookmarks.get_Item(ref endOfDocBookmark).Range;
            Paragraph paragraph2 = document.Content.Paragraphs.Add(ref range);

            paragraph2.Range.Text        = "This is a sentence of normal text. Now here is a table:";
            paragraph2.Range.Font.Bold   = 0;
            paragraph2.Format.SpaceAfter = 24;
            paragraph2.Range.InsertParagraphAfter();


            // insert a 5 x 2 table, make the first header row bold and italic
            range = document.Bookmarks.get_Item(ref endOfDocBookmark).Range;
            Table table = document.Tables.Add((Range)range, 5, 2, ref optional, ref optional);

            table.Cell(1, 1).Range.Text     = "Value";           // 1st column header
            table.Cell(1, 2).Range.Text     = "Barcode";         // 2nd column header
            table.Rows[1].Range.Font.Bold   = 1;
            table.Rows[1].Range.Font.Italic = 1;
            AddBorders(table.Cell(1, 1).Range);
            AddBorders(table.Cell(1, 2).Range);

            Random random    = new Random();
            string tempImage = Path.Combine(Path.GetTempPath(), "tempImage.png");

            // create barcode object
            Barcode barcode = new Barcode("demo", "demo");

            barcode.Symbology   = SymbologyType.Code128;
            barcode.DrawCaption = false;

            // fill the table with random data and add barcode images
            for (int row = 2; row <= 5; row++)
            {
                string randomValue = random.Next().ToString(CultureInfo.InvariantCulture);
                Range  cell        = table.Cell(row, 1).Range;
                cell.Text = randomValue;

                AddBorders(cell);

                // generate barcode and save it to temporary image file
                barcode.Value = randomValue;
                barcode.SaveImage(tempImage);

                // put barcode image to second column
                cell = table.Cell(row, 2).Range;
                cell.InlineShapes.AddPicture(tempImage, ref optional, ref optional, ref optional);

                AddBorders(cell);
            }


            // save document
            object fileName = @"sample.doc";             // use full file path in your app

            document.SaveAs(ref fileName, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional, ref optional);

            // quit Word
            object saveChanges = true;

            word.Quit(ref saveChanges, ref optional, ref optional);

            System.Diagnostics.Process.Start((string)fileName);
        }
Beispiel #21
0
        internal void SaveAsRtf(object fileName)
        {
            object format = WdSaveFormat.wdFormatRTF;

            oDoc.SaveAs(ref fileName, ref format, 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);
        }
Beispiel #22
0
 public void SaveAs(_Document doc, string fileFullName)
 {
     doc.SaveAs(fileFullName, 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);
 }
Beispiel #23
0
        public static bool ConvertToNewOfficeDocument(string fileName, out string newFileName, out string newExt)
        {
            var ext = Path.GetExtension(fileName).ToLower();

            newExt = ext;

            newFileName = fileName;

            if (!DestinationDictionary.ContainsKey(ext))
            {
                return(false);
            }
            if (fileName.StartsWith("~*"))
            {
                return(false);
            }

            var dest = DestinationDictionary[ext];

            newExt = dest.Extension;

            newFileName = ReplaceExtension(fileName, dest.Extension);

            object obj;

            var result = true;

            switch (dest.Application)
            {
            case OfficeApplication.Word:
                if (_wordApp == null)
                {
                    _wordApp = new Application();
                }
                _Document wordDoc = null;

                try
                {
                    wordDoc = _wordApp.Documents.Open(fileName);
                    wordDoc.Convert();
                    if (wordDoc.HasVBProject)
                    {
                        newFileName = ReplaceExtension(newFileName, ".docm");
                        dest        = new OfficeDestination(OfficeApplication.Word, ".docm",
                                                            WdSaveFormat.wdFormatXMLDocumentMacroEnabled); //for files with macro
                    }
                    wordDoc.SaveAs(newFileName, dest.FileFormat);
                }
                catch (Exception e)
                {
                    newFileName = fileName;
                    result      = false;
                    DisplayError(fileName, e);
                }
                finally
                {
                    if (wordDoc != null)
                    {
                        wordDoc.Close();
                        obj = wordDoc;
                        DisposeInteropObject(ref obj);
                    }
                    if (!KeepOpen || !result)
                    {
                        _wordApp.Quit();
                        obj = _wordApp;
                        DisposeInteropObject(ref obj);
                        _wordApp = null;
                    }
                }
                break;

            case OfficeApplication.Excel:
                if (_excelApp == null)
                {
                    _excelApp = new Microsoft.Office.Interop.Excel.Application();
                }
                _Workbook excelDoc = null;
                try
                {
                    excelDoc = _excelApp.Workbooks.Open(fileName);
                    if (excelDoc.HasVBProject)
                    {
                        newFileName = ReplaceExtension(newFileName, ".xlsm");
                        dest        = new OfficeDestination(OfficeApplication.Excel, ".xlsm",
                                                            XlFileFormat.xlOpenXMLWorkbookMacroEnabled); //for files with macro
                    }
                    excelDoc.SaveAs(newFileName, dest.FileFormat);
                }
                catch (Exception e)
                {
                    newFileName = fileName;
                    result      = false;
                    DisplayError(fileName, e);
                }
                finally
                {
                    if (excelDoc != null)
                    {
                        excelDoc.Close();
                        obj = excelDoc;
                        DisposeInteropObject(ref obj);
                    }
                    if (!KeepOpen || !result)
                    {
                        _excelApp.Quit();
                        obj = _excelApp;
                        DisposeInteropObject(ref obj);
                        _excelApp = null;
                    }
                }
                break;

            case OfficeApplication.PowerPoint:
                if (_powerpointApp == null)
                {
                    _powerpointApp = new Microsoft.Office.Interop.PowerPoint.Application();
                }
                _Presentation powerpointDoc = null;
                try
                {
                    powerpointDoc = _powerpointApp.Presentations.Open(fileName, MsoTriState.msoTrue,
                                                                      MsoTriState.msoTrue, MsoTriState.msoFalse);
                    if (powerpointDoc.HasVBProject)
                    {
                        newFileName = ReplaceExtension(newFileName, ".pptm");
                        dest        = new OfficeDestination(OfficeApplication.PowerPoint, ".pptm",
                                                            PpSaveAsFileType.ppSaveAsOpenXMLPresentationMacroEnabled); //for files with macro
                    }
                    powerpointDoc.SaveAs(newFileName, (PpSaveAsFileType)dest.FileFormat);
                }
                catch (Exception e)
                {
                    newFileName = fileName;
                    result      = false;
                    DisplayError(fileName, e);
                }
                finally
                {
                    if (powerpointDoc != null)
                    {
                        powerpointDoc.Close();
                        obj = powerpointDoc;
                        DisposeInteropObject(ref obj);
                    }
                    if (!KeepOpen || !result)
                    {
                        _powerpointApp.Quit();
                        obj = _powerpointApp;
                        DisposeInteropObject(ref obj);
                        _powerpointApp = null;
                    }
                }
                break;
            }

            GarbageCollector();
            return(result);
        }
Beispiel #24
0
    /// <summary>
    /// A function that merges Microsoft Word Documents that uses a template specified by the user
    /// </summary>
    /// <param name="filesToMerge">An array of files that we want to merge</param>
    /// <param name="outputFilename">The filename of the merged document</param>
    /// <param name="insertPageBreaks">Set to true if you want to have page breaks inserted after each document</param>
    /// <param name="documentTemplate">The word document you want to use to serve as the template</param>
    public static void Merge(string[] filesToMerge, string outputFilename, bool insertPageBreaks, string documentTemplate)
    {
        object defaultTemplate = documentTemplate;
        object missing         = System.Type.Missing;
        object pageBreak       = Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
        object outputFile      = outputFilename;

        // Create  a new Word application
        _Application wordApplication = new Application();

        try
        {
            // Create a new file based on our template
            _Document wordDocument = wordApplication.Documents.Add(
                ref defaultTemplate
                , ref missing
                , ref missing
                , ref missing);

            // Make a Word selection object.
            Selection selection = wordApplication.Selection;

            // Loop thru each of the Word documents
            foreach (string file in filesToMerge)
            {
                // Insert the files to our template
                selection.InsertFile(
                    file
                    , ref missing
                    , ref missing
                    , ref missing
                    , ref missing);

                //Do we want page breaks added after each documents?
                if (insertPageBreaks)
                {
                    selection.InsertBreak(ref pageBreak);
                }
            }

            // Save the document to it's output file.
            wordDocument.SaveAs(
                ref outputFile
                , 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
                , ref missing);

            // Clean up!
            wordDocument = null;
        }
        catch (Exception ex)
        {
            //I didn't include a default error handler so i'm just throwing the error
            throw ex;
        }
        finally
        {
            // Finally, Close our Word application
            wordApplication.Quit(ref missing, ref missing, ref missing);
        }
    }
 private void SaveDocument(_Document document, string output)
 {
     object missing = System.Reflection.Missing.Value;
     Directory.CreateDirectory(Path.GetDirectoryName(output));
     object filePath = output;
     document.SaveAs(ref filePath, 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, ref missing);
 }
Beispiel #26
0
        /// <summary>
        /// 采购合同
        /// </summary>
        /// <param name="templatePath"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string ExportPurchaseContract(string templatePath, Item model, string email)
        {
            object oMissing = System.Reflection.Missing.Value;
            //创建一个Word应用程序实例
            _Application oWord = new Application();

            //设置为不可见
            oWord.Visible = false;
            //模板文件地址
            object oTemplate = templatePath;

            //获取单据编号
            string b_prrecordNo = model.getProperty("b_prrecordno");

            //保存路径
            object filename = ConfigurationManager.AppSettings["DownloadContractPath"] + b_prrecordNo + ".doc";

            //以模板为基础生成文档
            _Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

            //声明书签数组
            object[] oBookMark = new object[9];
            //赋值书签名
            oBookMark[0] = "b_PrRecordNo";
            oBookMark[1] = "b_Buyer";
            oBookMark[2] = "BuyerAddress";
            oBookMark[3] = "InvoiceAddress";
            oBookMark[4] = "BankUserName";
            oBookMark[5] = "BankAccount";
            oBookMark[6] = "OpenBank";
            oBookMark[7] = "DutyParagraph";
            oBookMark[8] = "BuyerEmail";
            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model.getProperty("b_prrecordno");
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model.getProperty("b_buyer");
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "上海市闵行区江月路1599号2楼,4-6楼";
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "上海市闵行区江月路1599号2楼,4-6楼 " + model.getProperty("b_buyer");
            oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = email;

            //获取判断签约方
            string b_ContractParty = model.getProperty("b_contractparty");

            if (b_ContractParty.Contains("上海思致汽车工程技术有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "上海思致汽车工程技术有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "31001511920052503427";
                oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = "建设银行上海长寿路支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = "91310115677893509Y";
            }
            else if (b_ContractParty.Contains("南京盛和新能源科技有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "南京盛和新能源科技有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "93190154740001692";
                oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = "上海浦东发展银行股份有限公司南京浦口支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = "91320111MA1NR9UH1M";
            }
            else if (b_ContractParty.Contains("淮安骏盛新能源科技有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "淮安骏盛新能源科技有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "492370493139";
                oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = "中国银行股份有限公司淮安淮阴支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = "91320804MA1P6Q435W";
            }
            else if (b_ContractParty.Contains("南京博郡新能源汽车有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "南京博郡新能源汽车有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "93190154740001502";
                oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = "浦发银行南京浦口支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = "91320111MA1N3BWF2G";
            }
            else if (b_ContractParty.Contains("南京博郡汽车有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "南京博郡汽车有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "93190154740001721";
                oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = "上海浦东发展银行股份有限公司南京浦口支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = "91320111MA1NTGNJ3T";
            }


            //需求列表信息
            Item Relation = model.getRelationships("b_RequestInfo");
            //需求信息
            int count = Relation.getItemCount();

            //在表格中添加行
            var tableObj = oDoc.Content.Tables[1];
            //添加行所在的位置
            Row row = tableObj.Rows[12];

            for (int i = 0; i < count - 1; i++)
            {
                oDoc.Content.Tables[1].Rows.Add(row);
            }

            for (int index = 0; index < Relation.getItemCount(); index++)
            {
                int  nindex  = index + 12;
                Item ItemObJ = Relation.getItemByIndex(index).getRelatedItem();
                tableObj.Cell(nindex, 1).Range.Text = (index + 1).ToString();
                tableObj.Cell(nindex, 2).Range.Text = ItemObJ.getProperty("b_requestlist");
                tableObj.Cell(nindex, 3).Range.Text = ItemObJ.getProperty("b_specificationquantity");
                tableObj.Cell(nindex, 4).Range.Text = ItemObJ.getProperty("b_qty");
                tableObj.Cell(nindex, 5).Range.Text = ItemObJ.getProperty("b_unit");
            }

            oDoc.SaveAs(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);
            oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
            //关闭word
            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);


            return(filename.ToString());
        }
Beispiel #27
0
        private void Save(_Document document, Object path)
        {
            Object pathToSaveObj = path;

            document.SaveAs(ref pathToSaveObj, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj, ref missingObj);
        }
Beispiel #28
0
        /// <summary>
        /// 内部合同
        /// </summary>
        /// <param name="templatePath"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static string ExportInternalContract(string templatePath, Item model, string email)
        {
            object oMissing = System.Reflection.Missing.Value;
            //创建一个Word应用程序实例
            _Application oWord = new Application();

            //设置为不可见
            oWord.Visible = false;
            //模板文件地址
            object oTemplate = templatePath;

            //获取单据编号
            string b_prrecordNo = model.getProperty("b_prrecordno");

            //保存路径
            object filename = ConfigurationManager.AppSettings["DownloadContractPath"] + b_prrecordNo + ".doc";

            //以模板为基础生成文档
            _Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

            //声明书签数组
            object[] oBookMark = new object[8];
            oBookMark[0] = "b_Buyer";
            oBookMark[1] = "BuyerAddress";
            oBookMark[2] = "OpenBank";
            oBookMark[3] = "BankUserName";
            oBookMark[4] = "BankAccount";
            oBookMark[5] = "DutyParagraph";
            oBookMark[6] = "InvoiceAddress";
            oBookMark[7] = "BuyerEmail";

            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model.getProperty("b_buyer");
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = "上海市闵行区江月路1599号2楼,4-6楼";
            oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = "上海市闵行区江月路1599号2楼,4-6楼 " + model.getProperty("b_buyer");
            oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = email;

            //获取判断签约方
            string b_ContractParty = model.getProperty("b_contractparty");

            if (b_ContractParty.Contains("上海思致汽车工程技术有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "建设银行上海长寿路支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "上海思致汽车工程技术有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "31001511920052503427";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "91310115677893509Y";
            }
            else if (b_ContractParty.Contains("南京盛和新能源科技有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "上海浦东发展银行股份有限公司南京浦口支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "南京盛和新能源科技有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "93190154740001692";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "91320111MA1NR9UH1M";
            }
            else if (b_ContractParty.Contains("淮安骏盛新能源科技有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "中国银行股份有限公司淮安淮阴支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "淮安骏盛新能源科技有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "492370493139";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "91320804MA1P6Q435W";
            }
            else if (b_ContractParty.Contains("南京博郡新能源汽车有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "浦发银行南京浦口支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "南京博郡新能源汽车有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "93190154740001502";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "91320111MA1N3BWF2G";
            }
            else if (b_ContractParty.Contains("南京博郡汽车有限公司"))
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = "上海浦东发展银行股份有限公司南京浦口支行";
                oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = "南京博郡汽车有限公司";
                oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = "93190154740001721";
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "91320111MA1NTGNJ3T";
            }


            oDoc.SaveAs(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);
            oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
            //关闭word
            oWord.Quit(ref oMissing, ref oMissing, ref oMissing);


            return(filename.ToString());
        }