Пример #1
0
        public static ColumnsConfiguration CreateColumnsConfiguration(
            this Word.SectionProperties sectionProperties,
            PageConfiguration pageConfiguration,
            PageMargin pageMargin)
        {
            var columns = sectionProperties.GetSectionColumnConfigs(pageConfiguration, pageMargin);

            return(new ColumnsConfiguration(columns));
        }
Пример #2
0
        private static PageMargin GetPageMargin(this Word.SectionProperties sectionProperties)
        {
            var pageMargin = sectionProperties.ChildsOfType <Word.PageMargin>().Single();

            return(new PageMargin(
                       pageMargin.Top.DxaToPoint(),
                       pageMargin.Right.DxaToPoint(),
                       pageMargin.Bottom.DxaToPoint(),
                       pageMargin.Left.DxaToPoint(),
                       pageMargin.Header.DxaToPoint(),
                       pageMargin.Footer.DxaToPoint()));
        }
Пример #3
0
        private static PageConfiguration GetPageConfiguration(
            this Word.SectionProperties sectionProperties)
        {
            var pageSize = sectionProperties.ChildsOfType <Word.PageSize>().Single();
            var w        = pageSize.Width.DxaToPoint();
            var h        = pageSize.Height.DxaToPoint();


            var orientation = (pageSize.Orient?.Value ?? Word.PageOrientationValues.Portrait) == Word.PageOrientationValues.Portrait
                ? PageOrientation.Portrait
                : PageOrientation.Landscape;

            return(new PageConfiguration(new Size(w, h), orientation));
        }
Пример #4
0
        private static Section CreateSection(
            this IReadOnlyCollection <OpenXml.OpenXmlCompositeElement> xmlElements,
            Word.SectionProperties wordSectionProperties,
            Pack.MainDocumentPart mainDocumentPart,
            HeaderFooterConfiguration headerFooterConfiguration,
            bool isFirst,
            IStyleFactory styleFactory)
        {
            var imageAccessor = new ImageAccessor(mainDocumentPart);

            var sectionProperties    = wordSectionProperties.CreateSectionProperties(mainDocumentPart, isFirst, headerFooterConfiguration);
            var columnsConfiguration = wordSectionProperties.CreateColumnsConfiguration(sectionProperties.PageConfiguration, sectionProperties.Margin);
            var sectionContents      = xmlElements.SplitToSectionContents(columnsConfiguration, imageAccessor, styleFactory);
            var sd = new Section(sectionProperties, sectionContents, imageAccessor, styleFactory);

            return(sd);
        }
Пример #5
0
        private static HeaderFooterConfiguration GetHeaderFooterConfiguration(
            this Word.SectionProperties wordSectionProperties,
            Pack.MainDocumentPart mainDocument,
            HeaderFooterConfiguration previousHeaderFooterConfiguration)
        {
            var hasTitlePage = wordSectionProperties.ChildsOfType <Word.TitlePage>().SingleOrDefault()
                               .IsOn(ifOnOffTypeNull: false, ifOnOffValueNull: true);

            var headerRefs = wordSectionProperties
                             .ChildsOfType <Word.HeaderReference>()
                             .Select(fr => new HeaderFooterRef(fr.Id, fr.Type));

            var footerRefs = wordSectionProperties
                             .ChildsOfType <Word.FooterReference>()
                             .Select(fr => new HeaderFooterRef(fr.Id, fr.Type));

            return(previousHeaderFooterConfiguration.Inherited(mainDocument, hasTitlePage, headerRefs, footerRefs));
        }
