Ejemplo n.º 1
0
 private void QuitWPS(ref Word.Application wps, ref Document doc)
 {
     try
     {
         if (doc != null)
         {
             //doc.Save();
             doc.Close(false);
         }
         //无论是否成功,都退出
         if (wps != null)
         {
             PrintLog("Convert Word file To PDF end");
             wps.Quit(false);
         }
     }
     catch (Exception ex)
     {
         PrintLog(ex.Message.ToString());
         //m_nConvertStatus = EErrorType.OTP_EXCEPTION_FAILED;
     }
     finally
     {
         doc = null;
         wps = null;
     }
 }
Ejemplo n.º 2
0
 public static void QuitMsWordApp(bool isSaveDocument)
 {
     try
     {
         object saveOptionsObject = isSaveDocument ? WdSaveOptions.wdSaveChanges : WdSaveOptions.wdDoNotSaveChanges;
         if (_doc != null)
         {
             _doc.Close(ref saveOptionsObject, ref _objMiss, ref _objMiss);
             _doc.Application.Quit(ref _objMiss, ref _objMiss, ref _objMiss);
         }
     }
     catch { }
     finally
     {
         //--Closing the Word Application
         if (_msWord != null)
         {
             _msWord.Quit(ref _objMiss, ref _objMiss, ref _objMiss);
         }
         _doc    = null;
         _msWord = null;
         GC.Collect();
         GC.WaitForPendingFinalizers();
         GC.Collect();
         GC.WaitForPendingFinalizers();
     }
 }
Ejemplo n.º 3
0
        public void fSpellCheck(TextBox tBox, Label lLbl)
        {
            int iErrorCount = 0;

            Word.Application app = new Word.Application();
            if (tBox.Text.Length > 0)
            {
                app.Visible = false;
                // Setting these variables is comparable to passing null to the function.
                // This is necessary because the C# null cannot be passed by reference.
                object template     = Missing.Value;
                object newTemplate  = Missing.Value;
                object documentType = Missing.Value;
                object visible      = true;
                object optional     = Missing.Value;

                _Document doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                doc.Words.First.InsertBefore(tBox.Text);
                Word.ProofreadingErrors we = doc.SpellingErrors;
                iErrorCount = we.Count;

                doc.CheckSpelling(ref optional, ref optional, ref optional, ref optional,
                                  ref optional, ref optional, ref optional,
                                  ref optional, ref optional, ref optional, ref optional, ref optional);

                if (iErrorCount == 0)
                {
                    lLbl.Text = "Spelling OK. No errors corrected ";
                }
                else if (iErrorCount == 1)
                {
                    lLbl.Text = "Spelling OK. 1 error corrected ";
                }
                else
                {
                    lLbl.Text = "Spelling OK. " + iErrorCount + " errors corrected ";
                }
                object first = 0;
                object last  = doc.Characters.Count - 1;

                tBox.Text = doc.Range(ref first, ref last).Text;
            }
            else
            {
                lLbl.Text = "Textbox is empty";
            }

            object saveChanges    = false;
            object originalFormat = Missing.Value;
            object routeDocument  = Missing.Value;

            app.Quit(ref saveChanges, ref originalFormat, ref routeDocument);
        }
Ejemplo n.º 4
0
    public void CreateWord()
    {
        if (System.IO.File.Exists((string)strFileName))
        {
            System.IO.File.Delete((string)strFileName);
        }
        Nothing   = System.Reflection.Missing.Value;
        myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing,
                                            ref Nothing, ref Nothing);

        myWordDoc.Paragraphs.Last.Range.Text = strContent;

        myWordDoc.SaveAs(ref strFileName, 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);
        myWordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
        myWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
    }
