private static Border GetNewBorder(BorderInfo borderInfo, Boolean ignoreMod = true)
        {
            var border = new Border();
            if (borderInfo.Border.DiagonalUpModified || ignoreMod)
                border.DiagonalUp = borderInfo.Border.DiagonalUp;

            if (borderInfo.Border.DiagonalDownModified || ignoreMod)
                border.DiagonalDown = borderInfo.Border.DiagonalDown;

            if (borderInfo.Border.LeftBorderModified || borderInfo.Border.LeftBorderColorModified || ignoreMod)
            {
                var leftBorder = new LeftBorder {Style = borderInfo.Border.LeftBorder.ToOpenXml()};
                if (borderInfo.Border.LeftBorderColorModified || ignoreMod)
                {
                    var leftBorderColor = GetNewColor(borderInfo.Border.LeftBorderColor);
                    leftBorder.AppendChild(leftBorderColor);
                }
                border.AppendChild(leftBorder);
            }

            if (borderInfo.Border.RightBorderModified || borderInfo.Border.RightBorderColorModified || ignoreMod)
            {
                var rightBorder = new RightBorder {Style = borderInfo.Border.RightBorder.ToOpenXml()};
                if (borderInfo.Border.RightBorderColorModified || ignoreMod)
                {
                    var rightBorderColor = GetNewColor(borderInfo.Border.RightBorderColor);
                    rightBorder.AppendChild(rightBorderColor);
                }
                border.AppendChild(rightBorder);
            }

            if (borderInfo.Border.TopBorderModified || borderInfo.Border.TopBorderColorModified || ignoreMod)
            {
                var topBorder = new TopBorder {Style = borderInfo.Border.TopBorder.ToOpenXml()};
                if (borderInfo.Border.TopBorderColorModified || ignoreMod)
                {
                    var topBorderColor = GetNewColor(borderInfo.Border.TopBorderColor);
                    topBorder.AppendChild(topBorderColor);
                }
                border.AppendChild(topBorder);
            }

            if (borderInfo.Border.BottomBorderModified || borderInfo.Border.BottomBorderColorModified || ignoreMod)
            {
                var bottomBorder = new BottomBorder {Style = borderInfo.Border.BottomBorder.ToOpenXml()};
                if (borderInfo.Border.BottomBorderColorModified || ignoreMod)
                {
                    var bottomBorderColor = GetNewColor(borderInfo.Border.BottomBorderColor);
                    bottomBorder.AppendChild(bottomBorderColor);
                }
                border.AppendChild(bottomBorder);
            }

            if (borderInfo.Border.DiagonalBorderModified || borderInfo.Border.DiagonalBorderColorModified || ignoreMod)
            {
                var DiagonalBorder = new DiagonalBorder {Style = borderInfo.Border.DiagonalBorder.ToOpenXml()};
                if (borderInfo.Border.DiagonalBorderColorModified || ignoreMod)
                {
                    var DiagonalBorderColor = GetNewColor(borderInfo.Border.DiagonalBorderColor);
                    DiagonalBorder.AppendChild(DiagonalBorderColor);
                }
                border.AppendChild(DiagonalBorder);
            }

            return border;
        }
