Ejemplo n.º 1
0
        public static void Generate(IEnumerable <EFU> efus)
        {
            string content = string.Join(HtmlNewLine, efus.Select(GetContent));

            ColorConsole.WriteLine($"Generating Document from Work-items...".Cyan());
            var wordApp = new Word.Application {
                Visible = false, DisplayAlerts = Word.WdAlertLevel.wdAlertsNone, ScreenUpdating = false
            };
            object fileName = WordTemplate.GetFullPath();
            object missing  = Type.Missing;
            var    wordDoc  = wordApp.Documents.Open(
                ref fileName,
                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);

            var value    = "<html><body style=\"font-family:'segoe ui';font-size:14px\">" + content + "</body></html>";
            var bookmark = wordDoc.Bookmarks.get_Item(1);

            ReplaceBookmark(bookmark.Range, value);

            object saveTo = Path.Combine(Environment.CurrentDirectory, "FuncSpec (UserStories).docx");
            object format = Word.WdSaveFormat.wdFormatXMLDocument;

            object start = wordDoc.Content.Start;
            object end   = wordDoc.Content.End;

            wordDoc.Range(ref start, ref end).Select();
            wordApp.Selection.Range.Font.Name = "Segoe UI";
            wordApp.Selection.Range.Font.Size = 10;

            wordDoc.TrackRevisions = true;
            //// var translate = wordDoc.Research.SetLanguagePair(Word.WdLanguageID.wdSpanishModernSort, Word.WdLanguageID.wdEnglishUS);
            wordDoc.SaveAs(ref saveTo, ref format);
            wordDoc.Close(ref missing, ref missing, ref missing);
            wordDoc.NAR();
            wordApp.Quit(ref missing, ref missing, ref missing);
            wordApp.NAR();
            File.Delete("temp.html".GetFullPath());
            ColorConsole.WriteLine($"Done creating {saveTo}");
            Process.Start("cmd", $"/c \"{saveTo}\"");
        }