コード例 #1
0
ファイル: FormMain.cs プロジェクト: 20thfox/Test2
        private void CheckCabLine()
        {
            try
            {
                Object template     = @"C:\Users\Twent\Desktop\Templates\CheckCabLine.docx";
                Object newTemplate  = false;
                Object documentType = Word.Word.WdNewDocumentType.wdNewBlankDocument;
                Object visible      = true;



                worddocument = wordapp.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
                GenFormat();

                //Чтото происходит

                Save();
            }
            catch (Exception)
            {
                wordapp.Quit(ref falseObj, ref missingObj, ref missingObj);
                worddocument = null;
                wordapp      = null;
                genFaultActive();
            }
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: 20thfox/Test2
        private void CabLine()
        {
            try
            {
                Object template     = @"C:\Users\Twent\Desktop\Templates\CabLine1.docx";
                Object newTemplate  = false;
                Object documentType = Word.Word.WdNewDocumentType.wdNewBlankDocument;
                Object visible      = true;



                worddocument = wordapp.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible); //создание объекта документа по шаблону
                GenFormat();

                Save();

                //
                //вывод таблицы из проги и вставка в документ
                //резерв table2
            }
            catch (Exception)
            {
                wordapp.Quit(ref falseObj, ref missingObj, ref missingObj);
                worddocument = null;
                wordapp      = null;
                genFaultActive();
            }
        }
