Beispiel #1
0
        private void CreateAssignDocument(object SaveAs, Estudiante student, string projectName, Organización organization, Responsableproyecto responsibleProject)
        {
            object filename = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\Utilities\\DocTemplates\\AssignDocTemplate.docx"));

            Word.Application wordApp = new Word.Application();
            object           missing = Missing.Value;

            Word.Document myWordDoc = null;

            if (File.Exists((string)filename))
            {
                object readOnly  = false;
                object isVisible = false;
                wordApp.Visible = false;

                myWordDoc = 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);
                myWordDoc.Activate();

                //find and replace
                this.FindAndReplace(wordApp, myWordDoc, "<studentName>", student.Nombre + " " + student.Apellidopaterno + " " + student.Apellidomaterno);
                this.FindAndReplace(wordApp, myWordDoc, "<studentNumber>", student.Matricula);
                this.FindAndReplace(wordApp, myWordDoc, "<projectName>", projectName);
                this.FindAndReplace(wordApp, myWordDoc, "<projectManagerName>", responsibleProject.Nombre + " " + responsibleProject.Apellidopaterno + " " + responsibleProject.Apellidomaterno);
                this.FindAndReplace(wordApp, myWordDoc, "<OrganizationName>", organization.Nombre);
                this.FindAndReplace(wordApp, myWordDoc, "<OrganizationAddress>", organization.Calle + " #" + organization.Numext + " Col." + organization.Colonia);
                this.FindAndReplace(wordApp, myWordDoc, "<day>", thisDay.Day.ToString());
                this.FindAndReplace(wordApp, myWordDoc, "<month>", Period.CaclulateMonth(thisDay.Month));
                this.FindAndReplace(wordApp, myWordDoc, "<year>", thisDay.Year.ToString());

                //Save as
                myWordDoc.SaveAs2(ref SaveAs, 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);

                myWordDoc.Close();
                wordApp.Quit();
            }
            else
            {
                CustomMessageBox.Show("Plantilla de oficio de asignación no encontrada");
            }
        }