Exemplo n.º 1
0
        public static void PreviewCandidatePackage(QuestionSet questionSet)
        {
            Application wordApp = null;

            try
            {
                wordApp = new Application();
                //Init a Document in Word application
                wordApp.Visible = true;
                object   missing = Missing.Value;
                Document doc     = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
                //Settings Page
                DocUtils.SettingsPage(doc);

                //Insert Header and Footer of the page
                DocUtils.SettingsHeaderAndFooter(null, doc);

                //Insert QuestionRequirement of the Exam
                for (int i = 0; i < questionSet.QuestionList.Count; i++)
                {
                    Section section = (i == 0) ? doc.Sections.First : doc.Sections.Add();
                    for (int j = 0; j < questionSet.QuestionList.ElementAt(i).Candidates.Count; j++)
                    {
                        AppendSection(questionSet.QuestionList.ElementAt(i).Candidates.ElementAt(j), section, (i + 1), (j + 1), ref missing);
                    }
                }
            }
            catch (Exception e)
            {
                wordApp?.Application.Quit(false);
                throw e;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Export Doc in path
        /// </summary>
        /// <param name="paper"></param>
        /// <param name="path">Save to location</param>
        /// <returns></returns>
        public static void ExportDoc(Paper paper, string path)
        {
            Application wordApp = null;

            try
            {
                //Start new Word Application
                wordApp = new Application
                {
                    Visible       = false,
                    ShowAnimation = false
                };
                object missing = Missing.Value;
                var    doc     = wordApp.Documents.Add(missing);
                //Settings Page
                DocUtils.SettingsPage(doc);

                //Setings Header and Footer of the page
                DocUtils.SettingsHeaderAndFooter(paper, doc);

                //Insert QuestionRequirement of the Exam
                for (int i = 0; i < paper.CandidateSet.Count; i++)
                {
                    AppendTestQuestion(paper.CandidateSet.ElementAt(i), doc, (i + 1), ref missing);
                }
                //Saving file
                DocUtils.SavingDocFile(doc, path, paper);
            }
            finally
            {
                wordApp?.Application.Quit(false);
            }
        }