コード例 #3
0
 public Tuple <Excel.Excel.Application, Excel.Excel.Workbook, Excel.Excel.Worksheet, Excel.Excel.Worksheet, Excel.Excel.Worksheet> opendatasource()
 {
     xlApp      = new Excel.Excel.Application();
     xlWorkBook = xlApp.Workbooks.Open(strExcelFilePath
                                       , 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
     xlWorkSheetFirst  = (Excel.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
     xlWorkSheetSecond = (Excel.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
     xlWorkSheetThird  = (Excel.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(3);
     return(Tuple.Create(xlApp, xlWorkBook, xlWorkSheetFirst, xlWorkSheetSecond, xlWorkSheetThird));
 }
コード例 #4
0
        public void TC01()
        {
            CostCalculation cc = new CostCalculation();

            cc.opendatasource();
            Tuple <Excel.Excel.Application, Excel.Excel.Workbook, Excel.Excel.Worksheet,
                   Excel.Excel.Worksheet, Excel.Excel.Worksheet> getData = cc.opendatasource();

            xlApp             = getData.Item1;
            xlWorkBook        = getData.Item2;
            xlWorkSheetFirst  = getData.Item3;
            xlWorkSheetSecond = getData.Item4;
            xlWorkSheetThird  = getData.Item5;
        }
コード例 #5
0
        private void FindAndReplace(Microsoft.Office.Interop.Word.Application wordApp, object findText, object replaceWithText)
        {
            object matchCase       = true;
            object matchWholeWord  = true;
            object matchWildCards  = true;
            object matchSoundLike  = true;
            object matchAllForms   = true;
            object forward         = true;
            object format          = false;
            object matchKashida    = false;
            object matchDiactities = false;
            object matchAlefHamza  = false;
            object matchControl    = false;
            object read_only       = false;
            object visible         = true;
            object replace         = 2;
            object wrap            = 1;

            wordApp.Selection.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref matchSoundLike, ref matchAllForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace, ref matchKashida, ref matchDiactities, ref matchAlefHamza, ref matchControl);
        }
コード例 #6
0
        //-----------------------------------------
        private void CreateWordDocument(object filename, object saveAs, object imagePath)
        {
            object missing  = Missing.Value;
            string tempPath = null;

            Word.Word.Application wordApp = new Word.Word.Application();
            Word.Word.Document    aDoc    = null;
            if (File.Exists((string)filename))
            {
                DateTime today     = DateTime.Now;
                object   readOnly  = false;
                object   isVisible = true;
                wordApp.Visible = true;
                aDoc            = wordApp.Documents.Open(ref filename, ref missing, ref readOnly
                                                         , 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);
                aDoc.Activate();

                //Find and replace:
                this.FindAndReplace(wordApp, "$$EmployeeID$$", _presenter.CurrentEmployee.AppUser.EmployeeNo);
                this.FindAndReplace(wordApp, "$$FirstName$$", _presenter.CurrentEmployee.FirstName);
                this.FindAndReplace(wordApp, "$$LastName$$", _presenter.CurrentEmployee.LastName);
                this.FindAndReplace(wordApp, "$$EmailAddress$$", _presenter.CurrentEmployee.ChaiEMail);


                //insert the picture:


                Object oMissed           = aDoc.Paragraphs[1].Range; //the position you want to insert
                Object oLinkToFile       = false;                    //default
                Object oSaveWithDocument = true;                     //default
                aDoc.InlineShapes.AddPicture(tempPath, ref oLinkToFile, ref oSaveWithDocument, ref oMissed);

                #region Print Document :
                #endregion
            }
        }
コード例 #7
0
        public void PreencherNoWord(ModeloCarne modeloCarne, ProgressBar progressBar)
        {
            int quantosCarnes;

            object campoBranco = System.Reflection.Missing.Value;

            Word.Word.Application oApp = new Word.Word.Application();
            progressBar.Value = 2;
            object caminhoContrato = System.IO.Path.GetFullPath("Carne\\" + modeloCarne.mes + ".docx");

            progressBar.Value = 4;
            Word.Word.Document contrato = oApp.Documents.Add(ref caminhoContrato, false, ref campoBranco, false);
            progressBar.Value = 6;
            mudarTudo(contrato, campoBranco, modeloCarne.nomeAluno, "[nomealuno]");
            progressBar.Value = 8;
            mudarTudo(contrato, campoBranco, modeloCarne.mensalidadeNormal, "[valornormal]");
            progressBar.Value = 10;
            mudarTudo(contrato, campoBranco, modeloCarne.mensalidadeDesconto, "[valordesconto]");
            progressBar.Value = 12;
            mudarTudo(contrato, campoBranco, modeloCarne.portugues, "[P]");
            progressBar.Value = 16;
            mudarTudo(contrato, campoBranco, modeloCarne.matematica, "[M]");
            progressBar.Value = 18;
            mudarTudo(contrato, campoBranco, modeloCarne.ingles, "[I]");
            progressBar.Value = 20;

            if (modeloCarne.mes <= 9)
            {
                quantosCarnes = 9 - (modeloCarne.mes - 1);

                for (int x = 1; x <= quantosCarnes; x++)
                {
                    progressBar.Value += 80 / quantosCarnes;
                    mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year, modeloCarne.mes + (x - 1)), "[" + x + "]");
                }
            }
            else
            {
                if (modeloCarne.mes == 10)
                {
                    for (int x = 1; x <= 3; x++)
                    {
                        progressBar.Value += 80 / 12;
                        mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year, modeloCarne.mes + (x - 1)), "[" + x + "]");
                    }

                    for (int x = 4; x <= 12; x++)
                    {
                        progressBar.Value += 80 / 12;
                        mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year + 1, (x - 3)), "[" + x + "]");
                    }
                }
                else if (modeloCarne.mes == 11)
                {
                    for (int x = 1; x <= 2; x++)
                    {
                        progressBar.Value += 80 / 11;
                        mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year, modeloCarne.mes + (x - 1)), "[" + x + "]");
                    }

                    for (int x = 3; x <= 11; x++)
                    {
                        progressBar.Value += 80 / 11;
                        mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year + 1, (x - 2)), "[" + x + "]");
                    }
                }
                else
                {
                    progressBar.Value += 80 / 10;
                    mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year, 12), "[1]");

                    for (int x = 2; x <= 10; x++)
                    {
                        progressBar.Value += 80 / 10;
                        mudarTudo(contrato, campoBranco, quintoDia.RetornaQuintoDiaUtil(DateTime.Now.Year + 1, (x - 1)), "[" + x + "]");
                    }
                }
            }

            oApp.Visible = true;
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: 20thfox/Test2
        /*private void файлToolStripMenuItem_Click(object sender, EventArgs e)
         * {
         *  wordapp = new Word.Word.Application();
         *  wordapp.Visible = true;
         *  Object template = @"C:\111.docx"; //Type.Missing;
         *  Object newTemplate = false;
         *  Object documentType = Word.Word.WdNewDocumentType.wdNewBlankDocument;
         *  Object visible = true;
         *  //Object begin = 538; предполагаемое место Присоединения
         *  //Object end = 540;
         *  worddocument = wordapp.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
         *  //Word.Word.Range range = worddocument.Range(ref begin, ref end);
         *  //range.Select();
         *
         * } *///Открытие документа по верхнему меню.

        private void button1_Click(object sender, EventArgs e)
        {
            if (SavePath == null)
            {
                MessageBox.Show("Введите место сохранения");
            }
            else if (SavePath == "")
            {
                MessageBox.Show("Введите место сохранения");
            }
            else
            {
                wordapp = new Word.Word.Application
                {
                    Visible = false
                };
                CheckedListBox.CheckedIndexCollection CheckedItems = checkedListBox1.CheckedIndices;
                progressBar1.Maximum = CheckedItems.Count;
                if (checkedListBox1.GetItemChecked(0) == true)
                {
                    NumOfProt++;
                    SaveName = "Вторичная коммутация";
                    GenVtorCom();
                    progressBar1.Value++;
                }
                if (checkedListBox1.GetItemChecked(1) == true)
                {
                    NumOfProt++;
                    SaveName = "Металлосвязь";
                    GenGround();
                    progressBar1.Value++;
                }
                if (checkedListBox1.GetItemChecked(2) == true)
                {
                    NumOfProt++;
                    SaveName = "Электродвигатели";
                    GenEngine();
                    progressBar1.Value++;
                }
                if (checkedListBox1.GetItemChecked(3) == true)
                {
                    NumOfProt++;
                    SaveName = "Параметрирование ПЛК";
                    GenPLC();
                    progressBar1.Value++;
                }
                if (checkedListBox1.GetItemChecked(4) == true)
                {
                    NumOfProt++;
                    SaveName = "Кабельные линии";
                    CabLine();
                    progressBar1.Value++;
                }
                if (checkedListBox1.GetItemChecked(5) == true)
                {
                    NumOfProt++;
                    SaveName = "Испытание контрольных кабельных линий";
                    CheckCabLine();
                    progressBar1.Value++;
                }

                if (GeneralFault == false)
                {
                    wordapp.Quit(ref falseObj, ref missingObj, ref missingObj);
                    NumOfProt = 0;
                    MessageBox.Show("Завершено успешно");
                    progressBar1.Value = 0;
                }
            }
        }
