Exemplo n.º 1
0
 /// <summary>
 /// 文件保存
 /// </summary>
 /// <param name="filename"></param>
 public void SaveToWord(object 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);
     oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
 }
Exemplo n.º 2
0
        ///<summary>
        /// 替换word模板文件内容,包括表格中内容
        /// </summary>
        /// <param name="filePath">文件全路径</param>
        /// <param name="arr_Old">占位符数组</param>
        /// <param name="arr_New">替换字符串数组</param>
        public Microsoft.Office.Interop.Word.Application WordStringsReplace(string filePath, ArrayList arr_Old, ArrayList arr_New)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            object oMissing = System.Reflection.Missing.Value;
            object file     = filePath;

            Microsoft.Office.Interop.Word._Document doc = app.Documents.Open(ref file,
                                                                             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);
            for (int i = 0; i < arr_Old.Count; i++)
            {
                app.Selection.Find.ClearFormatting();
                app.Selection.Find.Replacement.ClearFormatting();
                app.Selection.Find.Text             = arr_Old[i].ToString();
                app.Selection.Find.Replacement.Text = arr_New[i].ToString();
                object objReplace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;
                app.Selection.Find.Execute(ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing,
                                           ref oMissing, ref objReplace, ref oMissing,
                                           ref oMissing, ref oMissing, ref oMissing);
            }

            //保存
            doc.Save();
            doc.Close(ref oMissing, ref oMissing, ref oMissing);
            app.Quit(ref oMissing, ref oMissing, ref oMissing);
            return(app);
        }
Exemplo n.º 3
0
        public static bool ReadWordText(Microsoft.Office.Interop.Word._Application app, string filePath, out string docText)
        {
            docText = string.Empty;
            try
            {
                Microsoft.Office.Interop.Word._Document doc = null;//实例化一个新的word文档
                object unknow             = Type.Missing;
                object paramSourceDocPath = filePath;
                object ConfirmConversions = false;
                object readOnly           = true;
                object AddToRecentFiles   = false;
                object Visible            = false;
                object Revert             = false;
                object Format             = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatAuto;
                object OpenAndRepair      = false;
                object NoEncodingDialog   = true;
                doc = app.Documents.Open(ref paramSourceDocPath,
                                         ref ConfirmConversions, ref readOnly, ref AddToRecentFiles, ref unknow, ref unknow,
                                         ref Revert, ref unknow, ref unknow, ref Format, ref unknow,
                                         ref Visible, ref OpenAndRepair, ref NoEncodingDialog, ref unknow, ref unknow);

                if (doc != null)
                {
                    docText = doc.Content.Text + " ";//将全篇内容存入字符串中,最后补一个空格,表示文档能够打开
                    doc.Close(ref unknow, ref unknow, ref unknow);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(false);
        }
Exemplo n.º 4
0
        private void save()
        {
            this.Enabled = false;


            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\307\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;//word模板路径

            OrignFile = "\\baseDB\\商标书式\\5 补证撤三出具证明\\07 撤销成为商品服务通用名称注册商标申请书.dot";

            //开始写入数据

            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + "\\" + main.companyName + "\\wjgl\\307\\" + a0.Text + "\\" + a0.Text + ".docx";

            object[] MyBM = new object[12]; //创建一个书签数组

            for (int i = 0; i < 12; i++)    //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }



            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text  = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text  = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text  = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text  = a4.Text;
            doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text  = a5.Text;
            doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text  = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text  = a7.Text;
            doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text  = a8.Text;
            doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text  = a9.Text;
            doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text  = a10.Text;
            doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = a11.Text;
            doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = a12.Text;
            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }
Exemplo n.º 5
0
        private void WordReplace(string filePath, string strOld, string strNew)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
            object nullobj = System.Reflection.Missing.Value;
            object file    = filePath;

            Microsoft.Office.Interop.Word._Document doc = app.Documents.Open(
                ref file, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj) as Microsoft.Office.Interop.Word._Document;

            app.Selection.Find.ClearFormatting();
            app.Selection.Find.Replacement.ClearFormatting();
            app.Selection.Find.Text             = strOld;
            app.Selection.Find.Replacement.Text = strNew;

            object objReplace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;

            app.Selection.Find.Execute(ref nullobj, ref nullobj, ref nullobj,
                                       ref nullobj, ref nullobj, ref nullobj,
                                       ref nullobj, ref nullobj, ref nullobj,
                                       ref nullobj, ref objReplace, ref nullobj,
                                       ref nullobj, ref nullobj, ref nullobj);
            doc.Save();
            doc.Close(ref nullobj, ref nullobj, ref nullobj);

            app.Quit(ref nullobj, ref nullobj, ref nullobj);
        }
Exemplo n.º 6
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>
        private 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
            Microsoft.Office.Interop.Word._Application wordApplication = new Microsoft.Office.Interop.Word.Application();
            if (filesToMerge.Count() == 1)
            {
                pageBreak = false;
            }
            try
            {
                // Create a new file based on our template
                Microsoft.Office.Interop.Word._Document wordDocument = wordApplication.Documents.Add(ref defaultTemplate, ref missing, ref missing, ref missing);

                // Make a Word selection object.
                Microsoft.Office.Interop.Word.Selection selection = wordApplication.Selection;

                int index = 0;

                // 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 && index != filesToMerge.Count() - 1)
                    {
                        selection.InsertBreak(ref pageBreak);
                    }

                    index++;
                }

                // 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.Close(ref missing, ref missing, ref missing);
                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);
            }
        }