Пример #6
0
        private static IEnumerable <ColumnConfig> GetSectionColumnConfigs(
            this Word.SectionProperties wordSectionProperties,
            PageConfiguration page,
            PageMargin pageMargin)
        {
            var columns = wordSectionProperties
                          .ChildsOfType <Word.Columns>()
                          .SingleOrDefault();

            var totalColumnsWidth = page.Width - pageMargin.HorizontalMargins;
            var columnsCount      = columns.ColumnCount?.Value ?? 1;

            if (columnsCount == 1)
            {
                return(new[] { new ColumnConfig(totalColumnsWidth, 0) });
            }

            if (columns.EqualWidth.IsOn(true))
            {
                var space       = columns.Space.ToPoint();
                var columnWidth = (totalColumnsWidth - space * (columnsCount - 1)) / columnsCount;

                return(Enumerable.Range(0, columnsCount)
                       .Select(i =>
                {
                    var s = i == columnsCount - 1
                            ? 0
                            : space;
                    return new ColumnConfig(columnWidth, s);
                })
                       .ToArray());
            }

            var cols = columns
                       .ChildsOfType <Word.Column>()
                       .Select(col =>
            {
                var cw    = col.Width.ToPoint();
                var space = col.Space.ToPoint();
                return(new ColumnConfig(cw, space));
            });

            return(cols);
        }
Пример #7
0
        private static SectionProperties CreateSectionProperties(
            this Word.SectionProperties wordSectionProperties,
            Pack.MainDocumentPart mainDocument,
            bool isFirstSection,
            HeaderFooterConfiguration inheritHeaderFooterConfiguration)
        {
            var pageCongifuration = wordSectionProperties.GetPageConfiguration();
            var pageMargin        = wordSectionProperties.GetPageMargin();

            var sectionMark = wordSectionProperties.ChildsOfType <Word.SectionType>().SingleOrDefault()?.Val ?? Word.SectionMarkValues.NextPage;

            var requiresNewPage = isFirstSection || sectionMark == Word.SectionMarkValues.NextPage;

            var headerFooterConfiguration = wordSectionProperties
                                            .GetHeaderFooterConfiguration(mainDocument, inheritHeaderFooterConfiguration);

            return(new SectionProperties(
                       pageCongifuration,
                       headerFooterConfiguration,
                       pageMargin,
                       requiresNewPage));
        }
        public static DocumentFormat.OpenXml.OpenXmlElement[] GetFormattedSection(MultiColumnSection section)
        {
            List<DocumentFormat.OpenXml.OpenXmlElement> formattedSection = new List<DocumentFormat.OpenXml.OpenXmlElement>();
            Element[] elements = section.SubElements;

            foreach (var element in elements)
            {
                formattedSection.AddRange(ElementFactory.GetElement(element));
            }

            Word.Columns cols = new Word.Columns()
            {
                ColumnCount = (Int16Value)section.NumberOfColumns
            };

            Word.SectionProperties secProps = new Word.SectionProperties(cols);
            Word.ParagraphProperties paraProp = new Word.ParagraphProperties(secProps);
            Word.Paragraph para = new Word.Paragraph(paraProp);

            formattedSection.Add(para);

            return formattedSection.ToArray();
        }
        public static DocumentFormat.OpenXml.OpenXmlElement[] GetFormattedSection(Section section)
        {
            List<DocumentFormat.OpenXml.OpenXmlElement> formattedSection = new List<DocumentFormat.OpenXml.OpenXmlElement>();
            Element[] elements = section.SubElements;

            foreach (var element in elements)
            {
                if (section.CanContain(element.GetElementType())) formattedSection.AddRange(ElementFactory.GetElement(element));
                else throw new InvalidSubFeatureException( section.GetElementType().ToString(), element.GetElementType().ToString() );
            }

            Word.Columns cols = new Word.Columns()
            {
                ColumnCount = (Int16Value)1
            };

            Word.SectionProperties secProps = new Word.SectionProperties(cols);
            Word.ParagraphProperties paraProp = new Word.ParagraphProperties(secProps);
            Word.Paragraph para = new Word.Paragraph(paraProp);

            formattedSection.Add(para);

            return formattedSection.ToArray();
        }
Пример #10
0
        public static Word.SectionMarkValues GetSectionMark(this Word.SectionProperties sectionProperties)
        {
            var st = sectionProperties.ChildsOfType <Word.SectionType>().SingleOrDefault();

            return(st?.Val ?? Word.SectionMarkValues.NextPage);
        }