Пример #1
0
        private static bool FormatDocument()
        {
            var documentFormatter = new DocumentFormatter(
                new ClauserUnitStrategy(new ClauserUnitChecker()),
                new AdverbUnitStrategy(),
                new TimerUnitStrategy(),
                new ModifierStrategy(new ModifierFormatter()),
                new PrenStrategy());

            List <OpenXmlElement> shuffledXmlElements = new List <OpenXmlElement>();

            try
            {
                using (var document = WordprocessingDocument.Open(wordPath, true))
                {
                    var docPart = document.MainDocumentPart;
                    if (docPart?.Document != null)
                    {
                        shuffledXmlElements = documentFormatter.ProcessDocument(docPart);
                    }
                    CreateAndSaveShuffledDocument(shuffledXmlElements);
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                return(false);
            }

            return(true);
        }
        private static List <OpenXmlElement> GetDocument(string documentName)
        {
            List <OpenXmlElement> elements;

            using (WordprocessingDocument document =
                       DocumentContentHelper.GetMainDocumentPart(documentName))
            {
                // arrange
                var documentFormatter = new DocumentFormatter(
                    new ClauserUnitStrategy(new ClauserUnitChecker()),
                    new AdverbUnitStrategy(),
                    new TimerUnitStrategy(),
                    new ModifierStrategy(new ModifierFormatter()),
                    new PrenStrategy());

                var docPart = document.MainDocumentPart;
                if (docPart?.Document == null)
                {
                    throw new Exception();
                }

                // act
                elements = documentFormatter.ProcessDocument(docPart);
            }
            return(elements);
        }