Ejemplo n.º 5
0
        //转化
        public static void WordToHtmlFile(string WordFilePath, string htmlpath)
        {
            try
            {
                Word.Application newApp = new Word.Application();
                // 指定原文件和目标文件
                object Source = WordFilePath;
                //string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";
                object Target = htmlpath;

                // 缺省参数
                object Unknown = Type.Missing;

                //为了保险,只读方式打开
                object readOnly = true;

                // 打开doc文件
                Word.Document doc = newApp.Documents.Open(ref Source, ref Unknown,
                                                          ref readOnly, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown, ref Unknown,
                                                          ref Unknown, ref Unknown);

                // 指定另存为格式(rtf)
                object format = Word.WdSaveFormat.wdFormatHTML;
                // 转换格式
                doc.SaveAs(ref Target, ref format,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown, ref Unknown,
                           ref Unknown, ref Unknown);

                // 关闭文档和Word程序
                doc.Close(ref Unknown, ref Unknown, ref Unknown);
                newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 6
0
        public override void process(DataRow[] drTables, DataSet dsTableColumns, DataSet dsTablePrimaryKeys)
        {
            try
            {
                base.process(drTables, dsTableColumns, dsTablePrimaryKeys);
                OutPut = FilePathHelper.ExportDBDocPath;
                FileHelper.CreateDirectory(OutPut);


                setEnable(false);
                string    msg = string.Empty;
                Stopwatch sw  = Stopwatch.StartNew();
                FileHelper.DeleteDirectory(FilePathHelper.ExportDBDocPath);
                if (drTables != null && dsTableColumns != null && dsTablePrimaryKeys != null)
                {
                    setStatusBar(string.Format("正在生成{0}数据库文档", dbName));
                    setProgreesEditValue(0);
                    setProgress(0);
                    setProgressMax(drTables.Length);

                    string path = FilePathHelper.ExportDBDocPath + dbName + "_DB_{0}_{1}" + ".doc";

                    FileHelper.CreateDirectory(path);
                    Object           Nothing   = System.Reflection.Missing.Value;
                    Word.Application dbWordApp = new Word.Application();
                    dbWordApp.NormalTemplate.Saved = true;

                    Word.Document dbDoc = dbWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
                    dbWordApp.ActiveWindow.View.Type     = WdViewType.wdOutlineView;
                    dbWordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
                    dbWordApp.ActiveWindow.ActivePane.Selection.InsertAfter(string.Format("{0} {1}数据库文档", dbName, dbType));
                    dbWordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                    dbWordApp.ActiveWindow.View.SeekView          = WdSeekView.wdSeekMainDocument;
                    string tableName = "";
                    int    begin     = 0;
                    int    end       = 0;

                    #region

                    try
                    {
                        for (int j = 0; j < drTables.Length; j++)
                        {
                            try
                            {
                                if ((j + 1) % num == 0 || (j + 1).Equals(drTables.Length))
                                {
                                    begin = end;
                                    end   = j;
                                }

                                #region 样式

                                DataRow drTable = drTables[j];

                                DataRow[] drTableColumns =
                                    dsTableColumns.Tables[dbName + DBtablesColumns].Select(
                                        "TABLE_NAME = '" + drTable["name"].ToString() + "'", "COLUMN_ID ASC");

                                tableName = drTable["name"] as string;                //表名
                                string tableComments = drTable["comments"] as string; //表说明

                                setStatusBar(string.Format("正在生成{0}中{1}表信息,共{2}张表,已生成了{3}张表", dbName, tableName,
                                                           drTables.Length, j));


                                //Word段落
                                Word.Paragraph p;
                                p = dbDoc.Content.Paragraphs.Add(ref Nothing);
                                //设置段落中的内容文本
                                p.Range.Text = "表" + Convert.ToString(j + 1) + ":" + tableName + "(" +
                                               tableComments + ")";
                                //设置为一号标题
                                object style = Word.WdBuiltinStyle.wdStyleHeading1;
                                p.set_Style(ref style);
                                //添加到末尾
                                p.Range.InsertParagraphAfter();

                                style = Word.WdBuiltinStyle.wdStyleBodyText;
                                p.set_Style(ref style);

                                //dbWordApp.Selection.TypeText("表" + Convert.ToString(j + 1) + ":" + tableName + "(" +
                                //                             tableComments + ")");

                                dbWordApp.Selection.ParagraphFormat.LineSpacing = 15f;
                                object count  = 20;
                                object WdLine = Word.WdUnits.wdLine;
                                dbWordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);

                                Word.Table newTable = dbDoc.Tables.Add(dbWordApp.Selection.Range,
                                                                       drTableColumns.Length + 2, 7, ref Nothing,
                                                                       ref Nothing);

                                newTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
                                newTable.Borders.InsideLineStyle  = Word.WdLineStyle.wdLineStyleSingle;
                                newTable.Columns[1].Width         = 110f; //列明
                                newTable.Columns[2].Width         = 90f;  //数据类型
                                newTable.Columns[3].Width         = 50f;  //是否NULL
                                newTable.Columns[4].Width         = 40f;  //默认值
                                newTable.Columns[5].Width         = 30f;  //主键
                                newTable.Columns[6].Width         = 30f;  //外键
                                newTable.Columns[7].Width         = 130f; //列说明

                                #endregion

                                #region 填充表名称(表格内)

                                newTable.Cell(1, 1).Range.Text = "表名:" + tableName + "(" + tableComments + ")";
                                newTable.Cell(1, 1).Range.Bold = 2; //设置单元格中字体为粗体
                                //合并单元格
                                newTable.Cell(1, 1).Merge(newTable.Cell(1, 7));
                                newTable.Cell(1, 1).Range.Font.Color = Word.WdColor.wdColorRed; //设置单元格内字体颜色
                                newTable.Cell(1, 1).Select();                                   //选中
                                dbWordApp.Selection.Cells.VerticalAlignment =
                                    Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;     //垂直居中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter;           //水平居中

                                #endregion

                                #region 填充列标题

                                newTable.Cell(2, 1).Range.Text       = "列名";
                                newTable.Cell(2, 1).Range.Font.Color = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 2).Range.Font.Bold  = 2;
                                newTable.Cell(2, 2).Range.Font.Size  = 9;
                                newTable.Cell(2, 2).Select(); //选中
                                newTable.Cell(2, 2).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 2).Range.Text       = "数据类型";
                                newTable.Cell(2, 2).Range.Font.Color = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 2).Range.Font.Bold  = 2;
                                newTable.Cell(2, 2).Range.Font.Size  = 9;
                                newTable.Cell(2, 2).Select(); //选中
                                newTable.Cell(2, 2).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 3).Range.Text        = "是否NULL";
                                newTable.Cell(2, 3).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 3).Range.Font.Bold   = 2;
                                newTable.Cell(2, 3).Range.Font.Size   = 9;
                                newTable.Cell(2, 3).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 3).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 4).Range.Text        = "默认值";
                                newTable.Cell(2, 4).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 4).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 4).Range.Font.Bold = 2;
                                newTable.Cell(2, 4).Range.Font.Size = 9;
                                newTable.Cell(2, 4).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 5).Range.Text        = "主键";
                                newTable.Cell(2, 5).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 5).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 5).Range.Font.Bold = 2;
                                newTable.Cell(2, 5).Range.Font.Size = 9;
                                newTable.Cell(2, 5).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 6).Range.Text        = "外键";
                                newTable.Cell(2, 6).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 6).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 6).Range.Font.Bold = 2;
                                newTable.Cell(2, 6).Range.Font.Size = 9;
                                newTable.Cell(2, 6).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                newTable.Cell(2, 7).Range.Text        = "备注";
                                newTable.Cell(2, 7).Range.Font.Color  = Word.WdColor.wdColorBlack; //设置单元格内字体颜色
                                newTable.Cell(2, 7).VerticalAlignment =
                                    WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                newTable.Cell(2, 7).Range.Font.Bold = 2;
                                newTable.Cell(2, 7).Range.Font.Size = 9;
                                newTable.Cell(2, 7).Select();                         //选中
                                dbWordApp.Selection.ParagraphFormat.Alignment =
                                    Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                #endregion

                                #region 填充表格内容

                                for (int i = 0; i < drTableColumns.Length; i++)
                                {
                                    string tableColumnName = drTableColumns[i]["COLUMN_NAME"] as string;         //列名

                                    string tableColumnComments = drTableColumns[i]["COMMENTS"] as string;        //列说明

                                    string tableColumnDataType = drTableColumns[i]["DATA_TYPE"] as string;       //列类型

                                    string tableColumnDataScale = drTableColumns[i]["DATA_SCALE"] + "";          //列精度

                                    string tableColumnDataLength = drTableColumns[i]["DATA_LENGTH"] + "";        //列长度

                                    string tableColumnDataNullAble = drTableColumns[i]["NULLABLE"] as string;    //可空

                                    string tableColumnDataDefault = drTableColumns[i]["DATA_DEFAULT"] as string; //默认值

                                    string tableColumnDataPrecision = drTableColumns[i]["Data_Precision"] + "";

                                    if (string.IsNullOrEmpty(tableColumnDataPrecision)) //字符串、日期等
                                    {
                                        if ("DATE".Equals(tableColumnDataType))
                                        {
                                            tableColumnDataType = tableColumnDataType + "()";
                                        }
                                        else
                                        {
                                            tableColumnDataType = tableColumnDataType + "(" + tableColumnDataLength +
                                                                  ")";
                                        }
                                    }
                                    else //数字类型等
                                    {
                                        if ("0".Equals(tableColumnDataScale))
                                        {
                                            tableColumnDataType = tableColumnDataType + "(" + tableColumnDataPrecision +
                                                                  ")";
                                        }
                                        else
                                        {
                                            tableColumnDataType = tableColumnDataType + "(" + tableColumnDataPrecision +
                                                                  "," + tableColumnDataScale + ")";
                                        }
                                    }

                                    //列名
                                    newTable.Cell(i + 3, 1).Range.Text        = tableColumnName;
                                    newTable.Cell(i + 3, 1).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;

                                    //数据类型
                                    newTable.Cell(i + 3, 2).Range.Text        = tableColumnDataType;
                                    newTable.Cell(i + 3, 2).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;


                                    //是否Null
                                    newTable.Cell(i + 3, 3).Range.Text        = tableColumnDataNullAble;
                                    newTable.Cell(i + 3, 3).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 3).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                    //默认值
                                    newTable.Cell(i + 3, 4).Range.Text        = tableColumnDataDefault;
                                    newTable.Cell(i + 3, 4).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 4).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中


                                    //主键

                                    newTable.Cell(i + 3, 5).Range.Text = "";

                                    DataRow[] dr =
                                        dsTablePrimaryKeys.Tables[dbName + DBtablesPrimaryKeys].Select(
                                            "TABLE_NAME = '" + tableName + "' AND COLUMN_NAME ='" + tableColumnName +
                                            "' and constraint_type='P'");

                                    if (dr != null && dr.Length > 0)
                                    {
                                        newTable.Cell(i + 3, 5).Range.Text = "Y";
                                    }
                                    newTable.Cell(i + 3, 5).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 5).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中

                                    //外键

                                    newTable.Cell(i + 3, 6).Range.Text = "";
                                    DataRow[] dr2 =
                                        dsTablePrimaryKeys.Tables[dbName + DBtablesPrimaryKeys].Select(
                                            "TABLE_NAME = '" + tableName + "' AND COLUMN_NAME ='" + tableColumnName +
                                            "' and constraint_type='R'");
                                    if (dr2 != null && dr2.Length > 0)
                                    {
                                        newTable.Cell(i + 3, 6).Range.Text = "Y";
                                    }
                                    newTable.Cell(i + 3, 6).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                    newTable.Cell(i + 3, 6).Select();
                                    dbWordApp.Selection.ParagraphFormat.Alignment =
                                        Word.WdParagraphAlignment.wdAlignParagraphCenter; //水平居中


                                    //说明
                                    newTable.Cell(i + 3, 7).Range.Text        = tableColumnComments;
                                    newTable.Cell(i + 3, 7).VerticalAlignment =
                                        WdCellVerticalAlignment.wdCellAlignVerticalCenter;
                                }

                                #endregion


                                setProgress(1);
                            }
                            catch (Exception ex)
                            {
                                msg = ex.Message;
                                string str = (string.Format("{0}生成数据库文档丢失{1}表", dbName, tableName));
                                setStatusBar(str);
                                LogHelper.Error(ex);
                                LogHelper.Debug(str);
                            }
                            finally
                            {
                                #region 释放资源

                                if ((j + 1) % num == 0 || (j + 1).Equals(drTables.Length))
                                {
                                    try
                                    {
                                        object fileName = string.Format(path, begin + 1, end + 1);

                                        dbDoc.SaveAs(ref fileName, 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);
                                    }
                                    catch (Exception ex)
                                    {
                                        msg = ex.Message;
                                        LogHelper.Error(ex);
                                    }
                                    try
                                    {
                                        dbDoc.Close(ref Nothing, ref Nothing, ref Nothing);
                                    }
                                    catch
                                    {
                                    }
                                    if (dbDoc != null)
                                    {
                                        try
                                        {
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(dbDoc);
                                        }
                                        catch
                                        {
                                        }
                                        dbDoc = null;
                                    }
                                    GC.Collect();
                                    if (!(j + 1).Equals(drTables.Length))
                                    {
                                        dbDoc = dbWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing,
                                                                        ref Nothing);
                                    }
                                }

                                #endregion
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        msg = ex.Message;
                        LogHelper.Error(ex);
                    }
                    finally
                    {
                        #region 释放资源

                        try
                        {
                            dbWordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
                        }
                        catch
                        {
                        }
                        if (dbWordApp != null)
                        {
                            try
                            {
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(dbWordApp);
                            }
                            catch
                            {
                            }
                            dbWordApp = null;
                        }
                        GC.Collect();


                        #endregion
                    }

                    #endregion
                }
                sw.Stop();

                if (string.IsNullOrEmpty(msg))
                {
                    setStatusBar(string.Format("{0}数据库文档生成成功", dbName));
                    openDialog();
                }
                else
                {
                    setStatusBar(string.Format("{0}数据库文档生成失败[{1}]", dbName, msg));
                }
                setEnable(true);
            }
            catch (Exception ex)
            {
                setStatusBar(string.Format("{0}数据库文档生成失败[{1}]", dbName, ex.Message));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 导出审批表word
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="Type">0-首营供货商,1-首营客户,2-首营药品</param>
        /// <returns></returns>
        public bool CreateWord(string Filename, string Name, int Type)
        {
            Word._Application oWord = new Word.Application();
            Word._Document    oDoc  = null;
            try
            {
                object oMissing = System.Reflection.Missing.Value;

                oWord.Visible = false;
                object oTemplate = Filename;
                oDoc = oWord.Documents.Open(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                oDoc.Activate();

                #region 这是首营信息们
                if (b != null)
                {
                    this.insertMarks(oDoc, 0);
                    this.insertGsp(oDoc, b.GSPLCID, b.id);
                    this.insertMedicineBussiness(oDoc, b.MedicineBusinessLCID);
                    this.insertBussiness(oDoc, b.BusinessLCID);
                    this.insertOrg(oDoc, b.OrganizationCodeLCID);
                    this.insertTax(oDoc, b.TaxRegisterLCID);
                    this.insertInstB(oDoc, b.InstrumentsBusinessLCID);
                    this.insertInstP(oDoc, b.InstrumentsProductionLCID);
                    this.insertHealth(oDoc, b.HealthLCID);
                    this.InsertGMP(oDoc, b.GMPLCID);
                    this.insertDelegate(oDoc);
                    this.insertSCXKZ(oDoc, b.MedicineProductionLCID);
                    this.insertQualityAgreement(oDoc);
                    this.insertBank(oDoc);

                    Service.Models.QueryApprovalFlowRecordModel aq = new  Service.Models.QueryApprovalFlowRecordModel
                    {
                        FlowId = b.ApprovalFlowId
                    };

                    var c = baseform.PharmacyDatabaseService.SearchApprovalFlowRecordsByQueryModel(out msg, aq).OrderBy(r => r.ApproveTime).ToList();

                    if (oDoc.Bookmarks["flow1"] != null)
                    {
                        for (int i = 0; i < c.Count; i++)
                        {
                            oDoc.Bookmarks["flow" + (i + 1)].Select();
                            oDoc.Bookmarks["flow" + (i + 1)].Range.Text = c[i].Comment;
                            var o = ListUsers.Where(r => r.Id == c[i].ApproveUserId).FirstOrDefault();
                            oDoc.Bookmarks["flowuser" + (i + 1)].Range.Text = o.Employee.Name + "  " + c[i].ApproveTime.ToLongDateString();
                        }
                    }
                }

                if (p != null)
                {
                    this.insertPurchaseBasicInfo(oDoc);
                    this.insertGsp(oDoc, p.GSPLCID, p.Id);
                    this.insertMedicineBussiness(oDoc, p.MedicineBusinessLCID);
                    this.insertBussiness(oDoc, p.BusinessLCID);
                    this.insertOrg(oDoc, p.OrganizationCodeLCID);
                    this.insertTax(oDoc, p.TaxRegisterLCID);
                    this.insertInstB(oDoc, p.InstrumentsBusinessLCID);
                    this.insertInstP(oDoc, p.InstrumentsProductionLCID);
                    this.insertHealth(oDoc, p.HealthLCID);
                    this.InsertGMP(oDoc, p.GMPLCID);
                    this.insertLn(oDoc, p.LnstitutionLegalPersonLCID);
                    this.InsertMMInst(oDoc, p.MmedicalInstitutionLCID);
                    this.insertDelegate(oDoc);
                    this.insertQualityAgreement(oDoc);
                }

                if (d != null)
                {
                    this.InsertDrugInfo(oDoc);
                }

                #region 医疗器械信息
                if (Inst != null)
                {
                    oDoc.Bookmarks["T1"].Select();
                    oDoc.Bookmarks["T1"].Range.Text = BugsBox.Pharmacy.AppClient.Common.PharmacyClientConfig.Config.Store.Name;

                    oDoc.Bookmarks["D1"].Range.Text  = Inst.ProductGeneralName;
                    oDoc.Bookmarks["D2"].Range.Text  = Inst.LicensePermissionNumber;
                    oDoc.Bookmarks["D3"].Range.Text  = Inst.PerformanceStandards;
                    oDoc.Bookmarks["D4"].Range.Text  = Inst.StandardCode;
                    oDoc.Bookmarks["D5"].Range.Text  = Inst.Code;
                    oDoc.Bookmarks["D6"].Range.Text  = Inst.DocCode;
                    oDoc.Bookmarks["D7"].Range.Text  = Inst.Pinyin;
                    oDoc.Bookmarks["D8"].Range.Text  = Inst.BarCode;
                    oDoc.Bookmarks["D11"].Range.Text = Inst.DictionaryMeasurementUnitCode;
                    oDoc.Bookmarks["D12"].Range.Text = Inst.DictionaryDosageCode;
                    oDoc.Bookmarks["D13"].Range.Text = Inst.DictionarySpecificationCode;
                    oDoc.Bookmarks["D14"].Range.Text = Inst.FactoryName;
                    oDoc.Bookmarks["D15"].Range.Text = Inst.Contact;
                    oDoc.Bookmarks["D16"].Range.Text = Inst.BusinessScopeCode;
                    oDoc.Bookmarks["D17"].Range.Text = Inst.IsApproval;
                    oDoc.Bookmarks["D18"].Range.Text = Inst.Valid;
                    oDoc.Bookmarks["D19"].Range.Text = Inst.WareHouses;
                    oDoc.Bookmarks["D20"].Range.Text = Inst.WareHouseZone;
                    oDoc.Bookmarks["D21"].Range.Text = Inst.DrugStorageTypeCode;
                    oDoc.Bookmarks["D22"].Range.Text = Inst.MaxInventoryCount.ToString();
                    oDoc.Bookmarks["D23"].Range.Text = Inst.MinInventoryCount.ToString();
                    oDoc.Bookmarks["D24"].Range.Text = Inst.ValidPeriod.ToString() + "个月";
                    oDoc.Bookmarks["D25"].Range.Text = Inst.DrugCategoryCode;
                    oDoc.Bookmarks["D26"].Range.Text = Inst.Price.ToString();
                    oDoc.Bookmarks["D27"].Range.Text = Inst.SalePrice.ToString();
                    oDoc.Bookmarks["D28"].Range.Text = Inst.LimitedUpPrice.ToString();
                    oDoc.Bookmarks["D29"].Range.Text = Inst.LimitedLowPrice.ToString();
                    oDoc.Bookmarks["D31"].Range.Text = Inst.Description;
                    oDoc.Bookmarks["D48"].Range.Text = Inst.CreateTime.ToString();
                    oDoc.Bookmarks["D49"].Range.Text = Inst.CreateUserName;
                }
                #endregion

                #region 保健食品信息
                if (this.Food != null)
                {
                    oDoc.Bookmarks["T1"].Select();
                    oDoc.Bookmarks["T1"].Range.Text = BugsBox.Pharmacy.AppClient.Common.PharmacyClientConfig.Config.Store.Name;

                    oDoc.Bookmarks["D1"].Range.Text  = Food.ProductGeneralName;
                    oDoc.Bookmarks["D2"].Range.Text  = Food.LicensePermissionNumber;
                    oDoc.Bookmarks["D3"].Range.Text  = Food.PerformanceStandards;
                    oDoc.Bookmarks["D4"].Range.Text  = Food.LicensePermissionOutValidDate.ToShortDateString();
                    oDoc.Bookmarks["D5"].Range.Text  = Food.Code;
                    oDoc.Bookmarks["D6"].Range.Text  = Food.DocCode;
                    oDoc.Bookmarks["D7"].Range.Text  = Food.Pinyin;
                    oDoc.Bookmarks["D8"].Range.Text  = Food.BarCode;
                    oDoc.Bookmarks["D11"].Range.Text = Food.DictionaryMeasurementUnitCode;
                    oDoc.Bookmarks["D12"].Range.Text = Food.DictionaryDosageCode;
                    oDoc.Bookmarks["D13"].Range.Text = Food.DictionarySpecificationCode;
                    oDoc.Bookmarks["D14"].Range.Text = Food.FactoryName;
                    oDoc.Bookmarks["D15"].Range.Text = Food.Contact;
                    oDoc.Bookmarks["D16"].Range.Text = Food.BusinessScopeCode;
                    oDoc.Bookmarks["D17"].Range.Text = Food.IsApproval;
                    oDoc.Bookmarks["D18"].Range.Text = Food.Valid;
                    oDoc.Bookmarks["D19"].Range.Text = Food.WareHouses;
                    oDoc.Bookmarks["D20"].Range.Text = Food.WareHouseZone;
                    oDoc.Bookmarks["D21"].Range.Text = Food.DrugStorageTypeCode;
                    oDoc.Bookmarks["D22"].Range.Text = Food.MaxInventoryCount.ToString();
                    oDoc.Bookmarks["D23"].Range.Text = Food.MinInventoryCount.ToString();
                    oDoc.Bookmarks["D24"].Range.Text = Food.ValidPeriod.ToString() + "个月";
                    oDoc.Bookmarks["D25"].Range.Text = Food.IsImport;



                    oDoc.Bookmarks["D26"].Range.Text = Food.Price.ToString();
                    oDoc.Bookmarks["D27"].Range.Text = Food.SalePrice.ToString();
                    oDoc.Bookmarks["D28"].Range.Text = Food.LimitedUpPrice.ToString();
                    oDoc.Bookmarks["D29"].Range.Text = Food.LimitedLowPrice.ToString();

                    oDoc.Bookmarks["D30"].Range.Text = Food.Origin;
                    oDoc.Bookmarks["D31"].Range.Text = Food.Description;

                    oDoc.Bookmarks["D48"].Range.Text = Food.CreateTime.ToString();
                    oDoc.Bookmarks["D49"].Range.Text = Food.CreateUserName;
                }

                #endregion

                #endregion

                #region word保存
                System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
                sfd.Filter     = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                sfd.FileName   = Name + DateTime.Now.Ticks + ".doc";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    object filename = sfd.FileName;
                    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);
                    if (oDoc != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                        oDoc = null;
                    }
                    if (oWord != null)
                    {
                        oWord.Quit();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                        oWord = null;
                    }
                    return(true);
                }
                else
                {
                    if (oDoc != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                        oDoc = null;
                    }
                    if (oWord != null)
                    {
                        oWord.Quit(Word.WdSaveOptions.wdDoNotSaveChanges);
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                        oWord = null;
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(Name + ":审批信息表导出失败!");
                if (oWord != null)
                {
                    oWord.Quit(Word.WdSaveOptions.wdDoNotSaveChanges);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                    oWord = null;
                }
                if (oDoc != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                    oDoc = null;
                }
                return(false);
            }
            finally
            {
                if (oWord != null)
                {
                    oWord.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
                    oWord = null;
                }
                if (oDoc != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc);
                    oDoc = null;
                }
            }
            #endregion
        }
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (testStandardEnum == TestStandardEnum.default1711 && comboBox1.Text != "EN1111-2017温控报告")
                {
                    MessageBox.Show("请选择正确的模板!");
                    this.Close();
                }
                if (testStandardEnum == TestStandardEnum.default2806 && comboBox1.Text != "2806温控报告")
                {
                    MessageBox.Show("请选择正确的模板!");
                    this.Close();
                }
                object oMissing = System.Reflection.Missing.Value;
                //创建一个word实例
                Word._Application oWord = new Word.Application();
                //设置为不可见
                oWord.Visible = false;
                //模板文件地址,这里假设在程序根目录
                object oTemplate = System.AppDomain.CurrentDomain.BaseDirectory + "//" + comboBox1.Text + ".dot";
                //以模板为基础生成文档
                Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

                #region 2806
                if (testStandardEnum == TestStandardEnum.default2806)
                {
                    //声明书签数组
                    object[] oBookMark = new object[46];
                    //赋值书签名
                    oBookMark[0]  = "Pc";
                    oBookMark[1]  = "Tc";
                    oBookMark[2]  = "Ph";
                    oBookMark[3]  = "Th";
                    oBookMark[4]  = "Qm";
                    oBookMark[5]  = "Tm";
                    oBookMark[6]  = "A_1_Qc";
                    oBookMark[7]  = "A_1_Tc";
                    oBookMark[8]  = "A_1_Tcdiff";
                    oBookMark[9]  = "A_2_Qc";
                    oBookMark[10] = "A_2_Tc";
                    oBookMark[11] = "A_2_Tcdiff";
                    oBookMark[12] = "B_1_Qh";
                    oBookMark[13] = "B_1_Th";
                    oBookMark[14] = "B_2_Qh";
                    oBookMark[15] = "B_2_Th";
                    oBookMark[16] = "B_2_Thdiff";

                    oBookMark[17] = "C_1_Tm";
                    oBookMark[18] = "C_1_3";
                    oBookMark[19] = "C_1_5";
                    oBookMark[20] = "C_1_Tmdiff";
                    oBookMark[21] = "C_2_Tm";
                    oBookMark[22] = "C_2_Tmdiff";
                    oBookMark[23] = "C_3_Tm";
                    oBookMark[24] = "C_3_3";
                    oBookMark[25] = "C_3_5";
                    oBookMark[26] = "C_3_Tmdiff";
                    oBookMark[27] = "C_4_Tm";
                    oBookMark[28] = "C_4_Tmdiff";

                    oBookMark[29] = "H_1_Tm";
                    oBookMark[30] = "H_1_3";
                    oBookMark[31] = "H_1_5";
                    oBookMark[32] = "H_1_Tmdiff";
                    oBookMark[33] = "H_2_Tm";
                    oBookMark[34] = "H_2_Tmdiff";
                    oBookMark[35] = "H_3_Tm";
                    oBookMark[36] = "H_3_3";
                    oBookMark[37] = "H_3_5";
                    oBookMark[38] = "H_3_Tmdiff";
                    oBookMark[39] = "H_4_Tm";
                    oBookMark[40] = "H_4_Tmdiff";

                    oBookMark[41] = "Up_Tm";
                    oBookMark[42] = "Up_Tmdiff";
                    oBookMark[43] = "Back_Tm";
                    oBookMark[44] = "Back_Tmdiff";
                    oBookMark[45] = "TmMax";

                    //赋值任意数据到书签的位置
                    oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model_2806.Pc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model_2806.Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model_2806.Ph + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model_2806.Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model_2806.Qm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model_2806.Tm + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text  = model_2806.A_1_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text  = model_2806.A_1_Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text  = model_2806.A_1_Tcdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text  = model_2806.A_2_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model_2806.A_2_Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = model_2806.A_2_Tcdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = model_2806.B_1_Qh + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = model_2806.B_1_Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = model_2806.B_2_Qh + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = model_2806.B_2_Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = model_2806.B_2_Thdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = model_2806.C_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = model_2806.C_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = model_2806.C_1_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = model_2806.C_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = model_2806.C_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = model_2806.C_2_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = model_2806.C_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = model_2806.C_3_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = model_2806.C_3_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = model_2806.C_3_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = model_2806.C_4_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = model_2806.C_4_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = model_2806.H_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = model_2806.H_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = model_2806.H_1_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = model_2806.H_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = model_2806.H_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = model_2806.H_2_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model_2806.H_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model_2806.H_3_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model_2806.H_3_5 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model_2806.H_3_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model_2806.H_4_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model_2806.H_4_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model_2806.Up_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[42]).Range.Text = model_2806.Up_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[43]).Range.Text = model_2806.Back_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[44]).Range.Text = model_2806.Back_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[45]).Range.Text = model_2806.TmMax + "";
                }
                #endregion

                #region 1111
                if (testStandardEnum == TestStandardEnum.default1711)
                {
                    //声明书签数组
                    object[] oBookMark = new object[42];
                    //赋值书签名
                    oBookMark[0] = "Pc";
                    oBookMark[1] = "Tc";
                    oBookMark[2] = "Ph";
                    oBookMark[3] = "Th";
                    oBookMark[4] = "Qm";
                    oBookMark[5] = "Tm";

                    oBookMark[6]  = "A_1_Qc";
                    oBookMark[7]  = "A_1_Tc";
                    oBookMark[8]  = "A_1_Tcdiff";
                    oBookMark[9]  = "A_2_Qc";
                    oBookMark[10] = "A_3_Tm";
                    oBookMark[11] = "A_3_Tmdiff";

                    oBookMark[12] = "H_1_Tm";
                    oBookMark[13] = "H_1_3";
                    oBookMark[14] = "H_1_Tmdiff";
                    oBookMark[15] = "H_2_Tm";
                    oBookMark[16] = "H_2_Tmdiff";

                    oBookMark[17] = "C_1_Tm";
                    oBookMark[18] = "C_1_3";
                    oBookMark[19] = "C_1_Tmdiff";
                    oBookMark[20] = "C_2_Tm";
                    oBookMark[21] = "C_2_Tmdiff";

                    oBookMark[22] = "Cool_1_Tm";
                    oBookMark[23] = "Cool_1_3";
                    oBookMark[24] = "Cool_1_Tmdiff";
                    oBookMark[25] = "Cool_2_Tm";
                    oBookMark[26] = "Cool_2_Tmdiff";

                    oBookMark[27] = "Steady_1_Tm";
                    oBookMark[28] = "Steady_1_Tmdiff";
                    oBookMark[29] = "Steady_2_Tm";
                    oBookMark[30] = "Steady_2_Tmdiff";
                    oBookMark[31] = "Steady_2_3";

                    oBookMark[32] = "Steady_3_Tm";
                    oBookMark[33] = "Steady_3_Tmdiff";
                    oBookMark[34] = "Steady_4_Tm";
                    oBookMark[35] = "Steady_4_Tmdiff";
                    oBookMark[36] = "Steady_4_3";

                    oBookMark[37] = "FLow_1_Qm";
                    oBookMark[38] = "FLow_1_Tm";
                    oBookMark[39] = "FLow_1_Tmdiff";
                    oBookMark[40] = "FLow_2_Tm";
                    oBookMark[41] = "FLow_2_Tmdiff";

                    //赋值任意数据到书签的位置
                    oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model_1111.Pc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model_1111.Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model_1111.Ph + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model_1111.Th + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model_1111.Qm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model_1111.Tm + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text  = model_1111.A_1_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text  = model_1111.A_1_Tc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text  = model_1111.A_1_Tcdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text  = model_1111.A_2_Qc + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model_1111.A_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = model_1111.A_3_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = model_1111.H_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = model_1111.H_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = model_1111.H_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = model_1111.H_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = model_1111.H_2_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = model_1111.C_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = model_1111.C_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = model_1111.C_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = model_1111.C_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = model_1111.C_2_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = model_1111.Cool_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = model_1111.Cool_1_3 + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = model_1111.Cool_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = model_1111.Cool_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = model_1111.Cool_2_Tmdiff + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = model_1111.Steady_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = model_1111.Steady_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = model_1111.Steady_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = model_1111.Steady_2_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = model_1111.Steady_2_3 + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = model_1111.Steady_3_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = model_1111.Steady_3_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = model_1111.Steady_4_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model_1111.Steady_4_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model_1111.Steady_4_3 + "";

                    oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model_1111.FLow_1_Qm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model_1111.FLow_1_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model_1111.FLow_1_Tmdiff + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model_1111.FLow_2_Tm + "";
                    oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model_1111.FLow_2_Tmdiff + "";
                }
                #endregion

                //弹出保存文件对话框,保存生成的Word
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter     = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    object filename = sfd.FileName;

                    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);
                    MessageBox.Show("保存成功!");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Convert Word Document
        /// </summary>
        /// <param name="strPath"></param>
        /// <param name="savePath"></param>
        /// <returns></returns>
        private bool ConvertWordDocument(string strPath,string savePath)
        {
            try
            {
                Word.Application wordApp = new Word.Application();
                object rdOnly=true;//Boolean.TrueString;
                object Source=strPath;
                object Destination= savePath;

                try
                {

                    wordApp.Documents.Open(ref Source,ref Unknown,
                        ref rdOnly,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,ref Unknown);//,ref Unknown);
                }
                catch(Exception ee)
                {
                    Console.Write("Unable to convert Word Document " + ee.Message);
                    return false;
                }

                try
                {

                    object format = Word.WdSaveFormat.wdFormatHTML;//.wdFormatRTF;// kein XML, nutzen?
                    wordApp.ActiveDocument.SaveAs(ref Destination,ref format,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown,ref Unknown,ref Unknown,
                        ref Unknown, ref Unknown);

                }
                catch(Exception ee)
                {
                    string errorText = "Unable to save specified Document. Access is denied. "+ ee.Message;
                    Console.Write("Unable to convert Word Document " + errorText);
                    return false;

                }
                object fileSave=false;

                wordApp.Quit(ref fileSave, ref Unknown, ref Unknown);

                wordApp = null; //GC
                GC.Collect(); //GC
                return true;
            }
            catch(Exception ee)
            {

            }
            return false;
        }