コード例 #9
0
        public void PreencherNoWord(ModeloContrato modeloContrato, ProgressBar progressBar)
        {
            progressBar.Value = 23;
            object campoBranco = System.Reflection.Missing.Value;

            Word.Word.Application oApp = new Word.Word.Application();

            object caminhoContrato = System.IO.Path.GetFullPath("Contrato.doc");

            Word.Word.Document contrato = oApp.Documents.Add(ref caminhoContrato, false, ref campoBranco, false);

            progressBar.Value = 26;

            mudar(contrato, campoBranco, modeloContrato.nomeAluno, "[nomeAluno]");
            progressBar.Value = 29;
            mudar(contrato, campoBranco, modeloContrato.dataNascimentoAluno, "[dataNascimentoAluno]");
            progressBar.Value = 32;
            mudar(contrato, campoBranco, modeloContrato.telefoneAluno, "[telefoneAluno]");
            progressBar.Value = 35;
            mudar(contrato, campoBranco, modeloContrato.celularAluno, "[celularAluno]");
            progressBar.Value = 38;
            mudar(contrato, campoBranco, modeloContrato.nomeContratante, "[nomeContratante]");
            progressBar.Value = 41;
            mudar(contrato, campoBranco, modeloContrato.nomeContratante, "[nomeContratante]");
            progressBar.Value = 44;
            mudar(contrato, campoBranco, modeloContrato.telefoneContratante, "[telefoneContratante]");
            progressBar.Value = 47;
            mudar(contrato, campoBranco, modeloContrato.celularContratante, "[celularContratante]");
            progressBar.Value = 50;
            mudar(contrato, campoBranco, modeloContrato.rgContratante, "[rgContratante]");
            progressBar.Value = 53;
            mudar(contrato, campoBranco, modeloContrato.cpfContratante, "[cpfContratante]");
            progressBar.Value = 56;
            mudar(contrato, campoBranco, modeloContrato.enderecoContratante, "[enderecoContratante]");
            progressBar.Value = 59;
            mudar(contrato, campoBranco, modeloContrato.matematica, "[matematica]");
            progressBar.Value = 62;
            mudar(contrato, campoBranco, modeloContrato.portugues, "[portugues]");
            progressBar.Value = 65;
            mudar(contrato, campoBranco, modeloContrato.ingles, "[ingles]");
            progressBar.Value = 68;
            mudar(contrato, campoBranco, modeloContrato.seisMeses, "[seisMeses]");
            progressBar.Value = 71;
            mudar(contrato, campoBranco, modeloContrato.dozeMeses, "[dozeMeses]");
            progressBar.Value = 74;
            mudar(contrato, campoBranco, modeloContrato.inicioDoCurso, "[inicioDoCurso]");
            progressBar.Value = 77;
            mudar(contrato, campoBranco, modeloContrato.diasDaSemana, "[diasDaSemana]");
            progressBar.Value = 80;
            mudar(contrato, campoBranco, modeloContrato.horarios, "[horarios]");
            progressBar.Value = 82;
            mudar(contrato, campoBranco, modeloContrato.taxaMatricula, "[taxaMatricula]");
            progressBar.Value = 84;
            mudar(contrato, campoBranco, modeloContrato.taxaMatriculaExtenso, "[taxaMatriculaExtenso]");
            progressBar.Value = 86;
            mudar(contrato, campoBranco, modeloContrato.mensalidade, "[mensalidade]");
            progressBar.Value = 88;
            mudar(contrato, campoBranco, modeloContrato.mensalidadeExtenso, "[mensalidadeExtenso]");
            progressBar.Value = 90;
            mudar(contrato, campoBranco, modeloContrato.dataFinalContrato, "[dataFinalContrato]");
            progressBar.Value = 92;
            mudar(contrato, campoBranco, modeloContrato.nomeTestemunha1, "[nomeTestemunha1]");
            progressBar.Value = 94;
            mudar(contrato, campoBranco, modeloContrato.rgTestemunha1, "[rgTestemunha1]");
            progressBar.Value = 96;
            mudar(contrato, campoBranco, modeloContrato.nomeTestemunha2, "[nomeTestemunha2]");
            progressBar.Value = 98;
            mudar(contrato, campoBranco, modeloContrato.rgTestemunha2, "[rgTestemunha2]");
            progressBar.Value = 99;

            oApp.Visible = true;
        }