コード例 #1
0
ファイル: RowConverter.cs プロジェクト: moayyaed/ReportDotNet
        public static TableRow Convert(Row row,
                                       WordprocessingDocument document,
                                       Table table,
                                       int[] tableWidths)
        {
            var docxRow    = new TableRow();
            var parameters = row.Parameters;

            if (parameters.Height.HasValue)
            {
                docxRow.TableRowProperties = new TableRowProperties();
                docxRow.TableRowProperties.AppendChild(new TableRowHeight
                {
                    Val        = (uint)parameters.Height.Value * OpenXmlUnits.Dxa,
                    HeightType = ConvertHeightType(parameters.HeightType)
                });
            }

            var spans = Helpers.GetSpans(tableWidths, row.GetWidths());
            var cells = parameters.GetCells().ToArray();

            for (var i = 0; i < cells.Length; i++)
            {
                docxRow.AppendChild(CellConverter.Convert(cells[i], document, table, spans[i]));
            }

            return(docxRow);
        }
コード例 #2
0
        public static OpenXmlElement Convert(Table table,
                                             WordprocessingDocument document)
        {
            var parameters = table.Parameters;
            var widths     = Helpers.GetWidths(parameters.Width, parameters.Rows.Select(x => x.GetWidths()));
            var docxTable  = CreateTable(parameters.Width, widths);

            foreach (var row in parameters.Rows)
            {
                docxTable.AppendChild(RowConverter.Convert(row, document, table, widths));
            }
            return(docxTable);
        }
コード例 #3
0
        private static SectionProperties FillSectionProperties(WordprocessingDocument wpDocument,
                                                               SectionProperties sectionProperties,
                                                               Page page,
                                                               PageLayout defaultPageLayout,
                                                               Table defaultFooter)
        {
            var pageOrientation = page.Parameters.Orientation ?? defaultPageLayout.Orientation ?? PageOrientation.Portrait;

            var width  = (uint)OpenXmlUnits.FromMmTo20thOfPoint(page.Parameters.Size.Width);
            var height = (uint)OpenXmlUnits.FromMmTo20thOfPoint(page.Parameters.Size.Height);

            sectionProperties.AppendChild(new PageSize
            {
                Orient = ConvertOrientation(pageOrientation),
                Width  = pageOrientation == PageOrientation.Portrait ? width : height,
                Height = pageOrientation == PageOrientation.Portrait ? height : width
            });
            sectionProperties.AppendChild(new PageMargin
            {
                Left   = (uint?)GetMargin(page.Parameters.MarginLeft, defaultPageLayout.MarginLeft),
                Top    = GetMargin(page.Parameters.MarginTop, defaultPageLayout.MarginTop),
                Right  = (uint?)GetMargin(page.Parameters.MarginRight, defaultPageLayout.MarginRight),
                Bottom = GetMargin(page.Parameters.MarginBottom, defaultPageLayout.MarginBottom),
                Header = (uint?)GetMargin(page.Parameters.HeaderMargin, defaultPageLayout.HeaderMargin),
                Footer = (uint?)GetMargin(page.Parameters.FooterMargin, defaultPageLayout.FooterMargin)
            });
            if (page.Parameters.Footer != null || defaultFooter != null)
            {
                var footerPart   = wpDocument.MainDocumentPart.AddNewPart <FooterPart>();
                var footerPartId = wpDocument.MainDocumentPart.GetIdOfPart(footerPart);
                sectionProperties.AppendChild(new FooterReference {
                    Id = footerPartId, Type = HeaderFooterValues.Default
                });
                var footer = new Footer(TableConverter.Convert(page.Parameters.Footer ?? defaultFooter, wpDocument));
                footer.Save(footerPart);
            }
            return(sectionProperties);
        }
コード例 #4
0
ファイル: DocxDocument.cs プロジェクト: moayyaed/ReportDotNet
 public void SetDefaultFooter(Table table)
 {
     defaultFooter = table;
 }
コード例 #5
0
ファイル: CellConverter.cs プロジェクト: roman-g/ReportDotNet
        public static TableCell Convert(Cell cell,
                                        WordprocessingDocument document,
                                        Table table,
                                        int span)
        {
            var tableCell      = new TableCell();
            var cellProperties = new TableCellProperties();
            var parameters     = cell.Parameters;

            if (span > 1)
            {
                cellProperties.GridSpan = new GridSpan {
                    Val = span
                }
            }
            ;

            cellProperties.TableCellVerticalAlignment = new TableCellVerticalAlignment
            {
                Val = GetVerticalAlignment(parameters.VerticalAlignment ?? VerticalAlignment.Bottom)
            };

            cellProperties.TableCellMargin = GetMargin(parameters.MarginLeft ?? table.Parameters.CellMarginLeft,
                                                       parameters.MarginRight ?? table.Parameters.CellMarginRight,
                                                       parameters.MarginTop ?? table.Parameters.CellMarginTop,
                                                       parameters.MarginBottom ?? table.Parameters.CellMarginBottom);

            if (parameters.MergeDown)
            {
                cellProperties.VerticalMerge = new VerticalMerge {
                    Val = MergedCellValues.Restart
                }
            }
            ;
            else if (parameters.MergeUp)
            {
                cellProperties.VerticalMerge = new VerticalMerge();
            }

            var borders = parameters.Borders ?? table.Parameters.Borders ?? Borders.None;

            if (borders != Borders.None)
            {
                cellProperties.TableCellBorders = new TableCellBorders
                {
                    BottomBorder = borders.HasFlag(Borders.Bottom)
                                                                         ? GetBorder <BottomBorder>(parameters.BottomBorderStyle, parameters.BorderSize)
                                                                         : null,
                    LeftBorder = borders.HasFlag(Borders.Left)
                                                                       ? GetBorder <LeftBorder>(parameters.LeftBorderStyle, parameters.BorderSize)
                                                                       : null,
                    TopBorder = borders.HasFlag(Borders.Top)
                                                                      ? GetBorder <TopBorder>(parameters.TopBorderStyle, parameters.BorderSize)
                                                                      : null,
                    RightBorder = borders.HasFlag(Borders.Right)
                                                                        ? GetBorder <RightBorder>(parameters.RightBorderStyle, parameters.BorderSize)
                                                                        : null
                }
            }
            ;

            if (parameters.TextDirection.HasValue)
            {
                cellProperties.TextDirection = new DocumentFormat.OpenXml.Wordprocessing.TextDirection {
                    Val = ConvertTextDirection(parameters.TextDirection.Value)
                }
            }
            ;

            if (parameters.BackgroundColor.HasValue)
            {
                cellProperties.Shading = new Shading
                {
                    Color = parameters.BackgroundColor.Value.ToHex(),
                    Fill  = "auto",
                    Val   = ShadingPatternValues.Solid
                }
            }
            ;

            tableCell.AppendChild(ParagraphConverter.Convert(parameters.Paragraph, document, table.Parameters.FontSize));

            tableCell.TableCellProperties = cellProperties;
            return(tableCell);
        }