Ejemplo n.º 10
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                object oMissing = System.Reflection.Missing.Value;
                //创建一个word实例
                Word._Application oWord = new Word.Application();
                //设置为不可见
                oWord.Visible = false;

                //模板文件地址,这里假设在程序根目录
                object oTemplate          = System.AppDomain.CurrentDomain.BaseDirectory + "//" + comboBox1.Text + ".dot";
                string pic65Path          = System.AppDomain.CurrentDomain.BaseDirectory + "//出水温度稳定性65℃.jpg";
                string pic50Path          = System.AppDomain.CurrentDomain.BaseDirectory + "//出水温度稳定性50℃.jpg";
                string picSenstivityPath1 = System.AppDomain.CurrentDomain.BaseDirectory + "//保真度曲线.jpg";
                string picSenstivityPath2 = System.AppDomain.CurrentDomain.BaseDirectory + "//灵敏度曲线.jpg";
                //以模板为基础生成文档
                Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                oWord = oDoc.Application;
                if (isTest)
                {
                    foreach (Bookmark bk in oDoc.Bookmarks)
                    {
                        if (bk.Name == "Tm_65_3")
                        {
                            bk.Range.Text = model.Tm_65_3 + "";
                        }
                        if (bk.Name == "Tm_65_3diff")
                        {
                            bk.Range.Text = model.Tm_65_3diff + "";
                        }
                        if (bk.Name == "Tm_65_6")
                        {
                            bk.Range.Text = model.Tm_65_6 + "";
                        }
                        if (bk.Name == "Tm_65_6diff")
                        {
                            bk.Range.Text = model.Tm_65_6diff + "";
                        }
                        if (bk.Name == "Tm_50_3")
                        {
                            bk.Range.Text = model.Tm_50_3 + "";
                        }
                        if (bk.Name == "Tm_50_3diff")
                        {
                            bk.Range.Text = model.Tm_50_3diff + "";
                        }
                        if (bk.Name == "Tm_50_6")
                        {
                            bk.Range.Text = model.Tm_50_6 + "";
                        }
                        if (bk.Name == "Tm_50_6diff")
                        {
                            bk.Range.Text = model.Tm_50_6diff + "";
                        }
                        if (bk.Name == "tmDiff")
                        {
                            bk.Range.Text = model.Tm_50_3 + "";
                        }
                        if (bk.Name == "G1")
                        {
                            bk.Range.Text = model.Tm_50_3diff + "";
                        }
                        if (bk.Name == "G2")
                        {
                            bk.Range.Text = model.Tm_50_6 + "";
                        }

                        if (bk.Name == "Tm_65_pic" && File.Exists(pic65Path))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(pic65Path);
                        }
                        if (bk.Name == "Tm_50_pic" && File.Exists(pic50Path))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(pic50Path);
                        }
                        if (bk.Name == "picSenstivity1" && File.Exists(picSenstivityPath1))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(picSenstivityPath1);
                        }
                        if (bk.Name == "picSenstivity2" && File.Exists(picSenstivityPath2))
                        {
                            bk.Select();
                            Selection sel = oWord.Selection;
                            sel.InlineShapes.AddPicture(picSenstivityPath2);
                        }
                    }
                    //object[] oBookMark = new object[10];
                    //oBookMark[0] = "Tm_65_3";
                    //oBookMark[1] = "Tm_65_3diff";
                    //oBookMark[2] = "Tm_65_6";
                    //oBookMark[3] = "Tm_65_6diff";
                    //oBookMark[4] = "Tm_65_pic";
                    //oBookMark[5] = "Tm_50_3";
                    //oBookMark[6] = "Tm_50_3diff";
                    //oBookMark[7] = "Tm_50_6";
                    //oBookMark[8] = "Tm_50_6diff";
                    //oBookMark[9] = "Tm_50_pic";

                    ////赋值任意数据到书签的位置
                    //oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model.Tm_65_3 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model.Tm_65_3diff + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model.Tm_65_6 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model.Tm_65_6diff + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model.Tm_50_3 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = model.Tm_50_3diff + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = model.Tm_50_6 + "";
                    //oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = model.Tm_50_6diff + "";

                    //Bookmark bk_65_pic= oDoc.Bookmarks.get_Item(ref oBookMark[4]);
                    //bk_65_pic.Select();
                    //Selection sel = oWord.Selection;
                    //sel.InlineShapes.AddPicture(pic65Path);


                    //Bookmark bk_50_pic = oDoc.Bookmarks.get_Item(ref oBookMark[9]);
                    //bk_50_pic.Select();
                    //sel.InlineShapes.AddPicture(pic50Path);
                }


                //#region 2806
                //if (testStandardEnum == TestStandardEnum.default2806)
                //{
                //    //声明书签数组
                //    object[] oBookMark = new object[46];
                //    //赋值书签名
                //    oBookMark[0] = "Pc";
                //    oBookMark[1] = "Tc";
                //    oBookMark[2] = "Ph";
                //    oBookMark[3] = "Th";
                //    oBookMark[4] = "Qm";
                //    oBookMark[5] = "Tm";
                //    oBookMark[6] = "A_1_Qc";
                //    oBookMark[7] = "A_1_Tc";
                //    oBookMark[8] = "A_1_Tcdiff";
                //    oBookMark[9] = "A_2_Qc";
                //    oBookMark[10] = "A_2_Tc";
                //    oBookMark[11] = "A_2_Tcdiff";
                //    oBookMark[12] = "B_1_Qh";
                //    oBookMark[13] = "B_1_Th";
                //    oBookMark[14] = "B_2_Qh";
                //    oBookMark[15] = "B_2_Th";
                //    oBookMark[16] = "B_2_Thdiff";

                //    oBookMark[17] = "C_1_Tm";
                //    oBookMark[18] = "C_1_3";
                //    oBookMark[19] = "C_1_5";
                //    oBookMark[20] = "C_1_Tmdiff";
                //    oBookMark[21] = "C_2_Tm";
                //    oBookMark[22] = "C_2_Tmdiff";
                //    oBookMark[23] = "C_3_Tm";
                //    oBookMark[24] = "C_3_3";
                //    oBookMark[25] = "C_3_5";
                //    oBookMark[26] = "C_3_Tmdiff";
                //    oBookMark[27] = "C_4_Tm";
                //    oBookMark[28] = "C_4_Tmdiff";

                //    oBookMark[29] = "H_1_Tm";
                //    oBookMark[30] = "H_1_3";
                //    oBookMark[31] = "H_1_5";
                //    oBookMark[32] = "H_1_Tmdiff";
                //    oBookMark[33] = "H_2_Tm";
                //    oBookMark[34] = "H_2_Tmdiff";
                //    oBookMark[35] = "H_3_Tm";
                //    oBookMark[36] = "H_3_3";
                //    oBookMark[37] = "H_3_5";
                //    oBookMark[38] = "H_3_Tmdiff";
                //    oBookMark[39] = "H_4_Tm";
                //    oBookMark[40] = "H_4_Tmdiff";

                //    oBookMark[41] = "Up_Tm";
                //    oBookMark[42] = "Up_Tmdiff";
                //    oBookMark[43] = "Back_Tm";
                //    oBookMark[44] = "Back_Tmdiff";
                //    oBookMark[45] = "TmMax";

                //    //赋值任意数据到书签的位置
                //    oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = model_2806.Pc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = model_2806.Tc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = model_2806.Ph + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = model_2806.Th + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = model_2806.Qm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = model_2806.Tm + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text = model_2806.A_1_Qc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text = model_2806.A_1_Tc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text = model_2806.A_1_Tcdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text = model_2806.A_2_Qc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = model_2806.A_2_Tc + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[11]).Range.Text = model_2806.A_2_Tcdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[12]).Range.Text = model_2806.B_1_Qh + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[13]).Range.Text = model_2806.B_1_Th + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[14]).Range.Text = model_2806.B_2_Qh + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[15]).Range.Text = model_2806.B_2_Th + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[16]).Range.Text = model_2806.B_2_Thdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[17]).Range.Text = model_2806.C_1_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[18]).Range.Text = model_2806.C_1_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[19]).Range.Text = model_2806.C_1_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[20]).Range.Text = model_2806.C_1_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[21]).Range.Text = model_2806.C_2_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[22]).Range.Text = model_2806.C_2_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[23]).Range.Text = model_2806.C_3_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[24]).Range.Text = model_2806.C_3_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[25]).Range.Text = model_2806.C_3_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[26]).Range.Text = model_2806.C_3_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[27]).Range.Text = model_2806.C_4_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[28]).Range.Text = model_2806.C_4_Tmdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[29]).Range.Text = model_2806.H_1_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[30]).Range.Text = model_2806.H_1_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[31]).Range.Text = model_2806.H_1_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[32]).Range.Text = model_2806.H_1_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[33]).Range.Text = model_2806.H_2_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[34]).Range.Text = model_2806.H_2_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[35]).Range.Text = model_2806.H_3_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[36]).Range.Text = model_2806.H_3_3 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[37]).Range.Text = model_2806.H_3_5 + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[38]).Range.Text = model_2806.H_3_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[39]).Range.Text = model_2806.H_4_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[40]).Range.Text = model_2806.H_4_Tmdiff + "";

                //    oDoc.Bookmarks.get_Item(ref oBookMark[41]).Range.Text = model_2806.Up_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[42]).Range.Text = model_2806.Up_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[43]).Range.Text = model_2806.Back_Tm + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[44]).Range.Text = model_2806.Back_Tmdiff + "";
                //    oDoc.Bookmarks.get_Item(ref oBookMark[45]).Range.Text = model_2806.TmMax + "";
                //}
                //#endregion



                //弹出保存文件对话框,保存生成的Word
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter     = "Word Document(*.doc)|*.doc";
                sfd.DefaultExt = "Word Document(*.doc)|*.doc";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    object filename = sfd.FileName;

                    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);
                    MessageBox.Show("保存成功!");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
                return;
            }
        }