コード例 #1
0
        private void WriteColums(SheetData sheetData, int tableIndex)
        {
            Row row = new Row()
            {
                RowIndex = 1
            };

            sheetData.Append(row);

            foreach (DataColumn column in ds.Tables[tableIndex].Columns)
            {
                RunProperties runProperties = new RunProperties();
                runProperties.Append(new Bold());
                runProperties.Append(new Color()
                {
                    Rgb = "aaaaaa"
                });
                runProperties.Append(new FontSize()
                {
                    Val = 20
                });

                Cell cell = CreateTextCell(ds.Tables[tableIndex].Columns.IndexOf(column) + 1, 1, column.ColumnName, runProperties);
                row.AppendChild(cell);
            }
        }
コード例 #2
0
        private static Run GetRun(IXLRichString rt)
        {
            var run = new Run();

            var runProperties = new RunProperties();

            var bold = rt.Bold ? new Bold() : null;
            var italic = rt.Italic ? new Italic() : null;
            var underline = rt.Underline != XLFontUnderlineValues.None
                ? new Underline {Val = rt.Underline.ToOpenXml()}
                : null;
            var strike = rt.Strikethrough ? new Strike() : null;
            var verticalAlignment = new VerticalTextAlignment
            {Val = rt.VerticalAlignment.ToOpenXml()};
            var shadow = rt.Shadow ? new Shadow() : null;
            var fontSize = new FontSize {Val = rt.FontSize};
            var color = GetNewColor(rt.FontColor);
            var fontName = new RunFont {Val = rt.FontName};
            var fontFamilyNumbering = new FontFamily {Val = (Int32)rt.FontFamilyNumbering};

            if (bold != null) runProperties.Append(bold);
            if (italic != null) runProperties.Append(italic);

            if (strike != null) runProperties.Append(strike);
            if (shadow != null) runProperties.Append(shadow);
            if (underline != null) runProperties.Append(underline);
            runProperties.Append(verticalAlignment);

            runProperties.Append(fontSize);
            runProperties.Append(color);
            runProperties.Append(fontName);
            runProperties.Append(fontFamilyNumbering);

            var text = new Text {Text = rt.Text};
            if (rt.Text.PreserveSpaces())
                text.Space = SpaceProcessingModeValues.Preserve;

            run.Append(runProperties);
            run.Append(text);
            return run;
        }
コード例 #3
0
        /// <summary>
        ///     Append given text with a given font style.
        /// </summary>
        /// <param name="Text">The text.</param>
        /// <param name="TextFont">The font style.</param>
        public void AppendText(string Text, SLFont TextFont)
        {
            var run      = new Run();
            var runprops = new RunProperties();

            if (TextFont.FontName != null)
            {
                runprops.Append(new RunFont {
                    Val = TextFont.FontName
                });
            }

            if (TextFont.CharacterSet != null)
            {
                runprops.Append(new RunPropertyCharSet {
                    Val = TextFont.CharacterSet.Value
                });
            }

            if (TextFont.FontFamily != null)
            {
                runprops.Append(new FontFamily {
                    Val = TextFont.FontFamily.Value
                });
            }

            if (TextFont.Bold != null)
            {
                runprops.Append(new Bold {
                    Val = TextFont.Bold.Value
                });
            }

            if (TextFont.Italic != null)
            {
                runprops.Append(new Italic {
                    Val = TextFont.Italic.Value
                });
            }

            if (TextFont.Strike != null)
            {
                runprops.Append(new Strike {
                    Val = TextFont.Strike.Value
                });
            }

            if (TextFont.Outline != null)
            {
                runprops.Append(new Outline {
                    Val = TextFont.Outline.Value
                });
            }

            if (TextFont.Shadow != null)
            {
                runprops.Append(new Shadow {
                    Val = TextFont.Shadow.Value
                });
            }

            if (TextFont.Condense != null)
            {
                runprops.Append(new Condense {
                    Val = TextFont.Condense.Value
                });
            }

            if (TextFont.Extend != null)
            {
                runprops.Append(new Extend {
                    Val = TextFont.Extend.Value
                });
            }

            if (TextFont.HasFontColor)
            {
                runprops.Append(TextFont.clrFontColor.ToSpreadsheetColor());
            }

            if (TextFont.FontSize != null)
            {
                runprops.Append(new FontSize {
                    Val = TextFont.FontSize.Value
                });
            }

            if (TextFont.HasUnderline)
            {
                runprops.Append(new Underline {
                    Val = TextFont.Underline
                });
            }

            if (TextFont.HasVerticalAlignment)
            {
                runprops.Append(new VerticalTextAlignment {
                    Val = TextFont.VerticalAlignment
                });
            }

            if (TextFont.HasFontScheme)
            {
                runprops.Append(new FontScheme {
                    Val = TextFont.FontScheme
                });
            }

            if (runprops.ChildElements.Count > 0)
            {
                run.Append(runprops);
            }

            run.Text      = new Text();
            run.Text.Text = Text;
            if (SLTool.ToPreserveSpace(Text))
            {
                run.Text.Space = SpaceProcessingModeValues.Preserve;
            }

            var bFound = false;
            var oxe    = istrReal.FirstChild;

            foreach (var child in istrReal.ChildElements)
            {
                if (child is Text || child is Run)
                {
                    oxe    = child;
                    bFound = true;
                }
            }

            if (bFound)
            {
                istrReal.InsertAfter(run, oxe);
            }
            else
            {
                istrReal.PrependChild(run);
            }
        }