예제 #1
0
        private void ProcessTableCellMargin(DocxTableProperties docxProperties, TableProperties tableProperties)
        {
            if (docxProperties.CellPadding != null)
            {
                TableCellMarginDefault cellMargin = new TableCellMarginDefault();
                Int16 width = (Int16)DocxUnits.GetDxaFromPixel(docxProperties.CellPadding.Value);

                cellMargin.TableCellLeftMargin = new TableCellLeftMargin()
                {
                    Width = width,
                    Type  = TableWidthValues.Dxa
                };

                cellMargin.TopMargin = new TopMargin()
                {
                    Width = width.ToString(),
                    Type  = TableWidthUnitValues.Dxa
                };

                cellMargin.TableCellRightMargin = new TableCellRightMargin()
                {
                    Width = width,
                    Type  = TableWidthValues.Dxa
                };

                cellMargin.BottomMargin = new BottomMargin()
                {
                    Width = width.ToString(),
                    Type  = TableWidthUnitValues.Dxa
                };

                tableProperties.Append(cellMargin);
            }
        }
예제 #2
0
        private void ProcessWidth(DocxNode node, TableProperties tableProperties)
        {
            string width      = node.ExtractAttributeValue(DocxUnits.width);
            string styleWidth = node.ExtractStyleValue(DocxUnits.width);

            if (!string.IsNullOrEmpty(styleWidth))
            {
                width = styleWidth;
            }

            if (!string.IsNullOrEmpty(width))
            {
                decimal value;
                TableWidthUnitValues unit;

                if (DocxUnits.TableUnitsFromStyle(width, out value, out unit))
                {
                    TableWidth tableWidth = new TableWidth()
                    {
                        Width = value.ToString(),
                        Type  = unit
                    };
                    tableProperties.Append(tableWidth);
                }
            }
        }
예제 #3
0
        internal static void SetBottomMargin(string style, ParagraphProperties properties)
        {
            decimal dxa = DocxUnits.GetDxaFromStyle(style);

            if (dxa != -1)
            {
                SpacingBetweenLines spacing = new SpacingBetweenLines();

                spacing.After = dxa.ToString();
                properties.Append(spacing);
            }
        }
예제 #4
0
        internal static void ApplyFontSize(string style, OpenXmlElement styleElement)
        {
            decimal fontSize = DocxUnits.HalfPointFromStyle(style);

            if (fontSize != 0)
            {
                fontSize = decimal.Round(fontSize);
                styleElement.Append(new FontSize()
                {
                    Val = fontSize.ToString("N0")
                });
            }
        }
예제 #5
0
        internal void Process(TableRow row, DocxTableProperties docxProperties)
        {
            TableRowProperties trProperties = new TableRowProperties();

            if (docxProperties.CellSpacing != null)
            {
                trProperties.Append(new TableCellSpacing()
                {
                    Width = DocxUnits.GetDxaFromPixel(docxProperties.CellSpacing.Value).ToString(),
                    Type  = TableWidthUnitValues.Dxa
                });
            }

            if (trProperties.ChildElements.Count > 0)
            {
                row.Append(trProperties);
            }
        }
        private void ProcessWidth(DocxNode node, TableCellProperties cellProperties)
        {
            string width = node.ExtractStyleValue(DocxUnits.width);

            if (!string.IsNullOrEmpty(width))
            {
                if (DocxUnits.TableUnitsFromStyle(width, out decimal value, out TableWidthUnitValues unit))
                {
                    TableCellWidth cellWidth = new TableCellWidth()
                    {
                        Width = value.ToString(),
                        Type  = unit
                    };

                    cellProperties.Append(cellWidth);
                }
            }
        }
예제 #7
0
        internal void ProcessParagraphMargin(ParagraphProperties properties)
        {
            string topMargin    = GetTopMargin();
            string bottomMargin = GetBottomMargin();
            string leftMargin   = GetLeftMargin();
            string rightMargin  = GetRightMargin();
            string line         = node.ExtractStyleValue(lineHeight);

            if (!string.IsNullOrEmpty(topMargin) || !string.IsNullOrEmpty(bottomMargin) || !string.IsNullOrEmpty(line))
            {
                SpacingBetweenLines spacing = new SpacingBetweenLines();

                if (!string.IsNullOrEmpty(topMargin))
                {
                    decimal dxa = DocxUnits.GetDxaFromStyle(topMargin);

                    if (dxa != -1)
                    {
                        spacing.Before = dxa.ToString();
                    }
                }

                if (!string.IsNullOrEmpty(bottomMargin))
                {
                    decimal dxa = DocxUnits.GetDxaFromStyle(bottomMargin);

                    if (dxa != -1)
                    {
                        spacing.After = decimal.Round(dxa).ToString();
                    }
                }

                if (!string.IsNullOrEmpty(line) && !line.CompareStringOrdinalIgnoreCase(DocxFontStyle.normal))
                {
                    decimal number;
                    decimal dxa = -1;
                    LineSpacingRuleValues lineSpacingRuleValues = LineSpacingRuleValues.AtLeast;

                    if (decimal.TryParse(line, out number))
                    {
                        dxa = DocxUnits.GetDxaFromNumber(number);
                        dxa = dxa - defaultLineHeight;//Removing the default line height
                    }
                    else if (line.Contains("%"))
                    {
                        line = line.Replace("%", string.Empty);

                        if (decimal.TryParse(line, out number))
                        {
                            dxa = (number / 100) * DocxFontStyle.defaultFontSizeInPixel;
                            dxa = dxa - defaultLineHeight;//Removing the default line height
                        }
                    }
                    else
                    {
                        dxa = DocxUnits.GetDxaFromStyle(line);
                        //lineSpacingRuleValues = LineSpacingRuleValues.Exact;
                    }

                    dxa = decimal.Round(dxa);

                    if (dxa > 0)
                    {
                        spacing.LineRule = lineSpacingRuleValues;
                        spacing.Line     = dxa.ToString();
                    }
                }

                if (spacing.HasAttributes)
                {
                    properties.Append(spacing);
                }
            }

            if (!string.IsNullOrEmpty(leftMargin) || !string.IsNullOrEmpty(rightMargin))
            {
                Indentation ind = new Indentation();

                if (!string.IsNullOrEmpty(leftMargin))
                {
                    decimal dxa = DocxUnits.GetDxaFromStyle(leftMargin);

                    if (dxa != -1)
                    {
                        ind.Left = dxa.ToString();
                    }
                }

                if (!string.IsNullOrEmpty(rightMargin))
                {
                    decimal dxa = DocxUnits.GetDxaFromStyle(rightMargin);

                    if (dxa != -1)
                    {
                        ind.Right = dxa.ToString();
                    }
                }

                if (ind.HasAttributes)
                {
                    properties.Append(ind);
                }
            }
        }