Ejemplo n.º 2
0
        private static void Build(Window window)
        {
            Border border = new Border();

            window.AppendChild(border);

            StackPanel panel = new StackPanel();

            border.AppendChild(panel);
            panel.Orientation = Orientation.Vertical;
            panel.Overlap     = true;

            Border header = new Border();

            header.Height = 10;
            panel.AppendChild(header);

            StackPanel menu = new StackPanel();

            menu.Id          = "menu";
            menu.Orientation = Orientation.Horizontal;
            menu.Overlap     = true;
            panel.AppendChild(menu);

            Border left = new Border();

            left.Width   = 30;
            left.Padding = new ThicknessRectangle(1);
            menu.AppendChild(left);

            Border middle = new Border();

            middle.Parent  = menu;
            middle.Padding = new ThicknessRectangle(5);

            Border right = new Border();

            right.Width   = 20;
            right.Parent  = menu;
            right.Padding = new ThicknessRectangle(1);

            TextBlock block = new TextBlock();

            block.Text   = text;
            block.Parent = left;
            block.Id     = "left";

            TextBlock block2 = new TextBlock();

            block2.Text   = longtext;
            block2.Parent = middle;
            block2.Id     = "mid";

            Button but = new Button();

            but.Parent = right;
            but.Text   = "ClickMe!";
            but.Width  = 8;
            but.Click += (sender) =>
            {
                Application.StopUI();
            };
        }
        private void AddBordersToCellFormat(ExcelCellStyle item, CellFormat cellFormat)
        {
            if (item.Borders != null && item.Borders.Count > 0)
            {
                var border = new Border();
                foreach (var borderItem in item.Borders)
                {
                    var color = new Color();
                    if (borderItem.Color is null)
                    {
                        color.Auto = true;
                    }
                    else
                    {
                        color.Rgb = borderItem.Color.ColorHexCode;
                    }

                    switch (borderItem.Border)
                    {
                    case ExcelCellBorderEnum.None:
                        break;

                    case ExcelCellBorderEnum.Left:
                        border.AppendChild(new LeftBorder {
                            Color = color, Style = (BorderStyleValues)(int)borderItem.Style
                        });
                        break;

                    case ExcelCellBorderEnum.Right:
                        border.AppendChild(new RightBorder {
                            Color = color, Style = (BorderStyleValues)(int)borderItem.Style
                        });
                        break;

                    case ExcelCellBorderEnum.Top:
                        border.AppendChild(new TopBorder {
                            Color = color, Style = (BorderStyleValues)(int)borderItem.Style
                        });
                        break;

                    case ExcelCellBorderEnum.Bottom:
                        border.AppendChild(new BottomBorder {
                            Color = color, Style = (BorderStyleValues)(int)borderItem.Style
                        });
                        break;

                    case ExcelCellBorderEnum.Diagonal:
                        border.AppendChild(new DiagonalBorder {
                            Color = color, Style = (BorderStyleValues)(int)borderItem.Style
                        });
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                cellFormat.BorderId    = GetElementIndexOrAdd(this.borders, border);
                cellFormat.ApplyBorder = true;
            }
        }
Ejemplo n.º 4
0
        public SpreadsheetStylesManager(WorkbookPart workbookPart)
        {
            _workbookPart = workbookPart;
            _styles       = new Dictionary <string, int>();
            _fonts        = new Dictionary <FontKey, int>();
            _fills        = new Dictionary <System.Drawing.Color, int>();

            var stylesPart = _workbookPart.AddNewPart <WorkbookStylesPart>();

            _stylesheet           = new Stylesheet();
            stylesPart.Stylesheet = _stylesheet;

            _stylesheet.Fills = new Fills();
            _stylesheet.Fills.AppendChild(new Fill {
                PatternFill = new PatternFill {
                    PatternType = PatternValues.None
                }
            });                                                                                                             // required, reserved by Excel
            _stylesheet.Fills.AppendChild(new Fill {
                PatternFill = new PatternFill {
                    PatternType = PatternValues.Gray125
                }
            });                                                                                                                // required, reserved by Excel
            _stylesheet.Fills.Count = 2;

            stylesPart.Stylesheet.Fonts       = new Fonts();
            stylesPart.Stylesheet.Fonts.Count = 2;
            stylesPart.Stylesheet.Fonts.AppendChild(new Font());

            Font      hyperLinkFont = new Font();
            Underline underline1    = new Underline();
            FontSize  fontSize2     = new FontSize()
            {
                Val = 11D
            };
            Color color2 = new Color()
            {
                Theme = (UInt32Value)10U
            };
            FontName fontName2 = new FontName()
            {
                Val = "Calibri"
            };
            FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering()
            {
                Val = 2
            };
            FontCharSet fontCharSet2 = new FontCharSet()
            {
                Val = 238
            };
            FontScheme fontScheme2 = new FontScheme()
            {
                Val = FontSchemeValues.Minor
            };

            hyperLinkFont.Append(underline1);
            hyperLinkFont.Append(fontSize2);
            hyperLinkFont.Append(color2);
            hyperLinkFont.Append(fontName2);
            hyperLinkFont.Append(fontFamilyNumbering2);
            hyperLinkFont.Append(fontCharSet2);
            hyperLinkFont.Append(fontScheme2);
            stylesPart.Stylesheet.Fonts.AppendChild(hyperLinkFont);

            stylesPart.Stylesheet.Borders       = new Borders();
            stylesPart.Stylesheet.Borders.Count = 1;
            stylesPart.Stylesheet.Borders.AppendChild(new Border());

            stylesPart.Stylesheet.CellStyleFormats       = new CellStyleFormats();
            stylesPart.Stylesheet.CellStyleFormats.Count = 2;
            stylesPart.Stylesheet.CellStyleFormats.AppendChild(new CellFormat());

            stylesPart.Stylesheet.CellFormats = new CellFormats();
            // empty one for index 0, seems to be required
            stylesPart.Stylesheet.CellFormats.AppendChild(new CellFormat());
            CellFormat hyperLinkFormt = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, ApplyNumberFormat = false, ApplyFill = false, ApplyBorder = false, ApplyAlignment = false, ApplyProtection = false
            };

            stylesPart.Stylesheet.CellFormats.AppendChild(hyperLinkFormt);
            stylesPart.Stylesheet.CellFormats.Count = 2;
            _hyperlinkStyles[new SpreadsheetStyle().GetIdentifier()] = 1;


            Borders borders = new Borders()
            {
                Count = (UInt32Value)1U
            };
            Border         border         = new Border();
            LeftBorder     leftBorder     = new LeftBorder();
            RightBorder    rightBorder    = new RightBorder();
            TopBorder      topBorder      = new TopBorder();
            BottomBorder   bottomBorder   = new BottomBorder();
            DiagonalBorder diagonalBorder = new DiagonalBorder();

            border.AppendChild(leftBorder);
            border.AppendChild(rightBorder);
            border.AppendChild(topBorder);
            border.AppendChild(bottomBorder);
            border.AppendChild(diagonalBorder);
            borders.AppendChild(border);

            _stylesheet.Borders = borders;

            CellStyles cellStyles = new CellStyles()
            {
                Count = (UInt32Value)1U
            };
            CellStyle cellStyle = new CellStyle()
            {
                Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U
            };

            cellStyles.AppendChild(cellStyle);
            _stylesheet.CellStyles = cellStyles;

            var dateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo;
            var dateTimeFormat     = "d.mm.yyyy hh:mm:ss";

            if (dateTimeFormatInfo != null)
            {
                dateTimeFormat = dateTimeFormatInfo.ShortDatePattern + " " + dateTimeFormatInfo.LongTimePattern;
                dateTimeFormat = dateTimeFormat.Replace("/", "\\/");
                dateTimeFormat = dateTimeFormat.Replace("tt", "AM/PM");
            }
            NumberingFormats numberingFormats = new NumberingFormats()
            {
                Count = (UInt32Value)1U
            };
            NumberingFormat numberingFormat1 = new NumberingFormat()
            {
                NumberFormatId = (UInt32Value)164U, FormatCode = dateTimeFormat
            };

            numberingFormats.Append(numberingFormat1);

            _stylesheet.NumberingFormats = numberingFormats;
        }