Exemple #1
0
        public void SaveFile(AcceptanceOfficeTemplate acceptanceOfficeTemplate)
        {
            OpenPathExplorer();
            DocumentGenerator documentGenerator = new DocumentGenerator();

            documentGenerator.CreateAcceptanceOfficeDocument($"{_savingPath}", acceptanceOfficeTemplate);
            throw new InvalidPathException();
        }
Exemple #2
0
        //Create the Doc Method
        public void CreateAcceptanceOfficeDocument(object SaveAs, AcceptanceOfficeTemplate acceptanceOfficeTemplate)
        {
            object filename = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Views\\AcceptanceOfficeTemplate.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, "<officeNumber>", "09/04");
                this.FindAndReplace(wordApp, myWordDoc, "<day>", acceptanceOfficeTemplate.Day.ToString());
                this.FindAndReplace(wordApp, myWordDoc, "<month>", acceptanceOfficeTemplate.Month);
                this.FindAndReplace(wordApp, myWordDoc, "<year>", acceptanceOfficeTemplate.Year.ToString());
                this.FindAndReplace(wordApp, myWordDoc, "<coordinatorNameUpperCase>", acceptanceOfficeTemplate.CoordinatorName.ToUpper());
                this.FindAndReplace(wordApp, myWordDoc, "<coordinatorName>", acceptanceOfficeTemplate.CoordinatorName);
                this.FindAndReplace(wordApp, myWordDoc, "<practicionerName>", acceptanceOfficeTemplate.PracticionerName);
                this.FindAndReplace(wordApp, myWordDoc, "<practicionerEnrollment>", acceptanceOfficeTemplate.PracticionerEnrollment);
                this.FindAndReplace(wordApp, myWordDoc, "<linkedOrganizationName>", acceptanceOfficeTemplate.LinkedOrganizationName);
                this.FindAndReplace(wordApp, myWordDoc, "<startingDate>", acceptanceOfficeTemplate.StartingDate.ToString());
                this.FindAndReplace(wordApp, myWordDoc, "<projectDuration>", acceptanceOfficeTemplate.ProjectDuration.ToString());
                this.FindAndReplace(wordApp, myWordDoc, "<mondaySchedule>", acceptanceOfficeTemplate.MondaySchedule);
                this.FindAndReplace(wordApp, myWordDoc, "<tuesdaySchedule>", acceptanceOfficeTemplate.TuesdaySchedule);
                this.FindAndReplace(wordApp, myWordDoc, "<wednesdaySchedule>", acceptanceOfficeTemplate.WednesdaySchedule);
                this.FindAndReplace(wordApp, myWordDoc, "<thursdaySchedule>", acceptanceOfficeTemplate.ThursdaySchedule);
                this.FindAndReplace(wordApp, myWordDoc, "<fridaySchedule>", acceptanceOfficeTemplate.FridaySchedule);
                this.FindAndReplace(wordApp, myWordDoc, "<coordinatorEmail>", acceptanceOfficeTemplate.CoordinatorEmail);
                this.FindAndReplace(wordApp, myWordDoc, "<coordinatorPhoneNumber>", acceptanceOfficeTemplate.CoordinatorPhoneNumber);
                this.FindAndReplace(wordApp, myWordDoc, "<coordinatorCharge>", acceptanceOfficeTemplate.CoordinatorCharge);
            }

            //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();
        }