Exemplo n.º 7
0
        public static void PrintWordDot(string lv模板文件名, List <string> lv模板词汇, List <string> lv替换词汇)
        {
            object   path;       //文件路径
            string   strContent; //文件内容
            string   lvssss = Application.StartupPath + "\\Microsoft.Office.Interop.Word.dll";
            Assembly ass;
            string   lv模板文件名含路径 = Application.StartupPath + "\\" + lv模板文件名;
            Object   oMissing   = System.Reflection.Missing.Value;
            object   obj模板      = oMissing;
            object   obj;

            //获取并加载DLL类库中的程序集
            ass = Assembly.LoadFile(lvssss);

            obj = ass.CreateInstance("Microsoft.Office.Interop.Word.ApplicationClass");
            //获取类的类型:必须使用名称空间+类名称
            Microsoft.Office.Interop.Word._Application WordApp = obj as Microsoft.Office.Interop.Word._Application;
            WordApp.Visible = true;
            try
            {
                Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Add(ref obj模板, ref oMissing, ref oMissing, ref oMissing);
                object FindText, ReplaceWith, Replace;
                for (int lvi = 0; lvi < lv模板词汇.Count; lvi++)
                {
                    WordDoc.Content.Find.Text = lv模板词汇[lvi];
                    //要查找的文本
                    FindText = lv模板词汇[lvi];
                    //替换文本
                    //ReplaceWith = strNewText;
                    ReplaceWith = lv替换词汇[lvi];

                    //wdReplaceAll - 替换找到的所有项。
                    //wdReplaceNone - 不替换找到的任何项。
                    //wdReplaceOne - 替换找到的第一项。
                    Replace = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;


                    //移除Find的搜索文本和段落格式设置
                    WordDoc.Content.Find.ClearFormatting();
                    WordDoc.Content.Find.Execute(ref FindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref ReplaceWith, ref Replace, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                }
                WordDoc.PrintPreview();
                WordDoc.Saved = true;
                //关闭wordDoc文档
                WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                //关闭wordApp组件对象
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
            catch //(Exception ex)
            {
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                throw;
            }
        }
Exemplo n.º 8
0
        private void CloseDoc()
        {
            if (_doc != null)
            {
                _doc.Close();
                _doc = null;
            }

            if (_app != null)
            {
                _app.Quit();
                _app = null;
            }
        }
Exemplo n.º 9
0
        //Загрузка содержимого Word файла
        private void LoadDocx(string filename)
        {
            richTextBox.Document = new FlowDocument();
            Microsoft.Office.Interop.Word.Application wordObject = new Microsoft.Office.Interop.Word.Application();
            object File       = EXE_DIRECTORY + FOLDER + filename;
            object nullobject = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
            wordobject.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
            Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File);
            docs.ActiveWindow.Selection.WholeStory();
            docs.ActiveWindow.Selection.Copy();
            richTextBox.Paste();
            docs.Close();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 导出word功能
        /// </summary>
        /// <param name="sender">事件对象</param>
        /// <param name="e">事件参数</param>
        private void t_tsb_ExportWord_Click(object sender, RoutedEventArgs e)
        {
            object oMissing = System.Reflection.Missing.Value;

            //创建一个Word应用程序实例
            Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
            //设置为不可见
            oWord.Visible = false;
            //模板文件地址,这里假设在X盘根目录
            object oTemplate = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\Template\\Template.doc";

            //以模板为基础生成文档
            Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
            //声明书签数组
            object[] oBookMark = new object[4];
            //赋值书签名
            oBookMark[0] = "Company_Name";
            oBookMark[1] = "Tel";
            oBookMark[2] = "Email";
            oBookMark[3] = "Fax";
            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = PTBQuotation.Company_Name;
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = PTBQuotation.Tel;
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = PTBQuotation.Email;
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = PTBQuotation.Fax;
            //弹出保存文件对话框,保存生成的Word
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter     = "Word Document(*.doc)|*.doc";
            sfd.DefaultExt = "Word Document(*.doc)|*.doc";
            if (sfd.ShowDialog() == true)
            {
                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);

                System.Diagnostics.Process.Start(sfd.FileName);
            }
        }
Exemplo n.º 11
0
        /// PrinPreview the document
        /// </summary>
        /// <param name="fileToPrint"></param>
        private void PrinPriview(string fileToPrint)
        {
            object missing         = System.Type.Missing;
            object objFile         = fileToPrint;
            object readOnly        = true;
            object addToRecentOpen = false;

            // Create  a new Word application
            Microsoft.Office.Interop.Word._Application wordApplication = new Microsoft.Office.Interop.Word.Application();
            try
            {
                // Create a new file based on our template
                Microsoft.Office.Interop.Word._Document wordDocument = wordApplication.Documents.Open(ref objFile, ref missing, ref readOnly, ref addToRecentOpen);

                wordApplication.Options.SaveNormalPrompt = false;

                if (wordDocument != null)
                {
                    // Show print preview
                    wordApplication.Visible = true;
                    wordDocument.PrintPreview();
                    wordDocument.Activate();
                    //wordDocument.op
                    while (!_IsPringPriview)
                    {
                        wordDocument.ActiveWindow.View.Magnifier = true;
                        Thread.Sleep(500);
                    }

                    wordDocument.Close(ref missing, ref missing, ref missing);
                    wordDocument = null;
                }
            }
            catch
            {
                //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);
                wordApplication = null;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 预览Word
        /// </summary>
        public string PreviewWord(string physicalPath, string url, string scode)
        {
            Microsoft.Office.Interop.Word._Application application = null;
            Microsoft.Office.Interop.Word._Document    doc         = null;
            application = new Microsoft.Office.Interop.Word.Application();
            object missing    = Type.Missing;
            object trueObject = true;

            application.Visible       = false;
            application.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
            doc = application.Documents.Open(physicalPath, missing, trueObject, missing, missing, missing,
                                             missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
            //Save Excel to Html
            object format     = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
            string htmlName   = scode + ".html";//Path.GetFileNameWithoutExtension(physicalPath)
            String outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;

            doc.SaveAs(outputFile, format, missing, missing, missing,
                       missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missing,
                       missing, missing, missing, missing);
            doc.Close();
            application.Quit();
            return(Path.GetDirectoryName(Server.UrlDecode(url)) + "\\" + htmlName);
        }
Exemplo n.º 13
0
        public void FillDataToWord(Dictionary <string, object> dic)
        {
            try
            {
                object oMissing = System.Reflection.Missing.Value;
                //创建一个Word应用程序实例
                Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
                //设置为不可见
                oWord.Visible = false;
                //模板文件地址
                object oTemplate = BasePath + "\\module\\recordModule.docx";
                //以模板为基础生成文档
                Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
                //声明书签数组
                object[] oBookMark = new object[dic.Count];
                //赋值书签名
                //List<string> keyString = new List<string>(dic.Keys);
                //for (int i = 0; i < keyString.Count; i++)
                //{
                //    oBookMark[i] = keyString[i];
                //}
                oBookMark[0] = "sn";
                oBookMark[1] = "productionType";
                oBookMark[2] = "onlineDate";
                oBookMark[3] = "offlineDate";
                oBookMark[4] = "materialData";
                oBookMark[5] = "boltData";
                oBookMark[6] = "leakageData";
                System.Data.DataTable materialtable = (System.Data.DataTable)dic["material"];
                System.Data.DataTable bolttable     = (System.Data.DataTable)dic["bolt"];
                System.Data.DataTable leakagetable  = (System.Data.DataTable)dic["leakage"];
                //赋值任意数据到书签的位置
                oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = dic["sn"].ToString();
                oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = dic["productionType"].ToString();
                if (dic["onlineDate"] != null)
                {
                    oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = dic["onlineDate"].ToString();
                }
                if (dic["offlineDate"] != null)
                {
                    oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = dic["offlineDate"].ToString();
                }
                if (materialtable.Rows.Count > 0)
                {
                    Microsoft.Office.Interop.Word.Table newTable = oDoc.Tables.Add(oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range, materialtable.Rows.Count + 1, materialtable.Columns.Count);
                    newTable.set_Style("网格型");
                    //设置首行标题
                    newTable.Rows[1].Cells[1].Range.Text = "日期";
                    newTable.Rows[1].Cells[2].Range.Text = "名称";
                    newTable.Rows[1].Cells[3].Range.Text = "批次号";
                    newTable.Rows[1].Cells[4].Range.Text = "员工号";
                    newTable.Rows[1].Cells[5].Range.Text = "工位";
                    for (int i = 1; i <= materialtable.Rows.Count; i++)
                    {
                        for (int j = 0; j < materialtable.Columns.Count; j++)
                        {
                            newTable.Rows[i + 1].Cells[j + 1].Range.Text = materialtable.Rows[i - 1][j].ToString();
                        }
                    }
                }
                if (bolttable.Rows.Count > 0)
                {
                    Microsoft.Office.Interop.Word.Table boltDataTable = oDoc.Tables.Add(oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range, bolttable.Rows.Count + 1, bolttable.Columns.Count);
                    boltDataTable.set_Style("网格型");
                    //设置首行标题
                    boltDataTable.Rows[1].Cells[1].Range.Text = "日期";
                    boltDataTable.Rows[1].Cells[2].Range.Text = "名称";
                    boltDataTable.Rows[1].Cells[3].Range.Text = "角度值°";
                    boltDataTable.Rows[1].Cells[4].Range.Text = "扭矩值N/M";
                    boltDataTable.Rows[1].Cells[5].Range.Text = "结果";
                    boltDataTable.Rows[1].Cells[6].Range.Text = "员工号";
                    boltDataTable.Rows[1].Cells[7].Range.Text = "工位";
                    for (int i = 1; i <= bolttable.Rows.Count; i++)
                    {
                        for (int j = 0; j < bolttable.Columns.Count; j++)
                        {
                            boltDataTable.Rows[i + 1].Cells[j + 1].Range.Text = bolttable.Rows[i - 1][j].ToString();
                            boltDataTable.Rows[i].Cells[1].Width = 80;
                            boltDataTable.Rows[i].Cells[2].Width = 95;
                            boltDataTable.Rows[i].Cells[3].Width = 50;
                            boltDataTable.Rows[i].Cells[4].Width = 50;
                            boltDataTable.Rows[i].Cells[5].Width = 30;
                            boltDataTable.Rows[i].Cells[6].Width = 90;
                            boltDataTable.Rows[i].Cells[7].Width = 30;
                        }
                    }
                    //设置末行宽度
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[1].Width = 80;
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[2].Width = 95;
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[3].Width = 50;
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[4].Width = 50;
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[5].Width = 30;
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[6].Width = 90;
                    boltDataTable.Rows[boltDataTable.Rows.Count].Cells[7].Width = 30;
                }
                if (leakagetable.Rows.Count > 0)
                {
                    Microsoft.Office.Interop.Word.Table leakageDataTable = oDoc.Tables.Add(oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range, leakagetable.Rows.Count + 1, leakagetable.Columns.Count);
                    leakageDataTable.set_Style("网格型");
                    //设置首行标题
                    leakageDataTable.Rows[1].Cells[1].Range.Text = "日期";
                    leakageDataTable.Rows[1].Cells[2].Range.Text = "气压值";
                    leakageDataTable.Rows[1].Cells[3].Range.Text = "泄漏值";
                    leakageDataTable.Rows[1].Cells[4].Range.Text = "结果";
                    leakageDataTable.Rows[1].Cells[5].Range.Text = "员工号";
                    leakageDataTable.Rows[1].Cells[6].Range.Text = "工位";
                    for (int i = 1; i <= leakagetable.Rows.Count; i++)
                    {
                        for (int j = 0; j < leakagetable.Columns.Count; j++)
                        {
                            leakageDataTable.Rows[i + 1].Cells[j + 1].Range.Text = leakagetable.Rows[i - 1][j].ToString();
                            leakageDataTable.Rows[i].Cells[1].Width = 80;
                            leakageDataTable.Rows[i].Cells[2].Width = 40;
                            leakageDataTable.Rows[i].Cells[3].Width = 40;
                            leakageDataTable.Rows[i].Cells[4].Width = 30;
                            leakageDataTable.Rows[i].Cells[5].Width = 100;
                            leakageDataTable.Rows[i].Cells[6].Width = 30;
                            //newTable.Rows[i].Cells[7].Width = 30;
                        }
                    }
                    //设置末行宽度
                    leakageDataTable.Rows[leakageDataTable.Rows.Count].Cells[1].Width = 80;
                    leakageDataTable.Rows[leakageDataTable.Rows.Count].Cells[2].Width = 40;
                    leakageDataTable.Rows[leakageDataTable.Rows.Count].Cells[3].Width = 40;
                    leakageDataTable.Rows[leakageDataTable.Rows.Count].Cells[4].Width = 30;
                    leakageDataTable.Rows[leakageDataTable.Rows.Count].Cells[5].Width = 100;
                    leakageDataTable.Rows[leakageDataTable.Rows.Count].Cells[6].Width = 30;
                }

                //弹出保存文件对话框,保存生成的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;
                    //object filename = BasePath + "\\module\\recordModule2017.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);
                    MessageBox.Show("保存成功!");
                    oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    //关闭word
                    oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
                    Thread.Sleep(1000);
                    //  DSO_Record.Open(filename.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Word转换成pdf
        /// </summary>
        /// <param name="sourcePath">源文件路径(物理路径)</param>
        /// <param name="targetPath">目标文件路径(物理路径)</param>
        /// <returns>true=转换成功</returns>
        public static bool DOCConvertToPDF(string sourcePath, string targetPath)
        {
            //    string targetPath = "G:\\工作\\ceshi\\ceshi.pdf";
            //    sourcePath = "G:\\工作\\OfficePreview\\Preview\\SourceFile\\测试.doc";
            bool result = false;

            Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF;
            object paramMissing = Type.Missing;

            Microsoft.Office.Interop.Word.ApplicationClass wordApplication = new Microsoft.Office.Interop.Word.ApplicationClass();
            Microsoft.Office.Interop.Word._Document        wordDocument    = null;
            try
            {
                object paramSourceDocPath  = sourcePath;
                string paramExportFilePath = targetPath;
                Microsoft.Office.Interop.Word.WdExportFormat paramExportFormat = exportFormat;
                bool paramOpenAfterExport = false;
                Microsoft.Office.Interop.Word.WdExportOptimizeFor paramExportOptimizeFor = Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint;
                Microsoft.Office.Interop.Word.WdExportRange       paramExportRange       = Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument;
                int paramStartPage = 0;
                int paramEndPage   = 0;
                Microsoft.Office.Interop.Word.WdExportItem paramExportItem = Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent;
                bool paramIncludeDocProps = true;
                bool paramKeepIRM         = true;
                Microsoft.Office.Interop.Word.WdExportCreateBookmarks paramCreateBookmarks = Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
                bool paramDocStructureTags   = true;
                bool paramBitmapMissingFonts = true;
                bool paramUseISO19005_1      = false;
                wordDocument = wordApplication.Documents.Open(
                    ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing, ref paramMissing, ref paramMissing,
                    ref paramMissing);
                if (wordDocument != null)
                {
                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                                                     paramExportFormat, paramOpenAfterExport,
                                                     paramExportOptimizeFor, paramExportRange, paramStartPage,
                                                     paramEndPage, paramExportItem, paramIncludeDocProps,
                                                     paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                                                     paramBitmapMissingFonts, paramUseISO19005_1,
                                                     ref paramMissing);
                }
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordDocument = null;
                }
                if (wordApplication != null)
                {
                    wordApplication.Quit(ref paramMissing, ref paramMissing, ref paramMissing);
                    wordApplication = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
Exemplo n.º 15
0
        public static void titreCongé(string raison, string spécialité, string wilaya, string RC, string matricule_fiscal, string date, string gérant, string employé, string poste, string début, string fin, string chemin, string chemin1)
        {
            Microsoft.Office.Interop.Word.Application _ApplicationWord = new Microsoft.Office.Interop.Word.Application();
            _ApplicationWord.Visible = false;
            string path      = chemin1 + "\\Modeles\\REF-TITRE DE CONGES.docx";
            object oFileName = (object)@path;
            object Faux      = (object)false;
            object Vrai      = (object)true;
            object M         = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Document _MonDocument = _ApplicationWord.Documents.Add(ref oFileName, ref Faux, ref M, ref Vrai);

            object Nom   = (object)"Logo";
            object Nom1  = (object)"Raison";
            object Nom2  = (object)"Spécialité";
            object Nom3  = (object)"Adresse";
            object Nom4  = (object)"Rc_MatriculeFiscal";
            object Nom5  = (object)"Gérant";
            object Nom6  = (object)"Raison1";
            object Nom7  = (object)"Employé";
            object Nom8  = (object)"Poste";
            object Nom9  = (object)"Date1";
            object Nom10 = (object)"Date2";
            object Nom11 = (object)"Gérant1";
            object Nom12 = (object)"Raison2";
            object Nom13 = (object)"nbr_jours";
            object Nom14 = (object)"Début";
            object Nom15 = (object)"Fin";
            object Nom16 = (object)"Fin1";



            Microsoft.Office.Interop.Word.Bookmark    _MonSignet;
            Microsoft.Office.Interop.Word.Range       _MonRange;
            Microsoft.Office.Interop.Word.InlineShape _MonImage;



            //récupére la liste de signets
            Microsoft.Office.Interop.Word.Bookmarks _MesSignets = _MonDocument.Bookmarks;

            if (_MesSignets.Exists("Logo"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonImage = _MonRange.InlineShapes.AddPicture(@chemin1 + "\\logo.png", ref Faux, ref Vrai, ref M);
            }
            if (_MesSignets.Exists("Raison"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom1);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("Spécialité"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom2);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(spécialité);
            }
            if (_MesSignets.Exists("Adresse"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom3);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(wilaya + "/Algérie ");
            }
            if (_MesSignets.Exists("Rc_MatriculeFiscal"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom4);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(RC + "/" + matricule_fiscal);
            }
            if (_MesSignets.Exists("Gérant"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom5);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(gérant);
            }
            if (_MesSignets.Exists("Raison1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom6);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("Employé"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom7);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(employé);
            }
            if (_MesSignets.Exists("Poste"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom8);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(poste);
            }
            if (_MesSignets.Exists("Date1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom9);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date);
            }
            if (_MesSignets.Exists("Date2"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom10);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter("le " + date);
            }
            if (_MesSignets.Exists("Gérant1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom11);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(gérant);
            }
            if (_MesSignets.Exists("Raison2"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom12);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("nbr_jours"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom13);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                DateTime debut      = Convert.ToDateTime(début);
                DateTime end        = Convert.ToDateTime(fin);
                TimeSpan difference = end.Date - debut.Date;
                string   nbj        = Convert.ToString(difference.Days);
                _MonRange.InsertAfter(nbj + " ");
            }
            if (_MesSignets.Exists("Début"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom14);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(" " + début + " ");
            }
            if (_MesSignets.Exists("Fin"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom15);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(" " + fin + " ");
            }
            if (_MesSignets.Exists("Fin1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom16);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(" " + fin);
            }

            oFileName = @chemin;
            _MonDocument.SaveAs(ref oFileName, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M);

            _MonDocument.Close(ref M, ref M, ref M);
            _ApplicationWord.Application.Quit(ref M, ref M, ref M);
        }
Exemplo n.º 16
0
        private void save()
        {
            this.Enabled = true;
            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\7\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;//word模板路径

            OrignFile = "\\baseDB\\商标书式\\7 评审复审\\8商标评审代理委托书\\商标评审代理委托书(样式).dot";

            //开始写入数据

            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + "\\" + main.companyName + "\\wjgl\\7\\" + a0.Text + "\\" + a0.Text + ".docx";

            object[] MyBM = new object[21]; //创建一个书签数组

            for (int i = 0; i < 12; i++)    //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }
            MyBM[12] = "a13_1";
            MyBM[13] = "a13_2";
            MyBM[14] = "a13_3";
            MyBM[15] = "a13_4";
            MyBM[16] = "a13_5";
            MyBM[17] = "a14";
            MyBM[18] = "a15_1";
            MyBM[19] = "a15_2";
            MyBM[20] = "a15_3";
            //  MyBM[21] = "a16";

            /*      驳回商标注册申请复审案
             * 商标不予注册复审案
             * 撤销注册商标复审案
             * 注册商标无效宣告案
             * 注册商标无效宣告复审案*/

            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text  = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text  = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text  = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text  = a4.Text;
            doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text  = a5.Text;
            doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text  = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text  = a7.Text;
            doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text  = a8.Text;
            doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text  = a9.Text;
            doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text  = a10.Text;
            doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = a11.Text;
            doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = a12.Text;
            if (a13.Text == "驳回商标注册申请复审案")
            {
                doc.Bookmarks.get_Item(ref MyBM[12]).Range.Text = "✔";
            }
            if (a13.Text == "商标不予注册复审案")
            {
                doc.Bookmarks.get_Item(ref MyBM[13]).Range.Text = "✔";
            }
            if (a13.Text == "撤销注册商标复审案")
            {
                doc.Bookmarks.get_Item(ref MyBM[14]).Range.Text = "✔";
            }
            if (a13.Text == "注册商标无效宣告案")
            {
                doc.Bookmarks.get_Item(ref MyBM[15]).Range.Text = "✔";
            }
            if (a13.Text == "注册商标无效宣告复审案")
            {
                doc.Bookmarks.get_Item(ref MyBM[16]).Range.Text = "✔";
            }
            doc.Bookmarks.get_Item(ref MyBM[17]).Range.Text = a14.Text;
            doc.Bookmarks.get_Item(ref MyBM[18]).Range.Text = a15_1.Text;
            doc.Bookmarks.get_Item(ref MyBM[19]).Range.Text = a15_2.Text;
            doc.Bookmarks.get_Item(ref MyBM[20]).Range.Text = a15_3.Text;
            //  doc.Bookmarks.get_Item(ref MyBM[21]).Range.Text = a16.Text;
            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }
Exemplo n.º 17
0
 public void closeFile()
 {
     oDoc.Save();
     oDoc.Close();
 }
Exemplo n.º 18
0
        private void save()
        {
            this.Enabled = true;
            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\563\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;//word模板路径

            OrignFile = "\\baseDB\\商标书式\\3 续展变更转让许可质押注销\\6质押\\3商标专用权质权登记期限延期申请书.dot";

            //开始写入数据

            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + "\\" + main.companyName + "\\wjgl\\563\\" + a0.Text + "\\" + a0.Text + ".docx";

            object[] MyBM = new object[34]; //创建一个书签数组

            for (int i = 0; i < 34; i++)    //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }

            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text  = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text  = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text  = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text  = a4.Text;
            doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text  = a5.Text;
            doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text  = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text  = a7.Text;
            doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text  = a8.Text;
            doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text  = a9.Text;
            doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text  = a10.Text;
            doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = a11.Text;
            doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = a12.Text;
            doc.Bookmarks.get_Item(ref MyBM[12]).Range.Text = a13.Text;
            doc.Bookmarks.get_Item(ref MyBM[13]).Range.Text = a14.Text;
            doc.Bookmarks.get_Item(ref MyBM[14]).Range.Text = a15.Text;
            doc.Bookmarks.get_Item(ref MyBM[15]).Range.Text = a16.Text;
            doc.Bookmarks.get_Item(ref MyBM[16]).Range.Text = a17.Text;
            doc.Bookmarks.get_Item(ref MyBM[17]).Range.Text = a18.Text;
            doc.Bookmarks.get_Item(ref MyBM[18]).Range.Text = a19.Text;
            doc.Bookmarks.get_Item(ref MyBM[19]).Range.Text = a20.Text;
            doc.Bookmarks.get_Item(ref MyBM[20]).Range.Text = a21.Text;
            doc.Bookmarks.get_Item(ref MyBM[21]).Range.Text = a22.Text;
            doc.Bookmarks.get_Item(ref MyBM[22]).Range.Text = a23.Text;
            doc.Bookmarks.get_Item(ref MyBM[23]).Range.Text = a24.Text;
            doc.Bookmarks.get_Item(ref MyBM[24]).Range.Text = a25.Text;
            doc.Bookmarks.get_Item(ref MyBM[25]).Range.Text = a26.Text;
            doc.Bookmarks.get_Item(ref MyBM[26]).Range.Text = a27.Text;
            doc.Bookmarks.get_Item(ref MyBM[27]).Range.Text = a28.Text;
            doc.Bookmarks.get_Item(ref MyBM[28]).Range.Text = a29.Text;
            doc.Bookmarks.get_Item(ref MyBM[29]).Range.Text = a30.Text;
            doc.Bookmarks.get_Item(ref MyBM[30]).Range.Text = a31.Text;
            doc.Bookmarks.get_Item(ref MyBM[31]).Range.Text = a32.Text;
            doc.Bookmarks.get_Item(ref MyBM[32]).Range.Text = a33.Text;
            doc.Bookmarks.get_Item(ref MyBM[33]).Range.Text = a34.Text;

            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }
Exemplo n.º 19
0
        public static void certificatTravail(string raison, string spécialité, string wilaya, string Rc, string matricule_fiscal, string date, string gérant, string employé, string date_embauche, string date_emission, string poste, string chemin, string chemin1)
        {
            Microsoft.Office.Interop.Word.Application _ApplicationWord = new Microsoft.Office.Interop.Word.Application();
            _ApplicationWord.Visible = false;

            // chemin vers le modéle word qu'on doit remplir ...
            string path      = chemin1 + "\\Modeles\\REF-CERTIFICAT DE TRAVAIL.docx";
            object oFileName = (object)@path;
            object Faux      = (object)false;
            object Vrai      = (object)true;
            object M         = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Document _MonDocument = _ApplicationWord.Documents.Add(ref oFileName, ref Faux, ref M, ref Vrai);

            object Nom   = (object)"Date";
            object Nom1  = (object)"date1";
            object Nom2  = (object)"DateEmbauche";
            object Nom3  = (object)"DateEmission";
            object Nom4  = (object)"employé";
            object Nom5  = (object)"employé1";
            object Nom6  = (object)"gérant";
            object Nom7  = (object)"logo";
            object Nom8  = (object)"poste";
            object Nom9  = (object)"raison";
            object Nom10 = (object)"raison1";
            object Nom11 = (object)"raison2";
            object Nom12 = (object)"RcMatriculeFiscal";
            object Nom13 = (object)"spécialité";
            object Nom14 = (object)"wilaya";

            Microsoft.Office.Interop.Word.Bookmark    _MonSignet;
            Microsoft.Office.Interop.Word.Range       _MonRange;
            Microsoft.Office.Interop.Word.InlineShape _MonImage;



            //récupére la liste de signets
            Microsoft.Office.Interop.Word.Bookmarks _MesSignets = _MonDocument.Bookmarks;

            if (_MesSignets.Exists("Date"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date + " ");
            }
            if (_MesSignets.Exists("date1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom1);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(" " + date + " ");
            }
            if (_MesSignets.Exists("DateEmbauche"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom2);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_embauche + " ");
            }
            if (_MesSignets.Exists("DateEmission"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom3);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_emission + " ");
            }
            if (_MesSignets.Exists("employé"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom4);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(employé + " ");
            }
            if (_MesSignets.Exists("employé1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom5);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(employé + " ");
            }
            if (_MesSignets.Exists("gérant"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom6);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(gérant + " ");
            }
            if (_MesSignets.Exists("logo"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom7);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonImage = _MonRange.InlineShapes.AddPicture(@chemin1 + "\\logo.png", ref Faux, ref Vrai, ref M);
            }
            if (_MesSignets.Exists("poste"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom8);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(" " + poste + " ");
            }
            if (_MesSignets.Exists("raison"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom9);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison + " ");
            }
            if (_MesSignets.Exists("raison1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom10);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison + " ");
            }
            if (_MesSignets.Exists("raison2"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom11);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison + " ");
            }
            if (_MesSignets.Exists("RcMatriculeFiscal"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom12);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(Rc + "/" + matricule_fiscal + " ");
            }
            if (_MesSignets.Exists("spécialité"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom13);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(spécialité + " ");
            }
            if (_MesSignets.Exists("wilaya"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom14);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(wilaya + "- Algérie");
            }


            // le fichier généré et son chemin ....
            oFileName = @chemin;
            _MonDocument.SaveAs(ref oFileName, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M);

            _MonDocument.Close(ref M, ref M, ref M);
            _ApplicationWord.Application.Quit(ref M, ref M, ref M);
        }
Exemplo n.º 20
0
        private void save()
        {
            this.Enabled = false;
            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\101\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;

            OrignFile = "\\baseDB\\商标书式\\1 注册申请\\01 商标注册申请书.dot";

            //开始写入数据

            int a13_1_a = 0, a13_2_a = 0, a13_3_a = 0, a13_4_a = 0, a13_5_a = 0, a13_6_a = 0;

            if (a13_1.CheckState == CheckState.Checked)
            {
                a13_1_a = 1;
            }
            if (a13_2.CheckState == CheckState.Checked)
            {
                a13_2_a = 1;
            }
            if (a13_3.CheckState == CheckState.Checked)
            {
                a13_3_a = 1;
            }
            if (a13_4.CheckState == CheckState.Checked)
            {
                a13_4_a = 1;
            }
            if (a13_5.CheckState == CheckState.Checked)
            {
                a13_5_a = 1;
            }
            if (a13_6.CheckState == CheckState.Checked)
            {
                a13_6_a = 1;
            }



            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + "\\" + main.companyName + "\\wjgl\\101\\" + a0.Text + "\\" + a0.Text + ".docx"; //命名更改

            object[] MyBM = new object[30];                                                                    //创建一个书签数组

            for (int i = 0; i < 12; i++)                                                                       //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }
            MyBM[12] = "a13_1";
            MyBM[13] = "a13_2";
            MyBM[14] = "a13_3";
            MyBM[15] = "a13_4";
            MyBM[16] = "a13_5";
            MyBM[17] = "a13_6";
            MyBM[18] = "a14_1";
            MyBM[19] = "a14_2";
            MyBM[20] = "a14_3";

            MyBM[21] = "a15";
            MyBM[22] = "a16";
            MyBM[23] = "a17";
            MyBM[24] = "a18";
            MyBM[25] = "a19";
            MyBM[26] = "a20";
            MyBM[27] = "a21";
            MyBM[28] = "a22";
            MyBM[29] = "a25";



            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text  = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text  = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text  = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text  = a4.Text;
            doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text  = a5.Text;
            doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text  = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text  = a7.Text;
            doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text  = a8.Text;
            doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text  = a9.Text;
            doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text  = a10.Text;
            doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = a11.Text;
            doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = a12.Text;
            string xx;

            if (a13_1_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[12]).Range.Text = xx;
            if (a13_2_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[13]).Range.Text = xx;
            if (a13_3_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[14]).Range.Text = xx;
            if (a13_4_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[15]).Range.Text = xx;
            if (a13_5_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[16]).Range.Text = xx;
            if (a13_6_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[17]).Range.Text = xx;

            switch (a14.Text)
            {
            case "基于第一次申请的优先权":
                doc.Bookmarks.get_Item(ref MyBM[18]).Range.Text = "✔";
                break;

            case "基于展会的优先权":
                doc.Bookmarks.get_Item(ref MyBM[19]).Range.Text = "✔";
                break;

            case "优先权证明文件后补":
                doc.Bookmarks.get_Item(ref MyBM[20]).Range.Text = "✔";
                break;

            default:
                break;
            }


            doc.Bookmarks.get_Item(ref MyBM[21]).Range.Text = a15.Text;
            doc.Bookmarks.get_Item(ref MyBM[22]).Range.Text = a16.Text;
            doc.Bookmarks.get_Item(ref MyBM[23]).Range.Text = a17.Text;
            doc.Bookmarks.get_Item(ref MyBM[24]).Range.Text = a18.Text;
            doc.Bookmarks.get_Item(ref MyBM[25]).Range.Text = a19.Text;
            doc.Bookmarks.get_Item(ref MyBM[26]).Range.Text = a20.Text;
            doc.Bookmarks.get_Item(ref MyBM[27]).Range.Text = a21.Text;
            doc.Bookmarks.get_Item(ref MyBM[28]).Range.Text = a22.Text;
            doc.Bookmarks.get_Item(ref MyBM[29]).Range.Text = a25.Text;



            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }
Exemplo n.º 21
0
        public static void contratTravail(string raison, string spécialité, string wilaya, string Rc, string matricule_fiscal, string matricule, string nom, string prenom, string date_naissance, string wilaya_naissance, string adresse, string date_embauche, string poste, string salaire, string gérant, string chemin, string chemin1)
        {
            Microsoft.Office.Interop.Word.Application _ApplicationWord = new Microsoft.Office.Interop.Word.Application();
            _ApplicationWord.Visible = false;
            string path      = chemin1 + "\\Modeles\\REF-CONTRAT DE TRAVAIL .docx";
            object oFileName = (object)@path;
            object Faux      = (object)false;
            object Vrai      = (object)true;
            object M         = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Document _MonDocument = _ApplicationWord.Documents.Add(ref oFileName, ref Faux, ref M, ref Vrai);

            object Nom   = (object)"adresse";
            object Nom1  = (object)"DateEmbauche";
            object Nom2  = (object)"DateEmbauche1";
            object Nom3  = (object)"DateNaissance";
            object Nom4  = (object)"gérant";
            object Nom5  = (object)"matricule";
            object Nom6  = (object)"NomPrénom";
            object Nom7  = (object)"poste";
            object Nom8  = (object)"raison";
            object Nom9  = (object)"raison1";
            object Nom10 = (object)"raison2";
            object Nom11 = (object)"raison3";
            object Nom12 = (object)"raison4";
            object Nom13 = (object)"raison5";
            object Nom14 = (object)"raison6";
            object Nom15 = (object)"raison7";
            object Nom16 = (object)"RcMatriculeFiscal";
            object Nom17 = (object)"salaire";
            object Nom18 = (object)"salaire1";
            object Nom19 = (object)"spécialité";
            object Nom20 = (object)"wilaya";
            object Nom21 = (object)"WilayaNaissance";
            object Nom22 = (object)"logo";

            Microsoft.Office.Interop.Word.Bookmark    _MonSignet;
            Microsoft.Office.Interop.Word.Range       _MonRange;
            Microsoft.Office.Interop.Word.InlineShape _MonImage;



            //récupére la liste de signets
            Microsoft.Office.Interop.Word.Bookmarks _MesSignets = _MonDocument.Bookmarks;


            if (_MesSignets.Exists("adresse"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(adresse);
            }
            if (_MesSignets.Exists("DateEmbauche"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom1);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_embauche);
            }
            if (_MesSignets.Exists("DateEmbauche1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom2);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_embauche);
            }
            if (_MesSignets.Exists("DateNaissance"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom3);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_naissance);
            }
            if (_MesSignets.Exists("gérant"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom4);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(gérant);
            }
            if (_MesSignets.Exists("matricule"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom5);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(matricule);
            }
            if (_MesSignets.Exists("NomPrénom"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom6);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(" " + nom + " " + prenom + " ");
            }
            if (_MesSignets.Exists("poste"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom7);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(poste);
            }
            if (_MesSignets.Exists("raison"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom8);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom9);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison2"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom10);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison3"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom11);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison4"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom12);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison5"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom13);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison6"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom14);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison7"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom15);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("RcMatriculeFiscal"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom16);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(Rc + "/" + matricule_fiscal);
            }
            if (_MesSignets.Exists("salaire"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom17);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                double sal = (Convert.ToDouble(salaire)) * 12;
                _MonRange.InsertAfter(Convert.ToString(sal));
            }
            if (_MesSignets.Exists("salaire1"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom18);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(salaire);
            }
            if (_MesSignets.Exists("spécialité"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom19);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(spécialité);
            }
            if (_MesSignets.Exists("wilaya"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom20);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(wilaya);
            }
            if (_MesSignets.Exists("WilayaNaissance"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom21);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(wilaya_naissance);
            }
            if (_MesSignets.Exists("logo"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom22);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonImage = _MonRange.InlineShapes.AddPicture($@"{System.IO.Directory.GetCurrentDirectory()}\logo.png", ref Faux, ref Vrai, ref M);
            }



            oFileName = @chemin;
            try
            {
                _MonDocument.SaveAs(ref oFileName, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M);
            }
            catch (Exception e) { }
            _MonDocument.Close(ref M, ref M, ref M);
            _ApplicationWord.Application.Quit(ref M, ref M, ref M);
        }
Exemplo n.º 22
0
        private void save()
        {
            this.Enabled = false;

            // thw new NotImplementedException();
            int a8_1_a = 0, a8_2_a = 0, a8_3_a = 0;

            if (a8_1.CheckState == CheckState.Checked)
            {
                a8_1_a = 1;
            }
            if (a8_2.CheckState == CheckState.Checked)
            {
                a8_2_a = 1;
            }
            if (a8_3.CheckState == CheckState.Checked)
            {
                a8_3_a = 1;
            }


            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\301\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;

            OrignFile = "\\baseDB\\商标书式\\5 补证撤三出具证明\\01 补发变更转让续展证明申请书.dot";

            //开始写入数据

            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + ".\\" + main.companyName + "\\wjgl\\301\\" + a0.Text + "\\" + a0.Text + ".docx"; //命名更改

            object[] MyBM = new object[15];                                                                     //创建一个书签数组

            for (int i = 0; i < 7; i++)                                                                         //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }
            MyBM[7]  = "a8_1";
            MyBM[8]  = "a8_2";
            MyBM[9]  = "a8_3";
            MyBM[10] = "a9";
            MyBM[11] = "a10";
            MyBM[12] = "a11";
            MyBM[13] = "a12";
            MyBM[14] = "a13";



            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text = a4.Text;
            doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text = a5.Text;
            doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text = a7.Text;



            string xx;

            if (a8_1_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text = xx;
            if (a8_2_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text = xx;
            if (a8_3_a == 1)
            {
                xx = "✔";
            }
            else
            {
                xx = " ";
            }
            doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text = xx;



            doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = a9.Text;
            doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = a10.Text;
            doc.Bookmarks.get_Item(ref MyBM[12]).Range.Text = a11.Text;
            doc.Bookmarks.get_Item(ref MyBM[13]).Range.Text = a12.Text;
            doc.Bookmarks.get_Item(ref MyBM[14]).Range.Text = a13.Text;



            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }
Exemplo n.º 23
0
        public static void attestation(string raison, string spécialité, string image, string wilaya, string Rc, string matricule_fiscal, string date, string gérant, string employé, string date_naissance, string date_embauche, string poste, string chemin, string chemin1)
        {
            Microsoft.Office.Interop.Word.Application _ApplicationWord = new Microsoft.Office.Interop.Word.Application();
            _ApplicationWord.Visible = false;
            string path      = chemin1 + "\\Modeles\\REF-ATTESTATION DE TRAVAIL.docx";
            object oFileName = (object)@path;
            object Faux      = (object)false;
            object Vrai      = (object)true;
            object M         = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Word._Document _MonDocument = _ApplicationWord.Documents.Add(ref oFileName, ref Faux, ref M, ref Vrai);

            object Nom   = (object)"date";
            object Nom1  = (object)"date1";
            object Nom2  = (object)"dateEmbauche";
            object Nom3  = (object)"dateNaissance";
            object Nom4  = (object)"employé";
            object Nom5  = (object)"gérant";
            object Nom6  = (object)"gérant1";
            object Nom7  = (object)"RcMatriculeFiscal";
            object Nom8  = (object)"poste";
            object Nom9  = (object)"raison";
            object Nom10 = (object)"raison1";
            object Nom11 = (object)"raison2";
            object Nom13 = (object)"spécialité";
            object Nom14 = (object)"wilaya";
            object Nom15 = (object)"wilaya1";
            object Nom16 = (object)"logo";



            Microsoft.Office.Interop.Word.Bookmark    _MonSignet;
            Microsoft.Office.Interop.Word.Range       _MonRange;
            Microsoft.Office.Interop.Word.InlineShape _MonImage;

            //récupére la liste de signets
            Microsoft.Office.Interop.Word.Bookmarks _MesSignets = _MonDocument.Bookmarks;

            //si le signet cherché existe
            if (_MesSignets.Exists("date"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date);
            }
            if (_MesSignets.Exists("date1"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom1);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date);
            }
            if (_MesSignets.Exists("dateEmbauche"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom2);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_embauche);
            }
            if (_MesSignets.Exists("dateNaissance"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom3);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(date_naissance);
            }
            if (_MesSignets.Exists("employé"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom4);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(employé);
            }
            if (_MesSignets.Exists("gérant"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom5);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(gérant);
            }
            if (_MesSignets.Exists("gérant1"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom6);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(gérant);
            }
            if (_MesSignets.Exists("RcMatriculeFiscal"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom7);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(Rc + "/" + matricule_fiscal);
            }
            if (_MesSignets.Exists("poste"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom8);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(poste);
            }
            if (_MesSignets.Exists("raison"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom9);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison1"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom10);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("raison2"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom11);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(raison);
            }
            if (_MesSignets.Exists("spécialité"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom13);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(spécialité);
            }
            if (_MesSignets.Exists("wilaya"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom14);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(wilaya);
            }
            if (_MesSignets.Exists("wilaya1"))
            {
                //on positionne le range sur le signet et la fonction retourne true
                _MonSignet = _MesSignets.get_Item(ref Nom15);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonRange.InsertAfter(wilaya);
            }
            if (_MesSignets.Exists("logo"))
            {
                _MonSignet = _MesSignets.get_Item(ref Nom16);
                _MonSignet.Select();
                _MonRange = _MonSignet.Range;
                _MonRange.Delete(ref M, 1);
                _MonImage = _MonRange.InlineShapes.AddPicture(image + "\\logo.png", ref Faux, ref Vrai, ref M); //le chemin d'accès au logo image+ "\\Logo\\Logo.png"
            }


            oFileName = @chemin;
            _MonDocument.SaveAs(ref oFileName, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M, ref M);

            _MonDocument.Close(ref M, ref M, ref M);
            _ApplicationWord.Application.Quit(ref M, ref M, ref M);
        }
Exemplo n.º 24
0
        private void save()
        {
            this.Enabled = false;

            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\522\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;//word模板路径

            OrignFile = "\\baseDB\\商标书式\\3 续展变更转让许可质押注销\\2变更\\2撤回变更商标申请人注册人名义地址变更集体商标证明商标管理规则集体成员名单申请书.dot";

            //开始写入数据

            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + "\\" + main.companyName + "\\wjgl\\522\\" + a0.Text + "\\" + a0.Text + ".docx";

            object[] MyBM = new object[34]; //创建一个书签数组

            for (int i = 0; i < 9; i++)     //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }

            MyBM[9]  = "a10_1";
            MyBM[10] = "a10_2";
            MyBM[11] = "a11";
            MyBM[12] = "a12_1";
            MyBM[13] = "a12_2";
            for (int i = 14; i < 23; i++)//给书签数组赋值
            {
                MyBM[i] = "a" + (i - 1).ToString();
            }


            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text = a4.Text;
            doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text = a5.Text;
            doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text = a7.Text;
            doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text = a8.Text;
            doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text = a9.Text;

            if (a10.Text == "是")
            {
                doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text = "✔";
            }
            if (a10.Text == "否")
            {
                doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = "✔";
            }



            doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = a11.Text;

            if (a12_1.CheckState == CheckState.Checked)
            {
                doc.Bookmarks.get_Item(ref MyBM[12]).Range.Text = "✔";
            }
            if (a12_2.CheckState == CheckState.Checked)
            {
                doc.Bookmarks.get_Item(ref MyBM[13]).Range.Text = "✔";
            }


            doc.Bookmarks.get_Item(ref MyBM[14]).Range.Text = a14.Text;


            doc.Bookmarks.get_Item(ref MyBM[16]).Range.Text = a15.Text;
            doc.Bookmarks.get_Item(ref MyBM[17]).Range.Text = a16.Text;
            doc.Bookmarks.get_Item(ref MyBM[18]).Range.Text = a17.Text;
            doc.Bookmarks.get_Item(ref MyBM[19]).Range.Text = a18.Text;

            doc.Bookmarks.get_Item(ref MyBM[20]).Range.Text = a19.Text;
            doc.Bookmarks.get_Item(ref MyBM[21]).Range.Text = a20.Text;
            doc.Bookmarks.get_Item(ref MyBM[22]).Range.Text = a21.Text;

            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }
Exemplo n.º 25
0
        private void executeToWord(Record beforeRecord, Record afterRecord)
        {
            oWord.Visible = true;
            object oFileName = "";

            try
            {
                File.Copy(@"D:\扭力扳手校验记录单(专检)QM1_TCD00000003344_B_20180420_083651_0.doc", Application.StartupPath + @"\test.doc", true);// + DateTime.Now.ToString() + ".doc", true);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            oFileName = Application.StartupPath + @"\test.doc";
            oDoc      = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing,
                                             ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            oDoc = oWord.ActiveDocument;
            int count = oDoc.Bookmarks.Count;

            for (int i = count; i > 0; i--)
            {
                //Conclusion: "不合格non-conformity" "合格conformity"
                // ToolCode,Date,NominalValue,MaxValue,MinValue,TestData1,TestData2,TestData3,Conclusion,CheckName,QSName,
                // AfterMaxValue,AfterMinValue,AfterTorqueValue,AfterDate,AfterCheckName,AfterQSName,AfterConclusion

                if (oDoc.Bookmarks[i].Name.Equals("ToolCode"))
                {
                    oDoc.Bookmarks[i].Range.Text = beforeRecord.SeriesNum;
                }
                if (oDoc.Bookmarks[i].Name.Equals("Date"))
                {
                    oDoc.Bookmarks[i].Range.Text = beforeRecord.CreateTime.ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("NominalValue"))
                {
                    oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[0].Standard.ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("MaxValue"))
                {
                    oDoc.Bookmarks[i].Range.Text = ((beforeRecord.RecordDetailList[0].Upper + 1) * beforeRecord.RecordDetailList[0].Standard).ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("MinValue"))
                {
                    oDoc.Bookmarks[i].Range.Text = ((beforeRecord.RecordDetailList[0].Lower + 1) * beforeRecord.RecordDetailList[0].Standard).ToString();
                }
                if (beforeRecord.RecordDetailList.Count == 1)
                {
                    if (oDoc.Bookmarks[i].Name.Equals("TestData1"))
                    {
                        oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[0].TestValue.ToString();
                    }
                }
                else if (beforeRecord.RecordDetailList.Count == 2)
                {
                    if (oDoc.Bookmarks[i].Name.Equals("TestData1"))
                    {
                        oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[0].TestValue.ToString();
                    }
                    if (oDoc.Bookmarks[i].Name.Equals("TestData2"))
                    {
                        oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[1].TestValue.ToString();
                    }
                }
                else if (beforeRecord.RecordDetailList.Count == 3)
                {
                    if (oDoc.Bookmarks[i].Name.Equals("TestData1"))
                    {
                        oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[0].TestValue.ToString();
                    }
                    if (oDoc.Bookmarks[i].Name.Equals("TestData2"))
                    {
                        oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[1].TestValue.ToString();
                    }
                    if (oDoc.Bookmarks[i].Name.Equals("TestData3"))
                    {
                        oDoc.Bookmarks[i].Range.Text = beforeRecord.RecordDetailList[2].TestValue.ToString();
                    }
                }
                if (oDoc.Bookmarks[i].Name.Equals("Conclusion"))
                {
                    oDoc.Bookmarks[i].Range.Text = beforeRecord.Result == 1 ? "不合格non-conformity":"合格conformity";
                }
                if (oDoc.Bookmarks[i].Name.Equals("CheckName"))
                {
                    oDoc.Bookmarks[i].Range.Text = beforeRecord.Operator.ToString();
                }
                //if (oDoc.Bookmarks[i].Name.Equals("QSName")) oDoc.Bookmarks[i].Range.Text = record.ProName;

                if (oDoc.Bookmarks[i].Name.Equals("AfterMaxValue"))
                {
                    oDoc.Bookmarks[i].Range.Text = ((afterRecord.RecordDetailList[0].Upper + 1) * afterRecord.RecordDetailList[0].Standard).ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("AfterMinValue"))
                {
                    oDoc.Bookmarks[i].Range.Text = ((afterRecord.RecordDetailList[0].Lower + 1) * afterRecord.RecordDetailList[0].Standard).ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("AfterTorqueValue"))
                {
                    oDoc.Bookmarks[i].Range.Text = afterRecord.RecordDetailList[0].TestValue.ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("AfterDate"))
                {
                    oDoc.Bookmarks[i].Range.Text = afterRecord.CreateTime.ToString();
                }
                if (oDoc.Bookmarks[i].Name.Equals("AfterCheckName"))
                {
                    oDoc.Bookmarks[i].Range.Text = afterRecord.Operator;
                }
                //if (oDoc.Bookmarks[i].Name.Equals("AfterQSName")) oDoc.Bookmarks[i].Range.Text = afterRecord.ProName;
                if (oDoc.Bookmarks[i].Name.Equals("AfterConclusion"))
                {
                    oDoc.Bookmarks[i].Range.Text = afterRecord.Result == 0 ? "不合格non-conformity":"合格conformity";
                }
            }
            oDoc.PrintOut();
            oDoc.Save();
            oDoc.Close();
            GC.Collect();
        }
Exemplo n.º 26
0
        /// <summary>
        /// 实现导出word
        /// </summary>
        /// <param name="Data">要存储的数据</param>
        /// <param name="NewFileAddress">目的文件绝对路径。eg:J:////4.1.dot</param>
        /// <param name="TemplateAddress"></param>
        /// <returns></returns>
        public static int StoreWord(string name, int banbenhao, Data[] data, int cuowuleixingshumu, int dengji, string NewFileAddress, string TemplateAddress)
        {
            object oMissing = System.Reflection.Missing.Value;

            //创建一个Word应用程序实例
            Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
            //设置为不可见
            oWord.Visible = false;
            //模板文件地址,这里假设在X盘根目录
            //       object oTemplate = "J://学习//大三下//软件体系结构和设计模式//code//11.dot";
            object oTemplate = TemplateAddress;

            //以模板为基础生成文档
            Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
            //声明书签数组
            object[] oBookMark = new object[11];
            //赋值书签名
            oBookMark[0]  = "wenjianming";
            oBookMark[1]  = "banbenhao";
            oBookMark[2]  = "wentidengji";
            oBookMark[3]  = "weizhi";
            oBookMark[4]  = "wentimiaoshu";
            oBookMark[5]  = "yinxiangfenxi";
            oBookMark[6]  = "chulijieguo";
            oBookMark[7]  = "baogaoren";
            oBookMark[8]  = "baogaoriqi";
            oBookMark[9]  = "kaifafang";
            oBookMark[10] = "ceshifang";
            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text = name;
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text = banbenhao.ToString();
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text = dengji.ToString();
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text = name;

            string temp = "";

            for (int i = 0; i < cuowuleixingshumu; i++)
            {
                temp += "错误名称:";
                temp += data[i].name + "   ";
                temp += "错误数量:";
                temp += data[i].num.ToString();
                temp += "\n";
            }
            string a = "我是第一行\r\n" + "我是第二行";

            oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text = temp;
            if (cuowuleixingshumu == 0)
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "无错误,影响良好";
            }
            else
            {
                oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text = "有错误,请及时修改";
            }
            oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text  = "";
            oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text  = "admin";
            oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text  = DateTime.Now.ToString();
            oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text  = "admin";
            oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = "admin";

            //弹出保存文件对话框,保存生成的Word


            {
                // object filename = "J://学习//大三下//软件体系结构和设计模式//code//新导入.dot";
                object filename = NewFileAddress;
                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(1);
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            object oTemplate = "";
            object oMissing  = System.Reflection.Missing.Value;

            //创建一个Word应用程序实例
            Microsoft.Office.Interop.Word._Application oWord = new Microsoft.Office.Interop.Word.Application();
            //设置为不可见
            oWord.Visible = false;
            //模板文件地址,这里假设在X盘根目录
            try
            {
                OpenFileDialog openFileDialogEmpImage = new OpenFileDialog();
                //          openFileDialogEmpImage.Filter = "*.jpg|*.jpg|*.png|*.png|*.bmp|*.bmp|*.tiff|*.tiff";//图片格式
                if (openFileDialogEmpImage.ShowDialog() == DialogResult.OK)
                {
                    //           isUpLoadPicture = true;//记录是否上传了相片,用于后面保存操作使用:是一个成员变
                    try
                    {
                        empUpLoadPictureRealPos = openFileDialogEmpImage.FileName;//实际的文件路径+文件名
                        String[] empImageData = empUpLoadPictureRealPos.Split('.');
                        //empImageData[1]:是上传的图片的后缀名
                        empUpLoadPictureFormat = empImageData[1];
                        oTemplate = openFileDialogEmpImage.FileName;
                    }
                    catch
                    {
                        MessageBox.Show("您选择的文件不能被读取或文件类型不对!", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch
            {
            }
            //       object oTemplate = "C:\\Users\\IHCI\\Desktop\\档案领取交接单.dot";
            //以模板为基础生成文档
            Microsoft.Office.Interop.Word._Document oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
            //声明书签数组
            object[] oBookMark = new object[11];
            //赋值书签名
            oBookMark[0]  = "a1";
            oBookMark[1]  = "a2";
            oBookMark[2]  = "a3";
            oBookMark[3]  = "a4";
            oBookMark[4]  = "a5";
            oBookMark[5]  = "a6";
            oBookMark[6]  = "a7";
            oBookMark[7]  = "a8";
            oBookMark[8]  = "a9";
            oBookMark[9]  = "a10";
            oBookMark[10] = "a11";
            //赋值任意数据到书签的位置
            oDoc.Bookmarks.get_Item(ref oBookMark[0]).Range.Text  = textBoxXMDW.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[1]).Range.Text  = textBoxLQPCH.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[2]).Range.Text  = dateTimePickerlLQSJ.Value.ToString("yyyy-MM-dd");
            oDoc.Bookmarks.get_Item(ref oBookMark[3]).Range.Text  = textBoxDALX.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[4]).Range.Text  = textBoxGDFS.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[5]).Range.Text  = textBoxNX.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[6]).Range.Text  = textBox.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[7]).Range.Text  = textBoxJGDW.Text.Trim();
            oDoc.Bookmarks.get_Item(ref oBookMark[8]).Range.Text  = dateTimePickerRQ1.Value.ToString("yyyy-MM-dd");
            oDoc.Bookmarks.get_Item(ref oBookMark[9]).Range.Text  = dateTimePickerRQ2.Value.ToString("yyyy-MM-dd");
            oDoc.Bookmarks.get_Item(ref oBookMark[10]).Range.Text = textBoxDH.Text.Trim();

            //弹出保存文件对话框,保存生成的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);
            }
            ExportToExcel d = new ExportToExcel();

            d.OutputAsExcelFile(dataGridView1);
        }
Exemplo n.º 28
0
        private void save()
        {
            this.Enabled = true;
            Directory.CreateDirectory(".\\" + main.companyName + "\\wjgl\\6\\" + a0.Text + "");

            string temp = System.IO.Directory.GetCurrentDirectory();// d当前运行路径

            //    MessageBox.Show(temp);
            string OrignFile;//word模板路径

            OrignFile = "\\baseDB\\商标书式\\6 商标代理委托书\\商标代理委托书(示范文本).dot";

            //开始写入数据

            string parFilePath = temp + OrignFile;//文件路径
            object FilePath    = parFilePath;

            Microsoft.Office.Interop.Word._Application AppliApp = new Microsoft.Office.Interop.Word.Application();
            AppliApp.Visible = false;
            Microsoft.Office.Interop.Word._Document doc = AppliApp.Documents.Add(ref FilePath);
            object missing    = System.Reflection.Missing.Value;
            object isReadOnly = false;



            doc.Activate();

            //数据写入代码段


            object aa = temp + "\\" + main.companyName + "\\wjgl\\6\\" + a0.Text + "\\" + a0.Text + ".docx";

            object[] MyBM = new object[57]; //创建一个书签数组

            for (int i = 0; i < 4; i++)     //给书签数组赋值
            {
                MyBM[i] = "a" + (i + 1).ToString();
            }
            for (int i = 4; i < 42; i++)
            {
                MyBM[i] = "a5_" + (i - 3).ToString();
            }
            for (int i = 42; i < 55; i++)
            {
                MyBM[i] = "a" + (i - 36).ToString();
            }
            MyBM[46] = "a10_1";
            MyBM[55] = "a10_2";
            MyBM[56] = "a10_3";
            //给对应的书签位置写入数据
            doc.Bookmarks.get_Item(ref MyBM[0]).Range.Text = a1.Text;
            doc.Bookmarks.get_Item(ref MyBM[1]).Range.Text = a2.Text;
            doc.Bookmarks.get_Item(ref MyBM[2]).Range.Text = a3.Text;
            doc.Bookmarks.get_Item(ref MyBM[3]).Range.Text = a4.Text;

            if (a5.Text == "商标注册申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[4]).Range.Text = "✔";
            }
            else if (a5.Text == "商标异议申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[5]).Range.Text = "✔";
            }
            else if (a5.Text == "商标异议答辩")
            {
                doc.Bookmarks.get_Item(ref MyBM[6]).Range.Text = "✔";
            }
            else if (a5.Text == "更正商标申请/注意事项申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[7]).Range.Text = "✔";
            }
            else if (a5.Text == "变更商标申请人/注册人名义/地址 变更集体商标/证明商标管理规则/集体成员名单申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[8]).Range.Text = "✔";
            }
            else if (a5.Text == "变更商标代理人/文件接收人申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[9]).Range.Text = "✔";
            }
            else if (a5.Text == "删减商品/服务项目申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[10]).Range.Text = "✔";
            }
            else if (a5.Text == "商标续展注册申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[11]).Range.Text = "✔";
            }
            else if (a5.Text == "商标注册申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[12]).Range.Text = "✔";
            }
            else if (a5.Text == "转让/移转申请/注册商标申请书")
            {
                doc.Bookmarks.get_Item(ref MyBM[13]).Range.Text = "✔";
            }
            else if (a5.Text == "商标使用许可备案")
            {
                doc.Bookmarks.get_Item(ref MyBM[14]).Range.Text = "✔";
            }
            else if (a5.Text == "变更许可人/被许可人名称备案")
            {
                doc.Bookmarks.get_Item(ref MyBM[15]).Range.Text = "✔";
            }
            else if (a5.Text == "商标专用权质权登记申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[16]).Range.Text = "✔";
            }
            else if (a5.Text == "商标专用权质权登记事项变更申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[17]).Range.Text = "✔";
            }
            else if (a5.Text == "商标专用权质权登记期限延期申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[18]).Range.Text = "✔";
            }
            else if (a5.Text == "商标专用权质权登记证补发申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[19]).Range.Text = "✔";
            }
            else if (a5.Text == "商标专用权质权登记注销申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[20]).Range.Text = "✔";
            }
            else if (a5.Text == "商标注销申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[21]).Range.Text = "✔";
            }
            else if (a5.Text == "撤销连续三年不使用注册商标申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[22]).Range.Text = "✔";
            }
            else if (a5.Text == "撤销成为商品/服务通用名称注册商标申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[23]).Range.Text = "✔";
            }
            else if (a5.Text == "撤销连续三年不使用注册商标提供证据")
            {
                doc.Bookmarks.get_Item(ref MyBM[24]).Range.Text = "✔";
            }
            else if (a5.Text == "撤销成为商品/服务通用名称注册商标答辩")
            {
                doc.Bookmarks.get_Item(ref MyBM[25]).Range.Text = "✔";
            }
            else if (a5.Text == "补发变更/转让/续展证明申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[26]).Range.Text = "✔";
            }
            else if (a5.Text == "补发商标注册证申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[27]).Range.Text = "✔";
            }
            else if (a5.Text == "出具商标注册证明申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[28]).Range.Text = "✔";
            }
            else if (a5.Text == "出具优先权证明文件申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[29]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回商标注册申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[30]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回商标异议申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[31]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回变更商标申请人/注册人名义/地址 变更集体商标/证明商标管理规则/集体成员名单申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[32]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回变更商标代理人/文件接收人申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[33]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回删减商品/服务项目申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[34]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回商标续展注册申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[35]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回转让/移转申请/注册商标申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[36]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回商标使用许可备案")
            {
                doc.Bookmarks.get_Item(ref MyBM[37]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回商标注销申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[38]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回撤销连续三年不使用注册商标申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[39]).Range.Text = "✔";
            }
            else if (a5.Text == "撤回撤销成为商品/服务通用名称注册商标申请")
            {
                doc.Bookmarks.get_Item(ref MyBM[40]).Range.Text = "✔";
            }
            else
            {
                doc.Bookmarks.get_Item(ref MyBM[41]).Range.Text = a5.Text;
            }

            doc.Bookmarks.get_Item(ref MyBM[42]).Range.Text = a6.Text;
            doc.Bookmarks.get_Item(ref MyBM[43]).Range.Text = a7.Text;
            doc.Bookmarks.get_Item(ref MyBM[44]).Range.Text = a8.Text;
            doc.Bookmarks.get_Item(ref MyBM[45]).Range.Text = a9.Text;
            doc.Bookmarks.get_Item(ref MyBM[46]).Range.Text = a10_1.Text;
            doc.Bookmarks.get_Item(ref MyBM[55]).Range.Text = a10_2.Text;
            doc.Bookmarks.get_Item(ref MyBM[56]).Range.Text = a10_3.Text;

            /* doc.Bookmarks.get_Item(ref MyBM[47]).Range.Text = a11.Text;
             * doc.Bookmarks.get_Item(ref MyBM[48]).Range.Text = a12.Text;
             * doc.Bookmarks.get_Item(ref MyBM[49]).Range.Text = a13.Text;
             * doc.Bookmarks.get_Item(ref MyBM[50]).Range.Text = a14.Text;
             * doc.Bookmarks.get_Item(ref MyBM[51]).Range.Text = a15.Text;
             * doc.Bookmarks.get_Item(ref MyBM[52]).Range.Text = a16.Text;
             * doc.Bookmarks.get_Item(ref MyBM[53]).Range.Text = a17.Text;
             * doc.Bookmarks.get_Item(ref MyBM[54]).Range.Text = a18.Text;*/

            doc.SaveAs(ref aa);
            doc.Close();
            this.Enabled = true;
        }