public static Paragraph GetParagraph(string text, Fonts type, int align = Element.ALIGN_LEFT)
        {
            Paragraph p;
            switch (type)
            {
                case Fonts.Footer:
                    p = new Paragraph(text, FooterFont);
                    break;

                case Fonts.ExtraLarge:
                    p = new Paragraph(text, ExtraLargeFont);
                    break;

                case Fonts.Large:
                    p = new Paragraph(text);
                    break;

                case Fonts.Compact:
                    p = new Paragraph(text, StandardFont);
                    p.SetLeading(0, 0.8f);
                    break;

                case Fonts.Standard:
                    p = new Paragraph(text, StandardFont);
                    break;

                default: throw new ArgumentOutOfRangeException("type");
            }

            p.Alignment = align;

            return p;
        }
        protected override void GetGlyphPosImpl(ActualFont actualFont, char[] buffer,
            int startAt, int len,
            Fonts.ProperGlyph[] properGlyphs)
        {
            NativeFont nativeFont = actualFont as NativeFont;
            if (nativeFont == null)
            {
                nativeFont = ResolveForNativeFont(actualFont);
            }

            unsafe
            {
                fixed (ProperGlyph* propGlyphH = &properGlyphs[0])
                fixed (char* head = &buffer[0])
                {
                    //we use font shaping engine here
                    NativeMyFontsLib.MyFtShaping(
                       nativeFont.NativeFontFace.HBFont,
                        head,
                        buffer.Length,
                        propGlyphH);
                }
            }

        }
Example #3
0
 public static void Render(Fonts font, string text, Vector2 position, Color color, float scale)
 {
     if (_useDefaultFont)
         Engine.SpriteBatch.DrawString(_default, text, position, Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
     else
         _fonts[(int)font].DrawString(text, position, color, scale);
 }
Example #4
0
    public LedMatrix(string _address)
    {
        address = _address;

        font = new Fonts();
        RED = new byte[128];
        GREEN = new byte[128];
        led_columns_red = new UInt16[max_line_length];
        led_columns_green = new UInt16[max_line_length];
        led_columns_red_out = new UInt16[max_line_length];
        led_columns_green_out = new UInt16[max_line_length];
        shift_auto_enabled = false;
        line_lengths = new int[2];

        connected_before = false;
        shift_position = 0;
        x = 0;
        y = 1;
        scroll_speed = 10;
        artist = "";
        title = "";

        remoteEndPoint = new IPEndPoint(IPAddress.Parse(address), 9328);
        client = new UdpClient();
        client.Client.ReceiveTimeout = 1000; // 1s timeout -> receive blocks 5s
    }
Example #5
0
 public static void Render(Fonts font, string text, Vector2 position, Color color)
 {
     if (_useDefaultFont)
         Engine.SpriteBatch.DrawString(_default, text, position, Color.Black);
     else
         _fonts[(int)font].DrawString(text, position, color, 1);
 }
Example #6
0
 public FontTablePart AddFontTablePartToPackage(WordprocessingDocument doc)
 {
     var part = doc.MainDocumentPart.AddNewPart<FontTablePart>();
     var root = new Fonts();
     root.Save(part);
     return part;
 }
Example #7
0
        public CustomStylesheet()
        {
            // blank font list
            var fonts = new Fonts();
            fonts.AppendChild(new Font());
            fonts.Count = 1;
            Append(fonts);

            // create fills
            var fills = new Fills();

            // create a solid blue fill
            var solidBlue = new PatternFill() { PatternType = PatternValues.Solid };
            solidBlue.ForegroundColor = new ForegroundColor { Rgb = HexBinaryValue.FromString("397FDB") }; // blue fill
            solidBlue.BackgroundColor = new BackgroundColor { Indexed = 64 };

            fills.AppendChild(new Fill { PatternFill = new PatternFill { PatternType = PatternValues.None } }); // required, reserved by Excel
            fills.AppendChild(new Fill { PatternFill = new PatternFill { PatternType = PatternValues.Gray125 } }); // required, reserved by Excel
            fills.AppendChild(new Fill { PatternFill = solidBlue });
            fills.Count = 3;
            Append(fills);

            // blank border list
            var borders = new Borders();
            borders.AppendChild(new Border());
            borders.AppendChild(new Border()
            {
                TopBorder = new TopBorder() { Style = BorderStyleValues.Thin },
                RightBorder = new RightBorder() { Style = BorderStyleValues.Thin },
                BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin },
                LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }
            });
            borders.Count = 2;
            Append(borders);

            // blank cell format list
            var cellStyleFormats = new CellStyleFormats();
            cellStyleFormats.AppendChild(new CellFormat());
            cellStyleFormats.Count = 1;
            Append(cellStyleFormats);

            // cell format list
            var cellFormats = new CellFormats();
            // empty one for index 0, seems to be required
            cellFormats.AppendChild(new CellFormat());
            // cell format default with border
            cellFormats.AppendChild(new CellFormat() { FormatId = 0, FontId = 0, BorderId = 1, FillId = 0 }).AppendChild(new Alignment() { WrapText = true });
            // cell format for header (blue with border)
            cellFormats.AppendChild(new CellFormat { FormatId = 0, FontId = 0, BorderId = 1, FillId = 2, ApplyFill = true }).AppendChild(new Alignment { Horizontal = HorizontalAlignmentValues.Center });
            cellFormats.Count = 2;
            Append(cellFormats);
        }
 public static PdfPCell CreateCell(string str, int align = Element.ALIGN_CENTER, float fixedHeight = -1, BaseColor borderColor = null, int colSpan = 1, Fonts font = Fonts.Standard)
 {
     var c = new PdfPCell(GetPhrase(str, font))
     {
         HorizontalAlignment = align,
         VerticalAlignment = Element.ALIGN_TOP,
         Padding = 5,
         BorderColor = borderColor ?? BaseColor.BLACK,
         Colspan = colSpan
     };
     if (fixedHeight > 0)
     {
         c.FixedHeight = fixedHeight;
     }
     c.PaddingTop = 2;
     return c;
 }
        void Init()
        {
            DynamicLayout p1, p2;

            StackLayout t1;

            p1 = UI.Shared.Common.GetDefaultContainer();
            p2 = UI.Shared.Common.GetDefaultContainer();

            p1.Width = 380;
            p2.Width = 380;

            t1 = new StackLayout();
            t1.Items.Add(new StackLayoutItem(p1));
            t1.Items.Add(new StackLayoutItem(p2));
            t1.Orientation = Orientation.Horizontal;

            Padding = new Padding(10);

            if (flowsheet.SensAnalysisCollection.Count == 0)
            {
                flowsheet.SensAnalysisCollection.Add(new DWSIM.SharedClasses.Flowsheet.Optimization.SensitivityAnalysisCase());
            }

            mycase = flowsheet.SensAnalysisCollection.First();

            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            s.CreateAndAddLabelRow2(this, "Use the Sensitivity Analysis tool to study/analyze the influence of a process variable on other variables in the flowsheet.");

            this.Add(t1);

            s.CreateAndAddLabelRow(p1, "Case ID");
            s.CreateAndAddFullTextBoxRow(p1, mycase.name, (arg3, arg2) => { mycase.name = arg3.Text; });

            s.CreateAndAddLabelRow(p1, "Case Description");
            s.CreateAndAddFullTextBoxRow(p1, mycase.description, (arg3, arg2) => { mycase.description = arg3.Text; });

            s.CreateAndAddLabelRow(p1, "Independent Variable");

            var objlist = flowsheet.SimulationObjects.Values.Select((x2) => x2.GraphicObject.Tag).ToList();

            objlist.Insert(0, "");

            var spinner = s.CreateAndAddDropDownRow(p1, "Object", objlist, 0, null);

            var spinner2 = s.CreateAndAddDropDownRow(p1, "Property", new List <string>(), 0, null);

            List <string> proplist = new List <string>();

            spinner.SelectedIndexChanged += (sender, e) =>
            {
                if (spinner.SelectedIndex > 0)
                {
                    mycase.iv1.objectID  = flowsheet.GetFlowsheetSimulationObject(objlist[spinner.SelectedIndex]).Name;
                    mycase.iv1.objectTAG = objlist[spinner.SelectedIndex];
                    proplist             = flowsheet.GetFlowsheetSimulationObject(objlist[spinner.SelectedIndex]).GetProperties(PropertyType.WR).ToList();
                    proplist.Insert(0, "");
                    spinner2.Items.Clear();
                    spinner2.Items.AddRange(proplist.Select(x => new ListItem {
                        Key = x, Text = flowsheet.GetTranslatedString(x)
                    }).ToList());
                    spinner2.SelectedIndex = (proplist.IndexOf(mycase.iv1.propID));
                }
                else
                {
                    spinner2.Items.Clear();
                }
            };
            if (flowsheet.SimulationObjects.ContainsKey(mycase.iv1.objectID))
            {
                spinner.SelectedIndex = (objlist.IndexOf(flowsheet.SimulationObjects[mycase.iv1.objectID].GraphicObject.Tag));
            }

            var txtLowerLimit = s.CreateAndAddTextBoxRow(p1, nf, "Initial Value", 0, null);
            var txtUpperLimit = s.CreateAndAddTextBoxRow(p1, nf, "Final Value", 0, null);
            var txtSteps      = s.CreateAndAddTextBoxRow(p1, "0", "Number of Steps", 0, null);

            txtLowerLimit.Text = mycase.iv1.lowerlimit.GetValueOrDefault().ToString(nf);
            txtUpperLimit.Text = mycase.iv1.upperlimit.GetValueOrDefault().ToString(nf);
            txtSteps.Text      = mycase.iv1.points.ToString();

            var labelUnits = s.CreateAndAddTwoLabelsRow(p1, "Property Units", "");

            spinner2.SelectedIndexChanged += (sender, e) =>
            {
                if (spinner2.SelectedIndex > 0)
                {
                    mycase.iv1.propID = proplist[spinner2.SelectedIndex];
                    mycase.iv1.unit   = flowsheet.GetFlowsheetSimulationObject(objlist[spinner.SelectedIndex]).GetPropertyUnit(proplist[spinner2.SelectedIndex], su);
                    labelUnits.Text   = mycase.iv1.unit;
                }
            };

            double dummy = 0.0f;

            txtLowerLimit.TextChanged += (sender2, e2) =>
            {
                if (double.TryParse(txtLowerLimit.Text.ToString(), out dummy))
                {
                    mycase.iv1.lowerlimit = Double.Parse(txtLowerLimit.Text);
                }
            };

            txtUpperLimit.TextChanged += (sender2, e2) =>
            {
                if (double.TryParse(txtUpperLimit.Text.ToString(), out dummy))
                {
                    mycase.iv1.upperlimit = Double.Parse(txtUpperLimit.Text);
                }
            };

            txtSteps.TextChanged += (sender2, e2) =>
            {
                if (double.TryParse(txtSteps.Text.ToString(), out dummy))
                {
                    mycase.iv1.points = Int32.Parse(txtSteps.Text);
                }
            };

            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);
            s.CreateAndAddEmptySpace(p1);

            var btnAddDepVar = s.CreateAndAddBoldLabelAndButtonRow(p2, "Dependent Variables", "Add New", null, null);

            var ll = new StackLayout {
                Orientation = Orientation.Vertical, Padding = new Eto.Drawing.Padding(2), Spacing = 10
            };

            ll.RemoveAll();

            var sc = new Scrollable {
                Border = BorderType.None, Content = ll
            };

            s.CreateAndAddControlRow(p2, sc);

            t1.SizeChanged += (sender, e) => {
                if (p1.ParentWindow != null)
                {
                    p1.Width  = (int)(p1.ParentWindow.Width / 2 - 10);
                    p2.Width  = (int)(p2.ParentWindow.Width / 2 - 10);
                    p1.Height = p1.ParentWindow.Height - 170;
                    p2.Height = p1.Height;
                    sc.Height = p2.Height - btnAddDepVar.Height - 30;
                    foreach (var item in ll.Items)
                    {
                        item.Control.Width = sc.Width - 25;
                    }
                }
            };

            foreach (var dvar in mycase.depvariables.Values)
            {
                AddDepVar(ll, dvar, objlist);
            }

            btnAddDepVar.Click += (sender2, e2) =>
            {
                var depvar = new DWSIM.SharedClasses.Flowsheet.Optimization.SAVariable();
                depvar.id = Guid.NewGuid().ToString();
                mycase.depvariables.Add(depvar.id, depvar);
                AddDepVar(ll, depvar, objlist);
            };

            var btnRun = s.CreateAndAddButtonRow(this, "Run Analysis", null, null);

            var btnAbort = s.CreateAndAddButtonRow(this, "Abort Run", null, null);

            btnAbort.Enabled = false;

            resulttextbox = new TextArea {
                Height = 400, Text = "", Font = Fonts.Monospace(GlobalSettings.Settings.ResultsReportFontSize), ReadOnly = true
            };

            s.CreateAndAddLabelRow(this, "Results");

            var btnrt = s.CreateAndAddLabelAndButtonRow(this, "View Results Report", "View Report", null, (sender, e) =>
            {
                var form = s.GetDefaultEditorForm("Sensitivity Analysis Report", 500, 500, resulttextbox, true);
                form.Show();
            });

            btnrt.Enabled = false;

            resultschart = new Eto.OxyPlot.Plot {
                Height = 400
            };

            var btnrc = s.CreateAndAddLabelAndButtonRow(this, "View Results Chart", "View Chart", null, (sender, e) =>
            {
                var form = s.GetDefaultEditorForm("Sensitivity Analysis Result", 500, 500, resultschart, true);
                form.Show();
            });

            btnrc.Enabled = false;

            btnRun.Click += (sender2, e2) =>
            {
                int    iv1np, i;
                double iv1ll, iv1ul, iv1val, iv1val0;
                string iv1id, iv1prop;
                List <List <double> > results = new List <List <double> >();

                iv1ll   = Converter.ConvertToSI(mycase.iv1.unit, mycase.iv1.lowerlimit.GetValueOrDefault());
                iv1ul   = Converter.ConvertToSI(mycase.iv1.unit, mycase.iv1.upperlimit.GetValueOrDefault());
                iv1np   = mycase.iv1.points - 1;
                iv1id   = mycase.iv1.objectID;
                iv1prop = mycase.iv1.propID;

                flowsheet.SupressMessages = true;

                Application.Instance.Invoke(() =>
                {
                    btnAbort.Enabled = true;
                    btnrt.Enabled    = false;
                    btnrc.Enabled    = false;
                    flowsheet.ShowMessage("Starting Sensitivity Analysis, please wait...", IFlowsheet.MessageType.Information);
                });

                var task = new Task(() =>
                {
                    flowsheet.SolveFlowsheet(true);

                    iv1val0 = Convert.ToDouble(flowsheet.SimulationObjects[iv1id].GetPropertyValue(iv1prop));

                    for (i = 0; i <= iv1np; i++)
                    {
                        iv1val = iv1ll + i * (iv1ul - iv1ll) / iv1np;
                        flowsheet.SimulationObjects[iv1id].SetPropertyValue(iv1prop, iv1val);
                        flowsheet.SolveFlowsheet(true);
                        List <double> depvarvals = new List <double>();
                        foreach (var depvar in mycase.depvariables.Values)
                        {
                            depvar.currentvalue = Convert.ToDouble(flowsheet.SimulationObjects[depvar.objectID].GetPropertyValue(depvar.propID));
                            depvarvals.Add(depvar.currentvalue);
                        }
                        results.Add(depvarvals);
                    }

                    mycase.results = new System.Collections.ArrayList();

                    foreach (var res in results)
                    {
                        mycase.results.Add(res.ToArray());
                    }

                    flowsheet.SimulationObjects[iv1id].SetPropertyValue(iv1prop, iv1val0);
                    flowsheet.SolveFlowsheet(true);
                }, GlobalSettings.Settings.TaskCancellationTokenSource.Token);

                task.ContinueWith((t) =>
                {
                    flowsheet.SupressMessages = false;

                    if (t.Exception != null)
                    {
                        Application.Instance.Invoke(() =>
                        {
                            btnAbort.Enabled = false;
                            btnrt.Enabled    = false;
                            btnrc.Enabled    = false;

                            flowsheet.ShowMessage("Error: " + t.Exception.Message, IFlowsheet.MessageType.GeneralError);
                        });
                    }
                    else
                    {
                        Application.Instance.Invoke(() =>
                        {
                            btnAbort.Enabled = false;
                            btnrt.Enabled    = true;
                            btnrc.Enabled    = true;

                            flowsheet.ShowMessage("Sensitivity Analysis finished successfully.", IFlowsheet.MessageType.Information);
                            if (t.Status == TaskStatus.RanToCompletion)
                            {
                                var str = new System.Text.StringBuilder();
                                str.AppendLine("Sensitivity Analysis Run Results");
                                str.AppendLine();
                                str.AppendLine("Independent Variable: " + flowsheet.SimulationObjects[iv1id].GraphicObject.Tag + " / " + flowsheet.GetTranslatedString(mycase.iv1.propID));
                                str.AppendLine();
                                str.AppendLine("Range: " + mycase.iv1.lowerlimit.GetValueOrDefault() + " to " + mycase.iv1.upperlimit.GetValueOrDefault() + " " + mycase.iv1.unit + ", " + mycase.iv1.points + " steps");
                                str.AppendLine();
                                str.AppendLine("Dependent Variables:");
                                int count = 1;
                                str.AppendLine();
                                foreach (var dvar in mycase.depvariables.Values)
                                {
                                    str.AppendLine(count + " - " + flowsheet.SimulationObjects[dvar.objectID].GraphicObject.Tag + " / " + flowsheet.GetTranslatedString(dvar.propID) + " (" + dvar.unit + ")");
                                    count += 1;
                                }
                                str.AppendLine();
                                str.AppendLine("Ind var\t\tDep. vars");
                                int cnt                  = 0;
                                List <double> px         = new List <double>();
                                List <List <double> > py = new List <List <double> >();
                                foreach (var dvar in mycase.depvariables.Values)
                                {
                                    py.Add(new List <double>());
                                }
                                foreach (double[] res in mycase.results)
                                {
                                    var dv = Converter.ConvertFromSI(mycase.iv1.unit, iv1ll + cnt * (iv1ul - iv1ll) / iv1np);
                                    px.Add(dv);
                                    string line = dv.ToString(nf) + "\t\t";
                                    int j       = 0;
                                    foreach (var d in res)
                                    {
                                        py[j].Add(Converter.ConvertFromSI(mycase.depvariables.Values.ElementAt(j).unit, d));
                                        line += Converter.ConvertFromSI(mycase.depvariables.Values.ElementAt(j).unit, d).ToString(nf) + "\t\t";
                                        j    += 1;
                                    }
                                    str.AppendLine(line);
                                    cnt += 1;
                                }

                                Application.Instance.Invoke(() => resulttextbox.Text = str.ToString());

                                var model = new PlotModel()
                                {
                                    Subtitle = "Sensitivity Analysis Run Results", Title = flowsheet.FlowsheetOptions.SimulationName
                                };
                                model.TitleFontSize    = 14;
                                model.SubtitleFontSize = 11;
                                model.Axes.Add(new LinearAxis()
                                {
                                    MajorGridlineStyle = LineStyle.Dash,
                                    MinorGridlineStyle = LineStyle.Dot,
                                    Position           = AxisPosition.Bottom,
                                    FontSize           = 12,
                                    Title = mycase.iv1.objectTAG + " / " + flowsheet.GetTranslatedString(mycase.iv1.propID) + " (" + mycase.iv1.unit + ")"
                                });
                                int cnt2 = 0;
                                foreach (var dvar in mycase.depvariables.Values)
                                {
                                    model.Axes.Add(new LinearAxis()
                                    {
                                        MajorGridlineStyle = LineStyle.Dash,
                                        MinorGridlineStyle = LineStyle.Dot,
                                        FontSize           = 12,
                                        Title = dvar.objectTAG + " / " + flowsheet.GetTranslatedString(dvar.propID) + " (" + dvar.unit + ")"
                                    });
                                    model.Axes[cnt2 + 1].Key           = cnt2.ToString();
                                    model.Axes[cnt2 + 1].PositionTier  = cnt2;
                                    model.Axes[cnt2 + 1].AxislineStyle = LineStyle.Solid;
                                    model.AddLineSeries(px, py[cnt2]);
                                    model.Series[cnt2].Title = dvar.objectTAG + " / " + flowsheet.GetTranslatedString(dvar.propID);
                                    ((OxyPlot.Series.LineSeries)(model.Series[cnt2])).YAxisKey = cnt2.ToString();
                                    cnt2 += 1;
                                }
                                model.LegendFontSize           = 11;
                                model.LegendPlacement          = LegendPlacement.Outside;
                                model.LegendOrientation        = LegendOrientation.Vertical;
                                model.LegendPosition           = LegendPosition.BottomCenter;
                                model.TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinView;

                                Application.Instance.Invoke(() => { resultschart.Model = model; resultschart.Invalidate(); });
                            }
                        });
                    }
                });

                btnAbort.Click += (sender, e) =>
                {
                    GlobalSettings.Settings.TaskCancellationTokenSource.Cancel();
                };

                task.Start();
            };
        }
Example #10
0
        private void load()
        {
            Resources.AddStore(new DllResourceStore(@"osu.Game.Resources.dll"));

            dependencies.Cache(contextFactory = new DatabaseContextFactory(Host.Storage));

            var largeStore = new LargeTextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore <byte[]>(Resources, @"Textures")));

            largeStore.AddStore(Host.CreateTextureLoaderStore(new OnlineStore()));
            dependencies.Cache(largeStore);

            dependencies.CacheAs(this);
            dependencies.Cache(LocalConfig);

            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/osuFont"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Medium"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-MediumItalic"));

            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Noto-Basic"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Noto-Hangul"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Noto-CJK-Basic"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Noto-CJK-Compatibility"));

            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Regular"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-RegularItalic"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-SemiBold"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-SemiBoldItalic"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Bold"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-BoldItalic"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Light"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-LightItalic"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-Black"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Exo2.0-BlackItalic"));

            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Venera"));
            Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Venera-Light"));

            runMigrations();

            dependencies.Cache(SkinManager = new SkinManager(Host.Storage, contextFactory, Host, Audio));
            dependencies.CacheAs <ISkinSource>(SkinManager);

            API = new APIAccess(LocalConfig);

            dependencies.CacheAs <IAPIProvider>(API);

            var defaultBeatmap = new DummyWorkingBeatmap(this);

            dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
            dependencies.Cache(FileStore    = new FileStore(contextFactory, Host.Storage));

            // ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
            dependencies.Cache(ScoreManager   = new ScoreManager(RulesetStore, () => BeatmapManager, Host.Storage, contextFactory, Host));
            dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, API, Audio, Host, defaultBeatmap));

            // this should likely be moved to ArchiveModelManager when another case appers where it is necessary
            // to have inter-dependent model managers. this could be obtained with an IHasForeign<T> interface to
            // allow lookups to be done on the child (ScoreManager in this case) to perform the cascading delete.
            List <ScoreInfo> getBeatmapScores(BeatmapSetInfo set)
            {
                var beatmapIds = BeatmapManager.QueryBeatmaps(b => b.BeatmapSetInfoID == set.ID).Select(b => b.ID).ToList();

                return(ScoreManager.QueryScores(s => beatmapIds.Contains(s.Beatmap.ID)).ToList());
            }

            BeatmapManager.ItemRemoved += i => ScoreManager.Delete(getBeatmapScores(i), true);
            BeatmapManager.ItemAdded   += (i, existing) => ScoreManager.Undelete(getBeatmapScores(i), true);

            dependencies.Cache(KeyBindingStore    = new KeyBindingStore(contextFactory, RulesetStore));
            dependencies.Cache(SettingsStore      = new SettingsStore(contextFactory));
            dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
            dependencies.Cache(new OsuColour());

            fileImporters.Add(BeatmapManager);
            fileImporters.Add(ScoreManager);
            fileImporters.Add(SkinManager);

            // tracks play so loud our samples can't keep up.
            // this adds a global reduction of track volume for the time being.
            Audio.Track.AddAdjustment(AdjustableProperty.Volume, new BindableDouble(0.8));

            beatmap = new OsuBindableBeatmap(defaultBeatmap, Audio);

            dependencies.CacheAs <IBindable <WorkingBeatmap> >(beatmap);
            dependencies.CacheAs(beatmap);

            FileStore.Cleanup();

            AddInternal(API);

            GlobalActionContainer globalBinding;

            MenuCursorContainer = new MenuCursorContainer {
                RelativeSizeAxes = Axes.Both
            };
            MenuCursorContainer.Child = globalBinding = new GlobalActionContainer(this)
            {
                RelativeSizeAxes = Axes.Both,
                Child            = content = new OsuTooltipContainer(MenuCursorContainer.Cursor)
                {
                    RelativeSizeAxes = Axes.Both
                }
            };

            base.Content.Add(new ScalingContainer(ScalingMode.Everything)
            {
                Child = MenuCursorContainer
            });

            KeyBindingStore.Register(globalBinding);
            dependencies.Cache(globalBinding);

            PreviewTrackManager previewTrackManager;

            dependencies.Cache(previewTrackManager = new PreviewTrackManager());
            Add(previewTrackManager);
        }
Example #11
0
        public CustomStylesheet()
        {
            var fonts    = new Fonts();
            var font     = new DocumentFormat.OpenXml.Spreadsheet.Font();
            var fontName = new FontName {
                Val = StringValue.FromString("Arial")
            };
            var fontSize = new FontSize {
                Val = DoubleValue.FromDouble(11)
            };

            font.FontName = fontName;
            font.FontSize = fontSize;
            fonts.Append(font);
            //Font Index 1
            font     = new DocumentFormat.OpenXml.Spreadsheet.Font();
            fontName = new FontName {
                Val = StringValue.FromString("Arial")
            };
            fontSize = new FontSize {
                Val = DoubleValue.FromDouble(12)
            };
            font.FontName = fontName;
            font.FontSize = fontSize;
            font.Bold     = new Bold();
            fonts.Append(font);
            fonts.Count = UInt32Value.FromUInt32((uint)fonts.ChildElements.Count);
            var fills       = new Fills();
            var fill        = new Fill();
            var patternFill = new PatternFill {
                PatternType = PatternValues.None
            };

            fill.PatternFill = patternFill;
            fills.Append(fill);
            fill        = new Fill();
            patternFill = new PatternFill {
                PatternType = PatternValues.Gray125
            };
            fill.PatternFill = patternFill;
            fills.Append(fill);
            //Fill index  2
            fill        = new Fill();
            patternFill = new PatternFill
            {
                PatternType     = PatternValues.Solid,
                ForegroundColor = new ForegroundColor()
            };
            patternFill.ForegroundColor =
                TranslateForeground(System.Drawing.Color.LightGray);
            patternFill.BackgroundColor =
                new BackgroundColor {
                Rgb = patternFill.ForegroundColor.Rgb
            };
            fill.PatternFill = patternFill;
            fills.Append(fill);
            //Fill index  3
            fill        = new Fill();
            patternFill = new PatternFill
            {
                PatternType     = PatternValues.Solid,
                ForegroundColor = new ForegroundColor()
            };
            patternFill.ForegroundColor =
                TranslateForeground(System.Drawing.Color.LightGray);
            patternFill.BackgroundColor =
                new BackgroundColor {
                Rgb = patternFill.ForegroundColor.Rgb
            };
            fill.PatternFill = patternFill;
            fills.Append(fill);
            fills.Count = UInt32Value.FromUInt32((uint)fills.ChildElements.Count);
            var borders = new Borders();
            var border  = new Border
            {
                LeftBorder = new LeftBorder {
                    Style = BorderStyleValues.Thin
                },
                RightBorder = new RightBorder {
                    Style = BorderStyleValues.Thin
                },
                TopBorder = new TopBorder {
                    Style = BorderStyleValues.Thin
                },
                BottomBorder = new BottomBorder {
                    Style = BorderStyleValues.Thin
                },
                DiagonalBorder = new DiagonalBorder()
            };

            borders.Append(border);
            //All Boarder Index 1
            border = new Border
            {
                LeftBorder = new LeftBorder {
                    Style = BorderStyleValues.Thin
                },
                RightBorder = new RightBorder {
                    Style = BorderStyleValues.Thin
                },
                TopBorder = new TopBorder {
                    Style = BorderStyleValues.Thin
                },
                BottomBorder = new BottomBorder {
                    Style = BorderStyleValues.Thin
                },
                DiagonalBorder = new DiagonalBorder()
            };
            borders.Append(border);
            //All Boarder Index 2
            border = new Border
            {
                LeftBorder = new LeftBorder {
                    Style = BorderStyleValues.Thin
                },
                RightBorder = new RightBorder {
                    Style = BorderStyleValues.Thin
                },
                TopBorder = new TopBorder {
                    Style = BorderStyleValues.Thin
                },
                BottomBorder = new BottomBorder {
                    Style = BorderStyleValues.Thin
                },
                DiagonalBorder = new DiagonalBorder()
            };
            borders.Append(border);
            borders.Count = UInt32Value.FromUInt32((uint)borders.ChildElements.Count);
            var cellStyleFormats = new CellStyleFormats();
            var cellFormat       = new CellFormat
            {
                NumberFormatId = 0,
                FontId         = 0,
                FillId         = 0,
                BorderId       = 0
            };

            cellStyleFormats.Append(cellFormat);
            cellStyleFormats.Count =
                UInt32Value.FromUInt32((uint)cellStyleFormats.ChildElements.Count);
            uint iExcelIndex      = 164;
            var  numberingFormats = new NumberingFormats();
            var  cellFormats      = new CellFormats();

            cellFormat = new CellFormat
            {
                NumberFormatId = 0,
                FontId         = 0,
                FillId         = 0,
                BorderId       = 0,
                FormatId       = 0
            };
            cellFormats.Append(cellFormat);
            var nformatDateTime = new NumberingFormat
            {
                NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
                FormatCode     = StringValue.FromString("dd/mm/yyyy hh:mm:ss")
            };

            numberingFormats.Append(nformatDateTime);
            var nformat4Decimal = new NumberingFormat
            {
                NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
                FormatCode     = StringValue.FromString("#,##0.0000")
            };

            numberingFormats.Append(nformat4Decimal);
            var nformat2Decimal = new NumberingFormat
            {
                NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
                FormatCode     = StringValue.FromString("#,##0.00")
            };

            numberingFormats.Append(nformat2Decimal);
            var nformatForcedText = new NumberingFormat
            {
                NumberFormatId = UInt32Value.FromUInt32(iExcelIndex),
                FormatCode     = StringValue.FromString("@")
            };

            numberingFormats.Append(nformatForcedText);
            // index 1
            // Cell Standard Date format
            cellFormat = new CellFormat
            {
                NumberFormatId    = 14,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 2
            // Cell Standard Number format with 2 decimal placing
            cellFormat = new CellFormat
            {
                NumberFormatId    = 4,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 3
            // Cell Date time custom format
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformatDateTime.NumberFormatId,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 4
            // Cell 4 decimal custom format
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformat4Decimal.NumberFormatId,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 5
            // Cell 2 decimal custom format
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformat2Decimal.NumberFormatId,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 6
            // Cell forced number text custom format
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformatForcedText.NumberFormatId,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 7
            // Cell text with font 12
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformatForcedText.NumberFormatId,
                FontId            = 1,
                FillId            = 0,
                BorderId          = 0,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 8
            // Cell text
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformatForcedText.NumberFormatId,
                FontId            = 0,
                FillId            = 0,
                BorderId          = 1,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 9
            // Coloured 2 decimal cell text
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformat2Decimal.NumberFormatId,
                FontId            = 0,
                FillId            = 2,
                BorderId          = 2,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 10
            // Coloured cell text
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformatForcedText.NumberFormatId,
                FontId            = 0,
                FillId            = 2,
                BorderId          = 2,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            // Index 11
            // Coloured cell text
            cellFormat = new CellFormat
            {
                NumberFormatId    = nformatForcedText.NumberFormatId,
                FontId            = 1,
                FillId            = 3,
                BorderId          = 2,
                FormatId          = 0,
                ApplyNumberFormat = BooleanValue.FromBoolean(true)
            };
            cellFormats.Append(cellFormat);
            numberingFormats.Count =
                UInt32Value.FromUInt32((uint)numberingFormats.ChildElements.Count);
            cellFormats.Count = UInt32Value.FromUInt32((uint)cellFormats.ChildElements.Count);
            this.Append(numberingFormats);
            this.Append(fonts);
            this.Append(fills);
            this.Append(borders);
            this.Append(cellStyleFormats);
            this.Append(cellFormats);
            var css = new CellStyles();
            var cs  = new CellStyle
            {
                Name      = StringValue.FromString("Normal"),
                FormatId  = 0,
                BuiltinId = 0
            };

            css.Append(cs);
            css.Count = UInt32Value.FromUInt32((uint)css.ChildElements.Count);
            this.Append(css);
            var dfs = new DifferentialFormats {
                Count = 0
            };

            this.Append(dfs);
            var tss = new TableStyles
            {
                Count             = 0,
                DefaultTableStyle = StringValue.FromString("TableStyleMedium9"),
                DefaultPivotStyle = StringValue.FromString("PivotStyleLight16")
            };

            this.Append(tss);
        }
        // Creates an Stylesheet instance and adds its children.
        public static Stylesheet GenerateStylesheet()
        {
            var stylesheet1 = new Stylesheet {MCAttributes = new MarkupCompatibilityAttributes {Ignorable = "x14ac"}};
            stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

            var fonts1 = new Fonts {Count = 7U, KnownFonts = true};

            var font1 = new Font();
            var fontSize1 = new FontSize {Val = 11D};
            var color1 = new Color {Theme = 1U};
            var fontName1 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering1 = new FontFamilyNumbering {Val = 2};
            var fontCharSet1 = new FontCharSet {Val = 204};
            var fontScheme1 = new FontScheme {Val = FontSchemeValues.Minor};

            font1.Append(fontSize1);
            font1.Append(color1);
            font1.Append(fontName1);
            font1.Append(fontFamilyNumbering1);
            font1.Append(fontCharSet1);
            font1.Append(fontScheme1);

            var font2 = new Font();
            var bold1 = new Bold();
            var fontSize2 = new FontSize {Val = 11D};
            var color2 = new Color {Theme = 1U};
            var fontName2 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering2 = new FontFamilyNumbering {Val = 2};
            var fontCharSet2 = new FontCharSet {Val = 204};
            var fontScheme2 = new FontScheme {Val = FontSchemeValues.Minor};

            font2.Append(bold1);
            font2.Append(fontSize2);
            font2.Append(color2);
            font2.Append(fontName2);
            font2.Append(fontFamilyNumbering2);
            font2.Append(fontCharSet2);
            font2.Append(fontScheme2);

            var font3 = new Font();
            var bold2 = new Bold();
            var italic1 = new Italic();
            var fontSize3 = new FontSize {Val = 11D};
            var color3 = new Color {Theme = 1U};
            var fontName3 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering3 = new FontFamilyNumbering {Val = 2};
            var fontCharSet3 = new FontCharSet {Val = 204};
            var fontScheme3 = new FontScheme {Val = FontSchemeValues.Minor};

            font3.Append(bold2);
            font3.Append(italic1);
            font3.Append(fontSize3);
            font3.Append(color3);
            font3.Append(fontName3);
            font3.Append(fontFamilyNumbering3);
            font3.Append(fontCharSet3);
            font3.Append(fontScheme3);

            var font4 = new Font();
            var bold3 = new Bold();
            var fontSize4 = new FontSize {Val = 18D};
            var color4 = new Color {Theme = 1U};
            var fontName4 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering4 = new FontFamilyNumbering {Val = 2};
            var fontCharSet4 = new FontCharSet {Val = 204};
            var fontScheme4 = new FontScheme {Val = FontSchemeValues.Minor};

            font4.Append(bold3);
            font4.Append(fontSize4);
            font4.Append(color4);
            font4.Append(fontName4);
            font4.Append(fontFamilyNumbering4);
            font4.Append(fontCharSet4);
            font4.Append(fontScheme4);

            var font5 = new Font();
            var bold4 = new Bold();
            var fontSize5 = new FontSize {Val = 11D};
            var fontName5 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering5 = new FontFamilyNumbering {Val = 2};
            var fontCharSet5 = new FontCharSet {Val = 204};
            var fontScheme5 = new FontScheme {Val = FontSchemeValues.Minor};

            font5.Append(bold4);
            font5.Append(fontSize5);
            font5.Append(fontName5);
            font5.Append(fontFamilyNumbering5);
            font5.Append(fontCharSet5);
            font5.Append(fontScheme5);

            var font6 = new Font();
            var fontSize6 = new FontSize {Val = 11D};
            var fontName6 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering6 = new FontFamilyNumbering {Val = 2};
            var fontCharSet6 = new FontCharSet {Val = 204};
            var fontScheme6 = new FontScheme {Val = FontSchemeValues.Minor};

            font6.Append(fontSize6);
            font6.Append(fontName6);
            font6.Append(fontFamilyNumbering6);
            font6.Append(fontCharSet6);
            font6.Append(fontScheme6);

            var font7 = new Font();
            var bold5 = new Bold();
            var fontSize7 = new FontSize {Val = 12D};
            var color5 = new Color {Theme = 1U};
            var fontName7 = new FontName {Val = "Calibri"};
            var fontFamilyNumbering7 = new FontFamilyNumbering {Val = 2};
            var fontCharSet7 = new FontCharSet {Val = 204};
            var fontScheme7 = new FontScheme {Val = FontSchemeValues.Minor};

            font7.Append(bold5);
            font7.Append(fontSize7);
            font7.Append(color5);
            font7.Append(fontName7);
            font7.Append(fontFamilyNumbering7);
            font7.Append(fontCharSet7);
            font7.Append(fontScheme7);

            fonts1.Append(font1);
            fonts1.Append(font2);
            fonts1.Append(font3);
            fonts1.Append(font4);
            fonts1.Append(font5);
            fonts1.Append(font6);
            fonts1.Append(font7);

            var fills1 = new Fills {Count = 2U};

            var fill1 = new Fill();
            var patternFill1 = new PatternFill {PatternType = PatternValues.None};

            fill1.Append(patternFill1);

            var fill2 = new Fill();
            var patternFill2 = new PatternFill {PatternType = PatternValues.Gray125};

            fill2.Append(patternFill2);

            fills1.Append(fill1);
            fills1.Append(fill2);

            var borders1 = new Borders {Count = 2U};

            var border1 = new Border();
            var leftBorder1 = new LeftBorder();
            var rightBorder1 = new RightBorder();
            var topBorder1 = new TopBorder();
            var bottomBorder1 = new BottomBorder();
            var diagonalBorder1 = new DiagonalBorder();

            border1.Append(leftBorder1);
            border1.Append(rightBorder1);
            border1.Append(topBorder1);
            border1.Append(bottomBorder1);
            border1.Append(diagonalBorder1);

            var border2 = new Border();

            var leftBorder2 = new LeftBorder {Style = BorderStyleValues.Thin};
            var color6 = new Color {Indexed = 64U};

            leftBorder2.Append(color6);

            var rightBorder2 = new RightBorder {Style = BorderStyleValues.Thin};
            var color7 = new Color {Indexed = 64U};

            rightBorder2.Append(color7);

            var topBorder2 = new TopBorder {Style = BorderStyleValues.Thin};
            var color8 = new Color {Indexed = 64U};

            topBorder2.Append(color8);

            var bottomBorder2 = new BottomBorder {Style = BorderStyleValues.Thin};
            var color9 = new Color {Indexed = 64U};

            bottomBorder2.Append(color9);
            var diagonalBorder2 = new DiagonalBorder();

            border2.Append(leftBorder2);
            border2.Append(rightBorder2);
            border2.Append(topBorder2);
            border2.Append(bottomBorder2);
            border2.Append(diagonalBorder2);

            borders1.Append(border1);
            borders1.Append(border2);

            var cellStyleFormats1 = new CellStyleFormats {Count = 4U};
            var cellFormat1 = new CellFormat {NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U};
            var cellFormat2 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 5U,
                    FillId = 0U,
                    BorderId = 1U,
                    ApplyNumberFormat = false,
                    ApplyAlignment = false,
                    ApplyProtection = false
                };
            var cellFormat3 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 4U,
                    FillId = 0U,
                    BorderId = 1U,
                    ApplyNumberFormat = false,
                    ApplyAlignment = false,
                    ApplyProtection = false
                };
            var cellFormat4 = new CellFormat {NumberFormatId = 0U, FontId = 6U, FillId = 0U, BorderId = 1U};

            cellStyleFormats1.Append(cellFormat1);
            cellStyleFormats1.Append(cellFormat2);
            cellStyleFormats1.Append(cellFormat3);
            cellStyleFormats1.Append(cellFormat4);

            var cellFormats1 = new CellFormats {Count = 5U};
            var cellFormat5 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 0U,
                    FillId = 0U,
                    BorderId = 0U,
                    FormatId = 0U
                };
            var cellFormat6 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 1U,
                    FillId = 0U,
                    BorderId = 0U,
                    FormatId = 0U,
                    ApplyFont = true
                };
            var cellFormat7 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 2U,
                    FillId = 0U,
                    BorderId = 0U,
                    FormatId = 0U,
                    ApplyFont = true,
                    ApplyBorder = true
                };
            var cellFormat8 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 0U,
                    FillId = 0U,
                    BorderId = 0U,
                    FormatId = 0U,
                    ApplyAlignment = true
                };

            var cellFormat9 = new CellFormat
                {
                    NumberFormatId = 0U,
                    FontId = 3U,
                    FillId = 0U,
                    BorderId = 0U,
                    FormatId = 0U,
                    ApplyFont = true,
                    ApplyAlignment = true
                };
            var alignment1 = new Alignment {Horizontal = HorizontalAlignmentValues.Center};

            cellFormat9.Append(alignment1);

            cellFormats1.Append(cellFormat5);
            cellFormats1.Append(cellFormat6);
            cellFormats1.Append(cellFormat7);
            cellFormats1.Append(cellFormat8);
            cellFormats1.Append(cellFormat9);

            var cellStyles1 = new CellStyles {Count = 4U};
            var cellStyle1 = new CellStyle {Name = "Custom", FormatId = 3U};
            var cellStyle2 = new CellStyle {Name = "Нейтральный", FormatId = 2U, BuiltinId = 28U, CustomBuiltin = true};
            var cellStyle3 = new CellStyle {Name = "Обычный", FormatId = 0U, BuiltinId = 0U};
            var cellStyle4 = new CellStyle {Name = "Плохой", FormatId = 1U, BuiltinId = 27U, CustomBuiltin = true};

            cellStyles1.Append(cellStyle1);
            cellStyles1.Append(cellStyle2);
            cellStyles1.Append(cellStyle3);
            cellStyles1.Append(cellStyle4);
            var differentialFormats1 = new DifferentialFormats {Count = 0U};
            var tableStyles1 = new TableStyles
                {
                    Count = 0U,
                    DefaultTableStyle = "TableStyleMedium2",
                    DefaultPivotStyle = "PivotStyleLight16"
                };

            var stylesheetExtensionList1 = new StylesheetExtensionList();

            var stylesheetExtension1 = new StylesheetExtension {Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"};
            stylesheetExtension1.AddNamespaceDeclaration("x14",
                                                         "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
            var slicerStyles1 = new X14.SlicerStyles {DefaultSlicerStyle = "SlicerStyleLight1"};

            stylesheetExtension1.Append(slicerStyles1);

            stylesheetExtensionList1.Append(stylesheetExtension1);

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellStyleFormats1);
            stylesheet1.Append(cellFormats1);
            stylesheet1.Append(cellStyles1);
            stylesheet1.Append(differentialFormats1);
            stylesheet1.Append(tableStyles1);
            stylesheet1.Append(stylesheetExtensionList1);
            return stylesheet1;
        }
        // Generates content of workbookStylesPart1.
        private void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1)
        {
            Stylesheet stylesheet1 = new Stylesheet();
            Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts = true };
            Font font1 = new Font();
            FontSize fontSize1 = new FontSize() { Val = 11D };
            Color color1 = new Color() { Theme = (UInt32Value)1U };
            FontName fontName1 = new FontName() { Val = "Calibri" };
            FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 };
            FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor };

            font1.Append(fontSize1);
            font1.Append(color1);
            font1.Append(fontName1);
            font1.Append(fontFamilyNumbering1);
            font1.Append(fontScheme1);

            fonts1.Append(font1);

            Fills fills1 = new Fills() { Count = (UInt32Value)2U };
            Fill fill1 = new Fill();
            PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None };
            fill1.Append(patternFill1);

            Fill fill2 = new Fill();
            PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 };
            fill2.Append(patternFill2);

            fills1.Append(fill1);
            fills1.Append(fill2);

            Borders borders1 = new Borders() { Count = (UInt32Value)1U };

            Border border1 = new Border();
            LeftBorder leftBorder1 = new LeftBorder();
            RightBorder rightBorder1 = new RightBorder();
            TopBorder topBorder1 = new TopBorder();
            BottomBorder bottomBorder1 = new BottomBorder();
            DiagonalBorder diagonalBorder1 = new DiagonalBorder();

            border1.Append(leftBorder1);
            border1.Append(rightBorder1);
            border1.Append(topBorder1);
            border1.Append(bottomBorder1);
            border1.Append(diagonalBorder1);

            borders1.Append(border1);

            CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U };
            CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U };

            cellStyleFormats1.Append(cellFormat1);

            CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)4U };
            CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U };
            CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true };
            CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, PivotButton = true };
            CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyAlignment = true };

            cellFormats1.Append(cellFormat2);
            cellFormats1.Append(cellFormat3);
            cellFormats1.Append(cellFormat4);
            cellFormats1.Append(cellFormat5);

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

            cellStyles1.Append(cellStyle1);
            DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U };

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellStyleFormats1);
            stylesheet1.Append(cellFormats1);
            stylesheet1.Append(cellStyles1);
            stylesheet1.Append(differentialFormats1);

            workbookStylesPart1.Stylesheet = stylesheet1;
        }
Example #14
0
        /// <summary>
        /// Adds minimal stylesheet to workbook
        /// </summary>
        /// <param name="spreadsheetDocument">workbook</param>
        private void AddStyleSheet(SpreadsheetDocument spreadsheetDocument)
        {
            WorkbookStylesPart stylesheet = spreadsheetDocument.WorkbookPart.AddNewPart <WorkbookStylesPart>();

            Stylesheet workbookstylesheet = new Stylesheet();

            // Create "fonts" node.
            Fonts fonts = new Fonts();

            fonts.Append(new Font() // default font
            {
                FontName = new FontName()
                {
                    Val = "Calibri"
                },
                FontSize = new FontSize()
                {
                    Val = 11
                },
                FontFamilyNumbering = new FontFamilyNumbering()
                {
                    Val = 2
                },
            });

            // <Fills>
            Fills fills = new Fills();      // Default fill

            fills.Append(new Fill());

            // <Borders>
            Borders borders = new Borders(); // default border

            borders.Append(new Border());

            // <CellFormats>
            // First define a default CellFormat; this is mandatory
            CellFormat cellformat0 = new CellFormat()
            {
                BorderId          = 0,
                FillId            = 0,
                FontId            = 0,
                NumberFormatId    = (uint)OutputNumberFormat.General,
                FormatId          = 0,
                ApplyNumberFormat = false
            }; // Default style : Mandatory; Style ID =0

            // Number
            CellFormat cellformat1 = new CellFormat()
            {
                BorderId          = 0,
                FillId            = 0,
                FontId            = 0,
                NumberFormatId    = (uint)OutputNumberFormat.Number,
                FormatId          = 0,
                ApplyNumberFormat = true
            };  // Style ID = 1

            // Date
            CellFormat cellformat2 = new CellFormat()
            {
                BorderId          = 0,
                FillId            = 0,
                FontId            = 0,
                NumberFormatId    = (uint)OutputNumberFormat.Date,
                FormatId          = 0,
                ApplyNumberFormat = true
            };  // Style ID = 2

            // Time
            CellFormat cellformat3 = new CellFormat()
            {
                BorderId          = 0,
                FillId            = 0,
                FontId            = 0,
                NumberFormatId    = (uint)OutputNumberFormat.Time,
                FormatId          = 0,
                ApplyNumberFormat = true
            };  // Style ID = 3

            // append cellformats
            CellFormats cellformats = new CellFormats();

            cellformats.Append(cellformat0);
            cellformats.Append(cellformat1);
            cellformats.Append(cellformat2);
            cellformats.Append(cellformat3);

            // Append FONTS, FILLS , BORDERS & CellFormats to stylesheet <Preserve the ORDER>
            workbookstylesheet.Append(fonts);
            workbookstylesheet.Append(fills);
            workbookstylesheet.Append(borders);
            workbookstylesheet.Append(cellformats);

            // Finalize
            stylesheet.Stylesheet = workbookstylesheet;
            stylesheet.Stylesheet.Save();
        }
Example #15
0
        private static Stylesheet GetStylesheet()
        {
            Stylesheet stylesheet = new Stylesheet();
            Fonts fonts = new Fonts();
            fonts.Append(new Font()
            {
                FontName = new FontName() { Val = "Calibri" },
                FontSize = new FontSize() { Val = 11 },
                FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 },
            });
            fonts.Count = (uint)fonts.ChildElements.Count;

            Fills fills = new Fills();
            fills.Append(new Fill() { PatternFill = new PatternFill() { PatternType = PatternValues.None } });
            fills.Append(new Fill() { PatternFill = new PatternFill() { PatternType = PatternValues.Gray125 } });
            fills.Count = (uint)fills.ChildElements.Count;

            Borders borders = new Borders();
            borders.Append(new Border()
            {
                LeftBorder = new LeftBorder(),
                RightBorder = new RightBorder(),
                TopBorder = new TopBorder(),
                BottomBorder = new BottomBorder(),
                DiagonalBorder = new DiagonalBorder()
            });
            borders.Count = (uint)borders.ChildElements.Count;

            CellStyleFormats cellstyleformats = new CellStyleFormats();
            cellstyleformats.Append(new CellFormat()
            {
                NumberFormatId = 0,
                FontId = 0,
                FillId = 0,
                BorderId = 0
            });
            cellstyleformats.Count = (uint)cellstyleformats.ChildElements.Count;

            CellFormats cellformats = new CellFormats();
            cellformats.Append(new CellFormat()
            {
                BorderId = 0,
                FillId = 0,
                FontId = 0,
                NumberFormatId = 0,
                FormatId = 0
            });
            cellformats.Append(new CellFormat()
            {
                BorderId = 0,
                FillId = 0,
                FontId = 0,
                NumberFormatId = 14,
                FormatId = 0,
                ApplyNumberFormat = true
            });
            cellformats.Count = (uint)cellformats.ChildElements.Count;

            CellStyles cellstyles = new CellStyles();
            cellstyles.Append(new CellStyle()
            {
                Name = "Normal",
                FormatId = 0,
                BuiltinId = 0
            });
            cellstyles.Count = (uint)cellstyles.ChildElements.Count;

            stylesheet.Append(fonts);
            stylesheet.Append(fills);
            stylesheet.Append(borders);
            stylesheet.Append(cellstyleformats);
            stylesheet.Append(cellformats);
            stylesheet.Append(cellstyles);

            return stylesheet;
        }
        public CustomStylesheet()
        {
            Fonts fts = new Fonts();
            Font ft = new Font();
            FontName ftn = new FontName();
            ftn.Val = StringValue.FromString("Calibri");
            FontSize ftsz = new FontSize();
            ftsz.Val = DoubleValue.FromDouble(11);
            ft.FontName = ftn;
            ft.FontSize = ftsz;
            fts.Append(ft);

            ft = new Font();
            ftn = new FontName();
            ftn.Val = StringValue.FromString("Palatino Linotype");
            ftsz = new FontSize();
            ftsz.Val = DoubleValue.FromDouble(18);
            ft.FontName = ftn;
            ft.FontSize = ftsz;
            fts.Append(ft);

            fts.Count = UInt32Value.FromUInt32((uint)fts.ChildElements.Count);

            Fills fills = new Fills();
            Fill fill;
            PatternFill patternFill;
            fill = new Fill();
            patternFill = new PatternFill();
            patternFill.PatternType = PatternValues.None;
            fill.PatternFill = patternFill;
            fills.Append(fill);

            fill = new Fill();
            patternFill = new PatternFill();
            patternFill.PatternType = PatternValues.Gray125;
            fill.PatternFill = patternFill;
            fills.Append(fill);

            fill = new Fill();
            patternFill = new PatternFill();
            patternFill.PatternType = PatternValues.Solid;
            patternFill.ForegroundColor = new ForegroundColor();
            patternFill.ForegroundColor.Rgb = HexBinaryValue.FromString("00ff9728");
            patternFill.BackgroundColor = new BackgroundColor();
            patternFill.BackgroundColor.Rgb = patternFill.ForegroundColor.Rgb;
            fill.PatternFill = patternFill;
            fills.Append(fill);

            fills.Count = UInt32Value.FromUInt32((uint)fills.ChildElements.Count);

            Borders borders = new Borders();
            Border border = new Border();
            border.LeftBorder = new LeftBorder();
            border.RightBorder = new RightBorder();
            border.TopBorder = new TopBorder();
            border.BottomBorder = new BottomBorder();
            border.DiagonalBorder = new DiagonalBorder();
            borders.Append(border);

            //Boarder Index 1
            border = new Border();
            border.LeftBorder = new LeftBorder();
            border.LeftBorder.Style = BorderStyleValues.Thin;
            border.RightBorder = new RightBorder();
            border.RightBorder.Style = BorderStyleValues.Thin;
            border.TopBorder = new TopBorder();
            border.TopBorder.Style = BorderStyleValues.Thin;
            border.BottomBorder = new BottomBorder();
            border.BottomBorder.Style = BorderStyleValues.Thin;
            border.DiagonalBorder = new DiagonalBorder();
            borders.Append(border);

            //Boarder Index 2
            border = new Border();
            border.LeftBorder = new LeftBorder();
            border.RightBorder = new RightBorder();
            border.TopBorder = new TopBorder();
            border.TopBorder.Style = BorderStyleValues.Thin;
            border.BottomBorder = new BottomBorder();
            border.BottomBorder.Style = BorderStyleValues.Thin;
            border.DiagonalBorder = new DiagonalBorder();
            borders.Append(border);

            borders.Count = UInt32Value.FromUInt32((uint)borders.ChildElements.Count);

            CellStyleFormats csfs = new CellStyleFormats();
            CellFormat cf = new CellFormat();
            cf.NumberFormatId = 0;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            csfs.Append(cf);
            csfs.Count = UInt32Value.FromUInt32((uint)csfs.ChildElements.Count);

            uint iExcelIndex = 164;
            NumberingFormats nfs = new NumberingFormats();
            CellFormats cfs = new CellFormats();

            cf = new CellFormat();
            cf.NumberFormatId = 0;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cfs.Append(cf);

            NumberingFormat nfDateTime = new NumberingFormat();
            nfDateTime.NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++);
            nfDateTime.FormatCode = StringValue.FromString("dd/mm/yyyy hh:mm:ss");
            nfs.Append(nfDateTime);

            NumberingFormat nf4decimal = new NumberingFormat();
            nf4decimal.NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++);
            nf4decimal.FormatCode = StringValue.FromString("#,##0.0000");
            nfs.Append(nf4decimal);

            // #,##0.00 is also Excel style index 4
            NumberingFormat nf2decimal = new NumberingFormat();
            nf2decimal.NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++);
            nf2decimal.FormatCode = StringValue.FromString("#,##0.00");
            nfs.Append(nf2decimal);

            // @ is also Excel style index 49
            NumberingFormat nfForcedText = new NumberingFormat();
            nfForcedText.NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++);
            nfForcedText.FormatCode = StringValue.FromString("@");
            nfs.Append(nfForcedText);

            // index 1
            // Format dd/mm/yyyy
            cf = new CellFormat();
            cf.NumberFormatId = 14;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 2
            // Format #,##0.00
            cf = new CellFormat();
            cf.NumberFormatId = 4;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 3
            cf = new CellFormat();
            cf.NumberFormatId = nfDateTime.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 4
            cf = new CellFormat();
            cf.NumberFormatId = nf4decimal.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 5
            cf = new CellFormat();
            cf.NumberFormatId = nf2decimal.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 6
            cf = new CellFormat();
            cf.NumberFormatId = nfForcedText.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 7
            // Header text
            cf = new CellFormat();
            cf.NumberFormatId = nfForcedText.NumberFormatId;
            cf.FontId = 1;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 8
            // column text
            cf = new CellFormat();
            cf.NumberFormatId = nfForcedText.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 1;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 9
            // coloured 2 decimal text
            cf = new CellFormat();
            cf.NumberFormatId = nf2decimal.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 2;
            cf.BorderId = 2;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            // index 10
            // coloured column text
            cf = new CellFormat();
            cf.NumberFormatId = nfForcedText.NumberFormatId;
            cf.FontId = 0;
            cf.FillId = 2;
            cf.BorderId = 2;
            cf.FormatId = 0;
            cf.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cfs.Append(cf);

            nfs.Count = UInt32Value.FromUInt32((uint)nfs.ChildElements.Count);
            cfs.Count = UInt32Value.FromUInt32((uint)cfs.ChildElements.Count);

            this.Append(nfs);
            this.Append(fts);
            this.Append(fills);
            this.Append(borders);
            this.Append(csfs);
            this.Append(cfs);

            CellStyles css = new CellStyles();
            CellStyle cs = new CellStyle();
            cs.Name = StringValue.FromString("Normal");
            cs.FormatId = 0;
            cs.BuiltinId = 0;
            css.Append(cs);
            css.Count = UInt32Value.FromUInt32((uint)css.ChildElements.Count);
            this.Append(css);

            DifferentialFormats dfs = new DifferentialFormats();
            dfs.Count = 0;
            this.Append(dfs);

            TableStyles tss = new TableStyles();
            tss.Count = 0;
            tss.DefaultTableStyle = StringValue.FromString("TableStyleMedium9");
            tss.DefaultPivotStyle = StringValue.FromString("PivotStyleLight16");
            this.Append(tss);
        }
Example #17
0
 protected virtual void OnFontChanged(Font font, Fonts.Manager fm) { }
Example #18
0
		private static Stylesheet OpenXML_CreateStylesheet()
		{
			// 08/25/2012   The file will be corrupt unless fonts, fills and borders are also provided. 
			var stylesheet = new Stylesheet();
			var fonts       = new Fonts      (new[] { new Font      () }) { Count = 1 };
			var fills       = new Fills      (new[] { new Fill      () }) { Count = 1 };
			var borders     = new Borders    (new[] { new Border    () }) { Count = 1 };
			var cellFormats = new CellFormats(new[] { new CellFormat() }) { Count = 1 };
			stylesheet.Append(fonts      );
			stylesheet.Append(fills      );
			stylesheet.Append(borders    );
			stylesheet.Append(cellFormats);
			return stylesheet;
		}
        // Creates an Stylesheet instance and adds its children.
        public Stylesheet GenerateStylesheet()
        {
            Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } };
            stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

            Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U };

            Font font1 = new Font();
            FontSize fontSize1 = new FontSize() { Val = 11D };
            FontName fontName1 = new FontName() { Val = "Calibri" };

            font1.Append(fontSize1);
            font1.Append(fontName1);

            fonts1.Append(font1);

            Fills fills1 = new Fills() { Count = (UInt32Value)2U };

            Fill fill1 = new Fill();
            PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None };

            fill1.Append(patternFill1);

            Fill fill2 = new Fill();
            PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 };

            fill2.Append(patternFill2);

            fills1.Append(fill1);
            fills1.Append(fill2);

            Borders borders1 = new Borders() { Count = (UInt32Value)1U };
            Border border1 = new Border();
            LeftBorder leftBorder1 = new LeftBorder();
            RightBorder rightBorder1 = new RightBorder();
            TopBorder topBorder1 = new TopBorder();
            BottomBorder bottomBorder1 = new BottomBorder();
            DiagonalBorder diagonalBorder1 = new DiagonalBorder();

            border1.Append(leftBorder1);
            border1.Append(rightBorder1);
            border1.Append(topBorder1);
            border1.Append(bottomBorder1);
            border1.Append(diagonalBorder1);

            Border border2 = new Border();
            LeftBorder leftBorder2 = new LeftBorder() { Style = BorderStyleValues.Thin };
            Color color1 = new Color() { Indexed = (UInt32Value)64U };
            leftBorder2.Append(color1);
            RightBorder rightBorder2 = new RightBorder() { Style = BorderStyleValues.Thin };
            Color color2 = new Color() { Indexed = (UInt32Value)64U };
            rightBorder2.Append(color2);
            TopBorder topBorder2 = new TopBorder() { Style = BorderStyleValues.Thin };
            Color color3 = new Color() { Indexed = (UInt32Value)64U };
            topBorder2.Append(color3);
            BottomBorder bottomBorder2 = new BottomBorder() { Style = BorderStyleValues.Thin };
            Color color4 = new Color() { Indexed = (UInt32Value)64U };
            bottomBorder2.Append(color4);
            DiagonalBorder diagonalBorder2 = new DiagonalBorder() { Style = BorderStyleValues.Thin };
            Color color5 = new Color() { Indexed = (UInt32Value)64U };
            diagonalBorder2.Append(color5);

            border2.Append(leftBorder2);
            border2.Append(rightBorder2);
            border2.Append(topBorder2);
            border2.Append(bottomBorder2);
            border2.Append(diagonalBorder2);

            borders1.Append(border1);
            borders1.Append(border2);

            CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U };
            CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U };

            cellStyleFormats1.Append(cellFormat1);

            CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)1U };
            CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U };

            cellFormats1.Append(cellFormat2);

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

            cellStyles1.Append(cellStyle1);
            DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U };
            TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };

            StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList();

            StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
            stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
            DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles slicerStyles1 = new DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" };

            stylesheetExtension1.Append(slicerStyles1);

            stylesheetExtensionList1.Append(stylesheetExtension1);

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellStyleFormats1);
            stylesheet1.Append(cellFormats1);
            stylesheet1.Append(cellStyles1);
            stylesheet1.Append(differentialFormats1);
            stylesheet1.Append(tableStyles1);
            stylesheet1.Append(stylesheetExtensionList1);
            return stylesheet1;
        }
Example #20
0
        /// <summary>
        /// Loads the style XML to memory
        /// </summary>
        private void LoadFromDocument()
        {
            //NumberFormats
            ExcelNumberFormatXml.AddBuildIn(NameSpaceManager, NumberFormats);
            XmlNode numNode = _styleXml.SelectSingleNode(NumberFormatsPath, _nameSpaceManager);

            if (numNode != null)
            {
                foreach (XmlNode n in numNode)
                {
                    ExcelNumberFormatXml nf = new ExcelNumberFormatXml(_nameSpaceManager, n);
                    NumberFormats.Add(nf.Id, nf);
                    if (nf.NumFmtId >= NumberFormats.NextId)
                    {
                        NumberFormats.NextId = nf.NumFmtId + 1;
                    }
                }
            }

            //Fonts
            XmlNode fontNode = _styleXml.SelectSingleNode(FontsPath, _nameSpaceManager);

            foreach (XmlNode n in fontNode)
            {
                ExcelFontXml f = new ExcelFontXml(_nameSpaceManager, n);
                Fonts.Add(f.Id, f);
            }

            //Fills
            XmlNode fillNode = _styleXml.SelectSingleNode(FillsPath, _nameSpaceManager);

            foreach (XmlNode n in fillNode)
            {
                ExcelFillXml f;
                if (n.FirstChild != null && n.FirstChild.LocalName == "gradientFill")
                {
                    f = new ExcelGradientFillXml(_nameSpaceManager, n);
                }
                else
                {
                    f = new ExcelFillXml(_nameSpaceManager, n);
                }
                Fills.Add(f.Id, f);
            }

            //Borders
            XmlNode borderNode = _styleXml.SelectSingleNode(BordersPath, _nameSpaceManager);

            foreach (XmlNode n in borderNode)
            {
                ExcelBorderXml b = new ExcelBorderXml(_nameSpaceManager, n);
                Borders.Add(b.Id, b);
            }

            //cellStyleXfs
            XmlNode styleXfsNode = _styleXml.SelectSingleNode(CellStyleXfsPath, _nameSpaceManager);

            if (styleXfsNode != null)
            {
                foreach (XmlNode n in styleXfsNode)
                {
                    ExcelXfs item = new ExcelXfs(_nameSpaceManager, n, this);
                    CellStyleXfs.Add(item.Id, item);
                }
            }

            XmlNode styleNode = _styleXml.SelectSingleNode(CellXfsPath, _nameSpaceManager);

            for (int i = 0; i < styleNode.ChildNodes.Count; i++)
            {
                XmlNode  n    = styleNode.ChildNodes[i];
                ExcelXfs item = new ExcelXfs(_nameSpaceManager, n, this);
                CellXfs.Add(item.Id, item);
            }

            //cellStyle
            XmlNode namedStyleNode = _styleXml.SelectSingleNode(CellStylesPath, _nameSpaceManager);

            if (namedStyleNode != null)
            {
                foreach (XmlNode n in namedStyleNode)
                {
                    ExcelNamedStyleXml item = new ExcelNamedStyleXml(_nameSpaceManager, n, this);
                    NamedStyles.Add(item.Name, item);
                }
            }

            //dxfsPath
            XmlNode dxfsNode = _styleXml.SelectSingleNode(dxfsPath, _nameSpaceManager);

            if (dxfsNode != null)
            {
                foreach (XmlNode x in dxfsNode)
                {
                    ExcelDxfStyleConditionalFormatting item = new ExcelDxfStyleConditionalFormatting(_nameSpaceManager, x, this);
                    Dxfs.Add(item.Id, item);
                }
            }
        }
Example #21
0
        private static void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart1)
        {
            Stylesheet stylesheet1 = new Stylesheet()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "x14ac x16r2 xr"
                }
            };

            stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");
            stylesheet1.AddNamespaceDeclaration("x16r2", "http://schemas.microsoft.com/office/spreadsheetml/2015/02/main");
            stylesheet1.AddNamespaceDeclaration("xr", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision");

            Fonts fonts1 = new Fonts()
            {
                Count = (UInt32Value)1U, KnownFonts = true
            };

            Font     font1     = new Font();
            FontSize fontSize1 = new FontSize()
            {
                Val = 11D
            };
            Color color1 = new Color()
            {
                Theme = (UInt32Value)1U
            };
            FontName fontName1 = new FontName()
            {
                Val = "Calibri"
            };
            FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering()
            {
                Val = 2
            };
            FontScheme fontScheme1 = new FontScheme()
            {
                Val = FontSchemeValues.Minor
            };

            font1.Append(fontSize1);
            font1.Append(color1);
            font1.Append(fontName1);
            font1.Append(fontFamilyNumbering1);
            font1.Append(fontScheme1);

            fonts1.Append(font1);

            Fills fills1 = new Fills()
            {
                Count = (UInt32Value)2U
            };

            Fill        fill1        = new Fill();
            PatternFill patternFill1 = new PatternFill()
            {
                PatternType = PatternValues.None
            };

            fill1.Append(patternFill1);

            Fill        fill2        = new Fill();
            PatternFill patternFill2 = new PatternFill()
            {
                PatternType = PatternValues.Gray125
            };

            fill2.Append(patternFill2);

            fills1.Append(fill1);
            fills1.Append(fill2);

            Borders borders1 = new Borders()
            {
                Count = (UInt32Value)1U
            };

            Border         border1         = new Border();
            LeftBorder     leftBorder1     = new LeftBorder();
            RightBorder    rightBorder1    = new RightBorder();
            TopBorder      topBorder1      = new TopBorder();
            BottomBorder   bottomBorder1   = new BottomBorder();
            DiagonalBorder diagonalBorder1 = new DiagonalBorder();

            border1.Append(leftBorder1);
            border1.Append(rightBorder1);
            border1.Append(topBorder1);
            border1.Append(bottomBorder1);
            border1.Append(diagonalBorder1);

            borders1.Append(border1);

            CellStyleFormats cellStyleFormats1 = new CellStyleFormats()
            {
                Count = (UInt32Value)1U
            };
            CellFormat cellFormat1 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U
            };

            cellStyleFormats1.Append(cellFormat1);

            CellFormats cellFormats1 = new CellFormats()
            {
                Count = (UInt32Value)2U
            };
            CellFormat cellFormat2 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U
            };
            CellFormat cellFormat3 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true
            };

            cellFormats1.Append(cellFormat2);
            cellFormats1.Append(cellFormat3);

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

            cellStyles1.Append(cellStyle1);
            DifferentialFormats differentialFormats1 = new DifferentialFormats()
            {
                Count = (UInt32Value)0U
            };
            TableStyles tableStyles1 = new TableStyles()
            {
                Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16"
            };

            StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList();

            StylesheetExtension stylesheetExtension1 = new StylesheetExtension()
            {
                Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
            };

            stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");

            StylesheetExtension stylesheetExtension2 = new StylesheetExtension()
            {
                Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
            };

            stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");

            OpenXmlUnknownElement openXmlUnknownElement4 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<x15:timelineStyles defaultTimelineStyle=\"TimeSlicerStyleLight1\" xmlns:x15=\"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main\" />");

            stylesheetExtension2.Append(openXmlUnknownElement4);

            stylesheetExtensionList1.Append(stylesheetExtension1);
            stylesheetExtensionList1.Append(stylesheetExtension2);

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellStyleFormats1);
            stylesheet1.Append(cellFormats1);
            stylesheet1.Append(cellStyles1);
            stylesheet1.Append(differentialFormats1);
            stylesheet1.Append(tableStyles1);
            stylesheet1.Append(stylesheetExtensionList1);

            workbookStylesPart1.Stylesheet = stylesheet1;
        }
        //описвывает форматы ячеек
        protected void GenWorkbookStylesPart(WorkbookStylesPart workbookStylesPart)
        {
            Stylesheet stylesheet = new Stylesheet();

            Fonts fonts1 = new Fonts();

            Font font1 = new Font();

            Font font2 = new Font();
            FontSize fontSize2 = new FontSize() { Val = 11D };
            Color color1 = new Color() { Rgb = "FF00B050" };
            FontName fontName2 = new FontName() { Val = "Calibri" };
            FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 };
            FontCharSet fontCharSet1 = new FontCharSet() { Val = 204 };

            font2.Append(fontSize2);
            font2.Append(color1);
            font2.Append(fontName2);
            font2.Append(fontFamilyNumbering1);
            font2.Append(fontCharSet1);

            //fonts1.Append(font2);
            fonts1.Append(font1);

            Fills fills1 = new Fills();
            Fill fill1 = new Fill();
            Fill fill2 = new Fill();
            Fill fill3 = new Fill();
            PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid };

            ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "0000FF" };
            patternFill3.Append(foregroundColor1);
            fill3.Append(patternFill3);
            fills1.Append(fill1);
            fills1.Append(fill2);
            fills1.Append(fill3);

            Borders borders1 = new Borders();
            Border border1 = new Border();
            borders1.Append(border1);

            //Переопределяем номера формата 164U, 166U, 167U, 168U,
            NumberingFormats numberingFormats1 = new NumberingFormats() { Count = (UInt32Value)3U };
            NumberingFormat numberingFormat1 = new NumberingFormat() { NumberFormatId = (UInt32Value)164U, FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy" };
            NumberingFormat numberingFormat2 = new NumberingFormat() { NumberFormatId = (UInt32Value)166U, FormatCode = "#,##0.000\"р.\"" };
            NumberingFormat numberingFormat3 = new NumberingFormat() { NumberFormatId = (UInt32Value)167U, FormatCode = "#,##0\"р.\"" }; //"#,##0.00\"р.\"" };
            NumberingFormat numberingFormat4 = new NumberingFormat() { NumberFormatId = (UInt32Value)168U, FormatCode = "#,##0.00\"р.\"" };

            numberingFormats1.Append(numberingFormat1);
            numberingFormats1.Append(numberingFormat2);
            numberingFormats1.Append(numberingFormat3);
            numberingFormats1.Append(numberingFormat4);

            CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)6U };
            CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U }; // Формат № 0 по умолчанию общий
            CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)164U }; // Формат № 1 для дат FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy"
            CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)166U }; //формат № 2 для денег по тысяч. ###,### <-- (number/ 1000)
            CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)14U }; //формат № 3 для дат * 14.03.2015
            CellFormat cellFormat6 = new CellFormat() { NumberFormatId = (UInt32Value)2U }; //формат № 4 для чисел
            CellFormat cellFormat7 = new CellFormat() { NumberFormatId = (UInt32Value)1U }; //более подходящий формат № 5U для чисел (5U)
            CellFormat cellFormat8 = new CellFormat() { NumberFormatId = (UInt32Value)165U };//формат №6U для денег по умолчанию
            CellFormat cellFormat9 = new CellFormat() { NumberFormatId = (UInt32Value)167U };// формат №7U для денег(переопределенный) по три разряда ### ### р.
            CellFormat cellFormat10 = new CellFormat() { NumberFormatId = (UInt32Value)168U };// формат №8U для денег(переопределенный) ### ###,00 р.

            cellFormats1.Append(cellFormat2);
            cellFormats1.Append(cellFormat3);
            cellFormats1.Append(cellFormat4);
            cellFormats1.Append(cellFormat5);
            cellFormats1.Append(cellFormat6);
            cellFormats1.Append(cellFormat7);
            cellFormats1.Append(cellFormat8);
            cellFormats1.Append(cellFormat9);
            cellFormats1.Append(cellFormat10);

            stylesheet.Append(numberingFormats1);
            stylesheet.Append(fonts1);
            stylesheet.Append(fills1);
            stylesheet.Append(borders1);
            stylesheet.Append(cellFormats1);

            workbookStylesPart.Stylesheet = stylesheet;
        }
Example #23
0
        private static Stylesheet CreateStylesheet()
        {
            Stylesheet stylesheet1 = new Stylesheet()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "x14ac"
                }
            };

            stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

            Fonts fonts1 = new Fonts()
            {
                Count = (UInt32Value)1U, KnownFonts = true
            };

            Font     font1     = new Font();
            FontSize fontSize1 = new FontSize()
            {
                Val = 11D
            };
            Color color1 = new Color()
            {
                Theme = (UInt32Value)1U
            };
            FontName fontName1 = new FontName()
            {
                Val = "Calibri"
            };
            FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering()
            {
                Val = 2
            };
            FontScheme fontScheme1 = new FontScheme()
            {
                Val = FontSchemeValues.Minor
            };

            font1.Append(fontSize1);
            font1.Append(color1);
            font1.Append(fontName1);
            font1.Append(fontFamilyNumbering1);
            font1.Append(fontScheme1);

            fonts1.Append(font1);

            Fills fills1 = new Fills()
            {
                Count = (UInt32Value)5U
            };

            // FillId = 0
            Fill        fill1        = new Fill();
            PatternFill patternFill1 = new PatternFill()
            {
                PatternType = PatternValues.None
            };

            fill1.Append(patternFill1);

            // FillId = 1
            Fill        fill2        = new Fill();
            PatternFill patternFill2 = new PatternFill()
            {
                PatternType = PatternValues.Gray125
            };

            fill2.Append(patternFill2);

            // FillId = 2,RED
            Fill        fill3        = new Fill();
            PatternFill patternFill3 = new PatternFill()
            {
                PatternType = PatternValues.Solid
            };
            ForegroundColor foregroundColor1 = new ForegroundColor()
            {
                Rgb = "FFFF0000"
            };
            BackgroundColor backgroundColor1 = new BackgroundColor()
            {
                Indexed = (UInt32Value)64U
            };

            patternFill3.Append(foregroundColor1);
            patternFill3.Append(backgroundColor1);
            fill3.Append(patternFill3);

            // FillId = 3,BLUE
            Fill        fill4        = new Fill();
            PatternFill patternFill4 = new PatternFill()
            {
                PatternType = PatternValues.Solid
            };
            ForegroundColor foregroundColor2 = new ForegroundColor()
            {
                Rgb = "FF0070C0"
            };
            BackgroundColor backgroundColor2 = new BackgroundColor()
            {
                Indexed = (UInt32Value)64U
            };

            patternFill4.Append(foregroundColor2);
            patternFill4.Append(backgroundColor2);
            fill4.Append(patternFill4);

            // FillId = 4,YELLO
            Fill        fill5        = new Fill();
            PatternFill patternFill5 = new PatternFill()
            {
                PatternType = PatternValues.Solid
            };
            ForegroundColor foregroundColor3 = new ForegroundColor()
            {
                Rgb = "FFFFFF00"
            };
            BackgroundColor backgroundColor3 = new BackgroundColor()
            {
                Indexed = (UInt32Value)64U
            };

            patternFill5.Append(foregroundColor3);
            patternFill5.Append(backgroundColor3);
            fill5.Append(patternFill5);

            fills1.Append(fill1);
            fills1.Append(fill2);
            fills1.Append(fill3);
            fills1.Append(fill4);
            fills1.Append(fill5);

            Borders borders1 = new Borders()
            {
                Count = (UInt32Value)1U
            };

            Border         border1         = new Border();
            LeftBorder     leftBorder1     = new LeftBorder();
            RightBorder    rightBorder1    = new RightBorder();
            TopBorder      topBorder1      = new TopBorder();
            BottomBorder   bottomBorder1   = new BottomBorder();
            DiagonalBorder diagonalBorder1 = new DiagonalBorder();

            border1.Append(leftBorder1);
            border1.Append(rightBorder1);
            border1.Append(topBorder1);
            border1.Append(bottomBorder1);
            border1.Append(diagonalBorder1);

            borders1.Append(border1);

            CellStyleFormats cellStyleFormats1 = new CellStyleFormats()
            {
                Count = (UInt32Value)1U
            };
            CellFormat cellFormat1 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U
            };

            cellStyleFormats1.Append(cellFormat1);

            CellFormats cellFormats1 = new CellFormats()
            {
                Count = (UInt32Value)4U
            };
            CellFormat cellFormat2 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U
            };
            CellFormat cellFormat3 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true
            };
            CellFormat cellFormat4 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true
            };
            CellFormat cellFormat5 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)4U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true
            };

            cellFormats1.Append(cellFormat2);
            cellFormats1.Append(cellFormat3);
            cellFormats1.Append(cellFormat4);
            cellFormats1.Append(cellFormat5);

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

            cellStyles1.Append(cellStyle1);
            DifferentialFormats differentialFormats1 = new DifferentialFormats()
            {
                Count = (UInt32Value)0U
            };
            TableStyles tableStyles1 = new TableStyles()
            {
                Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleMedium9"
            };

            StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList();

            StylesheetExtension stylesheetExtension1 = new StylesheetExtension()
            {
                Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
            };

            stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");

            stylesheetExtensionList1.Append(stylesheetExtension1);

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellStyleFormats1);
            stylesheet1.Append(cellFormats1);
            stylesheet1.Append(cellStyles1);
            stylesheet1.Append(differentialFormats1);
            stylesheet1.Append(tableStyles1);
            stylesheet1.Append(stylesheetExtensionList1);
            return(stylesheet1);
        }
Example #24
0
        public void AddLine(string s, PointF pos, Brush col, Fonts font = Fonts.ViewportLabel)
        {
            lines.Add(
                new TextEntry
                {
                    Text = s,
                    Position = pos,
                    Colour = col,
                    Font = font
                }
            );

            UpdateText();
        }
        /**
         * Constructor.  Instantiates the prerequisite list of formats and
         * styles required by all Excel workbooks
         *
         * @param f the list of Fonts
         * @param styles the list of style clones
         */
        public WritableFormattingRecords(Fonts f, Styles styles)
            : base(f)
        {
            try
            {
                // Hard code all the styles
                StyleXFRecord sxf = new StyleXFRecord
                                        (styles.getArial10Pt(), NumberFormats.DEFAULT);
                sxf.setLocked(true);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1), NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1), NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1), NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(2), NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(3), NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                sxf = new StyleXFRecord(styles.getArial10Pt(),
                                        NumberFormats.DEFAULT);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf400);
                addStyle(sxf);

                // That's the end of the built ins.  Write the normal style
                // cell XF here
                addStyle(styles.getNormalStyle());

                // Continue with "user defined" styles
                sxf = new StyleXFRecord(getFonts().getFont(1),
                                        NumberFormats.FORMAT7);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf800);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1),
                                        NumberFormats.FORMAT5);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf800);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1),
                                        NumberFormats.FORMAT8);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf800);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1),
                                        NumberFormats.FORMAT6);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf800);
                addStyle(sxf);

                sxf = new StyleXFRecord(getFonts().getFont(1),
                                        NumberFormats.PERCENT_INTEGER);
                sxf.setLocked(true);
                sxf.setCellOptions(0xf800);
                addStyle(sxf);

                // Hard code in the pre-defined number formats for now

                /*
                 * FormatRecord fr = new FormatRecord
                 * ("\"$\"#,##0_);\\(\"$\"#,##0\\)",5);
                 * addFormat(fr);
                 *
                 * fr = new FormatRecord
                 * ("\"$\"#,##0_);[Red]\\(\"$\"#,##0\\)", 6);
                 * addFormat(fr);
                 *
                 * fr = new FormatRecord
                 * ("\"$\"#,##0.00_);\\(\"$\"#,##0.00\\)", 7);
                 * addFormat(fr);
                 *
                 * fr = new FormatRecord
                 * ("\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)", 8);
                 * addFormat(fr);
                 *
                 * fr = new FormatRecord
                 * ("_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)",
                 * 0x2a);
                 * //        outputFile.write(fr);
                 *
                 * fr = new FormatRecord
                 * ("_(* #,##0_);_(* \\(#,##0\\);_(* \"-\"_);_(@_)",
                 * 0x2e);
                 * //        outputFile.write(fr);
                 *
                 * fr = new FormatRecord
                 * ("_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)",
                 * 0x2c);
                 * //        outputFile.write(fr);
                 *
                 * fr = new FormatRecord
                 * ("_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)",
                 * 0x2b);
                 * //        outputFile.write(fr);
                 */
            }
            catch (NumFormatRecordsException e)
            {
                // This should not happen yet, since we are just creating the file.
                // Bomb out
                Assert.verify(false, e.Message);
            }
        }
        /// <summary>
        /// create the default excel formats.  These formats are required for the excel in order for it to render
        /// correctly.
        /// </summary>
        /// <returns></returns>
        public Stylesheet CreateDefaultStylesheet()
        {
            Stylesheet ss = new Stylesheet();
            Fonts fts = new Fonts();
            DocumentFormat.OpenXml.Spreadsheet.Font ft = new DocumentFormat.OpenXml.Spreadsheet.Font();
            FontName ftn = new FontName();
            ftn.Val = "Calibri";
            FontSize ftsz = new FontSize();
            ftsz.Val = 11;
            ft.FontName = ftn;
            ft.FontSize = ftsz;
            fts.Append(ft);
            fts.Count = (uint)fts.ChildElements.Count;

            Fills fills = new Fills();
            Fill fill;
            PatternFill patternFill;

            //default fills used by Excel, don't changes these

            fill = new Fill();
            patternFill = new PatternFill();
            patternFill.PatternType = PatternValues.None;
            fill.PatternFill = patternFill;
            fills.AppendChild(fill);

            fill = new Fill();
            patternFill = new PatternFill();
            patternFill.PatternType = PatternValues.Gray125;
            fill.PatternFill = patternFill;
            fills.AppendChild(fill);

            fills.Count = (uint)fills.ChildElements.Count;

            Borders borders = new Borders();
            Border border = new Border();
            border.LeftBorder = new LeftBorder();
            border.RightBorder = new RightBorder();
            border.TopBorder = new TopBorder();
            border.BottomBorder = new BottomBorder();
            border.DiagonalBorder = new DiagonalBorder();
            borders.Append(border);
            borders.Count = (uint)borders.ChildElements.Count;

            CellStyleFormats csfs = new CellStyleFormats();
            CellFormat cf = new CellFormat();
            cf.NumberFormatId = 0;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            csfs.Append(cf);
            csfs.Count = (uint)csfs.ChildElements.Count;

            CellFormats cfs = new CellFormats();

            cf = new CellFormat();
            cf.NumberFormatId = 0;
            cf.FontId = 0;
            cf.FillId = 0;
            cf.BorderId = 0;
            cf.FormatId = 0;
            cfs.Append(cf);

            var nfs = new NumberingFormats();

            nfs.Count = (uint)nfs.ChildElements.Count;
            cfs.Count = (uint)cfs.ChildElements.Count;

            ss.Append(nfs);
            ss.Append(fts);
            ss.Append(fills);
            ss.Append(borders);
            ss.Append(csfs);
            ss.Append(cfs);

            CellStyles css = new CellStyles(
                new CellStyle()
                {
                    Name = "Normal",
                    FormatId = 0,
                    BuiltinId = 0,
                }
                );

            css.Count = (uint)css.ChildElements.Count;
            ss.Append(css);

            DifferentialFormats dfs = new DifferentialFormats();
            dfs.Count = 0;
            ss.Append(dfs);

            TableStyles tss = new TableStyles();
            tss.Count = 0;
            tss.DefaultTableStyle = "TableStyleMedium9";
            tss.DefaultPivotStyle = "PivotStyleLight16";
            ss.Append(tss);
            return ss;
        }
        public static Stylesheet CreateStylesheet()
        {
            var ss = new Stylesheet();

            var fts = new Fonts();
            var ftn = new FontName { Val = "Arial" };
            var ftsz = new FontSize { Val = 11 };
            var ft = new DocumentFormat.OpenXml.Spreadsheet.Font { FontName = ftn, FontSize = ftsz };
            fts.Append(ft);
            fts.Count = (uint)fts.ChildElements.Count;

            var fills = new Fills();
            var fill = new Fill();
            var patternFill = new PatternFill { PatternType = PatternValues.None };
            fill.PatternFill = patternFill;
            fills.Append(fill);

            fill = new Fill();
            patternFill = new PatternFill { PatternType = PatternValues.Gray125 };
            fill.PatternFill = patternFill;
            fills.Append(fill);

            fills.Count = (uint)fills.ChildElements.Count;

            var borders = new Borders();
            var border = new Border
            {
                LeftBorder = new LeftBorder(),
                RightBorder = new RightBorder(),
                TopBorder = new TopBorder(),
                BottomBorder = new BottomBorder(),
                DiagonalBorder = new DiagonalBorder()
            };
            borders.Append(border);
            borders.Count = (uint)borders.ChildElements.Count;

            var csfs = new CellStyleFormats();
            var cf = new CellFormat { NumberFormatId = 0, FontId = 0, FillId = 0, BorderId = 0 };
            csfs.Append(cf);
            csfs.Count = (uint)csfs.ChildElements.Count;

            // dd/mm/yyyy is also Excel style index 14

            uint iExcelIndex = 164;
            var nfs = new NumberingFormats();
            var cfs = new CellFormats();

            cf = new CellFormat { NumberFormatId = 0, FontId = 0, FillId = 0, BorderId = 0, FormatId = 0 };
            cfs.Append(cf);

            var nf = new NumberingFormat { NumberFormatId = iExcelIndex, FormatCode = "dd/mm/yyyy hh:mm:ss" };
            nfs.Append(nf);

            cf = new CellFormat
            {
                NumberFormatId = nf.NumberFormatId,
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                FormatId = 0,
                ApplyNumberFormat = true
            };
            cfs.Append(cf);

            iExcelIndex = 165;
            nfs = new NumberingFormats();
            cfs = new CellFormats();

            cf = new CellFormat { NumberFormatId = 0, FontId = 0, FillId = 0, BorderId = 0, FormatId = 0 };
            cfs.Append(cf);

            nf = new NumberingFormat { NumberFormatId = iExcelIndex, FormatCode = "MMM yyyy" };
            nfs.Append(nf);

            cf = new CellFormat
            {
                NumberFormatId = nf.NumberFormatId,
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                FormatId = 0,
                ApplyNumberFormat = true
            };
            cfs.Append(cf);

            iExcelIndex = 170;
            nf = new NumberingFormat { NumberFormatId = iExcelIndex, FormatCode = "#,##0.0000" };
            nfs.Append(nf);
            cf = new CellFormat
            {
                NumberFormatId = nf.NumberFormatId,
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                FormatId = 0,
                ApplyNumberFormat = true
            };
            cfs.Append(cf);

            // #,##0.00 is also Excel style index 4
            iExcelIndex = 171;
            nf = new NumberingFormat { NumberFormatId = iExcelIndex, FormatCode = "#,##0.00" };
            nfs.Append(nf);
            cf = new CellFormat
            {
                NumberFormatId = nf.NumberFormatId,
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                FormatId = 0,
                ApplyNumberFormat = true
            };
            cfs.Append(cf);

            // @ is also Excel style index 49
            iExcelIndex = 172;
            nf = new NumberingFormat { NumberFormatId = iExcelIndex, FormatCode = "@" };
            nfs.Append(nf);
            cf = new CellFormat
            {
                NumberFormatId = nf.NumberFormatId,
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                FormatId = 0,
                ApplyNumberFormat = true
            };
            cfs.Append(cf);

            nfs.Count = (uint)nfs.ChildElements.Count;
            cfs.Count = (uint)cfs.ChildElements.Count;

            ss.Append(nfs);
            ss.Append(fts);
            ss.Append(fills);
            ss.Append(borders);
            ss.Append(csfs);
            ss.Append(cfs);

            var css = new CellStyles();
            var cs = new CellStyle { Name = "Normal", FormatId = 0, BuiltinId = 0 };
            css.Append(cs);
            css.Count = (uint)css.ChildElements.Count;
            ss.Append(css);

            var dfs = new DifferentialFormats { Count = 0 };
            ss.Append(dfs);

            var tss = new TableStyles
            {
                Count = 0,
                DefaultTableStyle = "TableStyleMedium9",
                DefaultPivotStyle = "PivotStyleLight16"
            };
            ss.Append(tss);

            return ss;
        }
Example #28
0
        public PlottableBar(double[] xs, double[] ys, string label,
                            double barWidth, double xOffset,
                            bool fill, Color fillColor,
                            double outlineWidth, Color outlineColor,
                            double[] yErr, double errorLineWidth, double errorCapSize, Color errorColor,
                            bool horizontal, bool showValues, Color valueColor, double[] yOffsets, Color negativeColor
                            )
        {
            if (ys is null || ys.Length == 0)
            {
                throw new ArgumentException("ys must contain data values");
            }

            if (xs is null)
            {
                xs = DataGen.Consecutive(ys.Length);
            }

            if (xs.Length != ys.Length)
            {
                throw new ArgumentException("xs and ys must have same number of elements");
            }

            if (yErr is null)
            {
                yErr = DataGen.Zeros(ys.Length);
            }

            if (yErr.Length != ys.Length)
            {
                throw new ArgumentException("yErr and ys must have same number of elements");
            }

            if (yOffsets is null)
            {
                yOffsets = DataGen.Zeros(ys.Length);
            }


            this.xs           = xs;
            this.ys           = ys;
            this.yErr         = yErr;
            this.xOffset      = xOffset;
            this.label        = label;
            this.verticalBars = !horizontal;
            this.showValues   = showValues;

            this.barWidth     = barWidth;
            this.errorCapSize = errorCapSize;

            this.fill          = fill;
            this.fillColor     = fillColor;
            this.negativeColor = negativeColor;

            this.yOffsets = yOffsets;

            fillBrush  = new SolidBrush(fillColor);
            outlinePen = new Pen(outlineColor, (float)outlineWidth);
            errorPen   = new Pen(errorColor, (float)errorLineWidth);

            valueTextFont  = new Font(Fonts.GetDefaultFontName(), 12);
            valueTextBrush = new SolidBrush(valueColor);
        }
Example #29
0
        public void Initialize(Position position = Position.Center, Align textAlign = Align.Center, Fonts font = Fonts.RegularConsolas16)
        {
            _center     = new Vector2(Game.Window.ClientBounds.Width / 2, Game.Window.ClientBounds.Height / 2);
            _itemHeight = ItemsFont.MeasureString(_items[0].Text).Y;

            _maxItemWidth = 0;

            foreach (var item in _items)
            {
                var width = ItemsFont.MeasureString(item.Text).X;
                item.Size = new Point((int)width, (int)_itemHeight);
                if (width > _maxItemWidth)
                {
                    _maxItemWidth = width;
                }
            }

            _maxItemWidth *= 1.2f;

            var pos = Vector2.Zero;

            switch (position)
            {
            case Position.Top: { pos = new Vector2(_center.X, _itemHeight / 2); break; }

            case Position.Bottom: { pos = new Vector2(_center.X, Game.Window.ClientBounds.Height - _items.Count * _itemHeight + _itemHeight / 2); break; }

            case Position.Right: { pos = new Vector2(Game.Window.ClientBounds.Width - _maxItemWidth / 2, _center.Y - _items.Count / 2 * _itemHeight + _itemHeight / 2.5f); break; }

            case Position.Left: { pos = new Vector2(_maxItemWidth / 2, _center.Y - _items.Count / 2 * _itemHeight + _itemHeight / 2.5f); break; }

            case Position.Center: { pos = new Vector2(_center.X, _center.Y - _items.Count / 2 * _itemHeight + _itemHeight / 2.5f); break; }

            case Position.TopLeft: { pos = new Vector2(_maxItemWidth / 2, _itemHeight / 2); break; }

            case Position.TopRight: { pos = new Vector2(Game.Window.ClientBounds.Width - _maxItemWidth / 2, _itemHeight / 2); break; }

            case Position.BottomLeft: { pos = new Vector2(_maxItemWidth / 2, Game.Window.ClientBounds.Height - _items.Count * _itemHeight + _itemHeight / 2); break; }

            case Position.BottomRight: { pos = new Vector2(Game.Window.ClientBounds.Width - _maxItemWidth / 2, Game.Window.ClientBounds.Height - _items.Count * _itemHeight + _itemHeight / 2); break; }
            }

            foreach (var item in _items)
            {
                item.Rect = new Rectangle(
                    (int)(pos.X - _maxItemWidth / 2),
                    (int)(pos.Y - _itemHeight / 2),
                    (int)_maxItemWidth,
                    (int)_itemHeight
                    );

                pos.Y += _itemHeight;
            }

            _selectedItemRect = new Texture2D(Game.Graphics.GraphicsDevice, 1, 1);
            _selectedItemRect.SetData(new[] { Color.White });
        }
Example #30
0
 public SelectColourBox()
 {
     font = Fonts.Sans(8);
 }
Example #31
0
        private Stylesheet GenerateNumberingStylesheet()
        {
            Stylesheet stylesheet = null;
            // Create a numberingformat,

            //stylesheet.NumberingFormats = new NumberingFormats();
            NumberingFormats numberingFormats = new NumberingFormats();
            //#.##% is also Excel style index 1

            //uint iExcelIndex = 164;
            NumberingFormat nf2decimal = new NumberingFormat()
            {
                NumberFormatId = UInt32Value.FromUInt32(3453),
                FormatCode     = StringValue.FromString("0.0%")
            };

            numberingFormats.Append(nf2decimal);

            var nformat4Decimal = new NumberingFormat
            {
                //NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
                NumberFormatId = UInt32Value.FromUInt32(3500),
                FormatCode     = StringValue.FromString("#,##0.0000")
            };

            numberingFormats.Append(nformat4Decimal);

            var dateFormat = new NumberingFormat()
            {
                NumberFormatId = (UInt32Value)4000,
                FormatCode     = StringValue.FromString("dd.mm.yyyy")
            };

            numberingFormats.Append(dateFormat);


            //stylesheet.Fonts = new Fonts(
            var fonts = new Fonts(
                new Font(),
                new Font(
                    new FontSize()
            {
                Val = 10
            },
                    new Bold()
                    )
                );
            // Create a cell format and apply the numbering format id

            CellFormats cellFormats = new CellFormats();
            var         cellFormat  = new CellFormat();

            cellFormat.FontId            = 0;
            cellFormat.FillId            = 0;
            cellFormat.BorderId          = 0;
            cellFormat.FormatId          = 0;
            cellFormat.NumberFormatId    = nf2decimal.NumberFormatId;
            cellFormat.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cellFormat.ApplyFont         = true;

            //append cell format for cells of header row
            //stylesheet.CellFormats = new CellFormats();
            cellFormats.AppendChild <CellFormat>(cellFormat);

            cellFormat                   = new CellFormat();
            cellFormat.FontId            = 0;
            cellFormat.FillId            = 0;
            cellFormat.BorderId          = 0;
            cellFormat.FormatId          = 0;
            cellFormat.NumberFormatId    = nformat4Decimal.NumberFormatId;
            cellFormat.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cellFormat.ApplyFont         = true;
            //append cell format for cells of header row
            cellFormats.AppendChild <CellFormat>(cellFormat);

            // Percentage
            cellFormat                   = new CellFormat();
            cellFormat.FontId            = 1;
            cellFormat.FillId            = 0;
            cellFormat.BorderId          = 0;
            cellFormat.FormatId          = 0;
            cellFormat.NumberFormatId    = 10;
            cellFormat.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cellFormat.ApplyFont         = true;
            //append cell format for cells of header row
            cellFormats.AppendChild <CellFormat>(cellFormat);

            // Date
            cellFormat                   = new CellFormat();
            cellFormat.FontId            = 1;
            cellFormat.FillId            = 0;
            cellFormat.BorderId          = 0;
            cellFormat.FormatId          = 0;
            cellFormat.NumberFormatId    = dateFormat.NumberFormatId;
            cellFormat.ApplyNumberFormat = BooleanValue.FromBoolean(true);
            cellFormat.ApplyFont         = true;
            //append cell format for cells of header row
            cellFormats.AppendChild <CellFormat>(cellFormat);

            Fills   fills   = new Fills(new Fill());
            Borders borders = new Borders(new Border());

            stylesheet = new Stylesheet(fonts, fills, borders, cellFormats);//, numberingFormats);
            stylesheet.NumberingFormats = numberingFormats;

            //update font count
            stylesheet.CellFormats.Count = UInt32Value.FromUInt32((uint)stylesheet.CellFormats.ChildElements.Count);

            return(stylesheet);
        }
Example #32
0
        public override void PrepareStream(Size pageSize, List <Font> fonts, bool compress)
        {
            var result      = "";
            var contentFont = fonts.Find(f => f.FontName == FontFace);

            var lineHeight = FontSize;

            if (LineHeight != 0)
            {
                lineHeight = LineHeight;
            }

            var textHeight = Height;
            var textWidth  = Width;

            if (textWidth == 0)
            {
                // the text hasn't been constrained to a specific width so calculate that constraint
                // based on alignment and position.
                switch (TextAlignment)
                {
                case Alignment.Center:
                    // the width is the lesser value of the current X position and the
                    // distance to either the left or right page content limits doubled
                    textWidth = ((pageSize.ContentWidth - PosX) < PosX ? (pageSize.ContentWidth - PosX) : PosX) * 2;
                    break;

                case Alignment.Right:
                    // the width is the current X Position;
                    textWidth = (PosX);
                    break;

                case Alignment.Left:
                    // the width is the difference between the current X Position and the width of the page;
                    textWidth = (pageSize.ContentWidth - PosX);
                    break;
                }
            }

            // now split the strings at their line breaks and process each paragraph so that it fits within the width
            var textLines    = Text.Split("\n");
            var adjustedText = "";
            var calcHeight   = 0;
            var isbold       = false;
            var isitalic     = false;

            for (var l = 0; l < textLines.Length; l++)
            {
                // split each line into words
                var lineWords = textLines[l].Split(" ");
                var width     = 0;
                for (var num = 0; num < lineWords.Length; num++)
                {
                    if (num + 1 < lineWords.Length)
                    {
                        lineWords[num] += " ";
                    }

                    var style = "";
                    var word  = lineWords[num].ToLower();
                    if (word.Contains("<b>"))
                    {
                        isbold = true;
                        if (isitalic)
                        {
                            style = "{{BI}}";
                        }
                        else
                        {
                            style = "{{B}}";
                        }
                    }
                    if (word.Contains("<i>"))
                    {
                        isitalic = true;
                        if (isbold)
                        {
                            style = "{{BI}}";
                        }
                        else
                        {
                            style = "{{I}}";
                        }
                    }

                    var pureWord = lineWords[num].Replace("<b>", "");
                    pureWord = pureWord.Replace("<B>", "");
                    pureWord = pureWord.Replace("<i>", "");
                    pureWord = pureWord.Replace("<I>", "");
                    pureWord = pureWord.Replace("</b>", "");
                    pureWord = pureWord.Replace("</B>", "");
                    pureWord = pureWord.Replace("</i>", "");
                    pureWord = pureWord.Replace("</I>", "");


                    // if the word was only the bold or italic tag then loop to the next word
                    if (!string.IsNullOrEmpty(lineWords[num]))
                    {
                        // determine the font that should be used to calculate the width
                        var font = Fonts.Font(contentFont.BaseFont, isbold, isitalic);

                        var wordWidth = StringLength(pureWord, FontSize, font);
                        if (width + wordWidth > textWidth)
                        {
                            // this word will take us over the edge so get rid of the trailing space and add a linebreak
                            adjustedText  = adjustedText.Substring(0, adjustedText.Length - 1);
                            adjustedText += "\n";
                            calcHeight   += lineHeight;
                            width         = 0;
                        }

                        if (textHeight == 0 || calcHeight < textHeight)
                        {
                            // this text is still within the box height it's ok to keep adding words
                            adjustedText += (style + pureWord);
                            style         = "";
                            width        += wordWidth;
                        }
                    }

                    if (word.Contains("</b>"))
                    {
                        if (isitalic)
                        {
                            style = "{{/BI}}{{I}}";
                        }
                        else
                        {
                            style = "{{/B}}";
                        }
                        isbold = false;
                    }
                    if (word.Contains("</i>"))
                    {
                        if (isbold)
                        {
                            style = "{{/BI}}{{B}}";
                        }
                        else
                        {
                            style = "{{/I}}";
                        }
                        isitalic = false;
                    }

                    if (!string.IsNullOrEmpty(style))
                    {
                        adjustedText += style;
                    }
                }

                if (l + 1 < textLines.Length)
                {
                    // Add the newline character back since this is where it used to be
                    adjustedText += "\n";
                }
                calcHeight += lineHeight;
            }

            result  = "BT\n";
            result += string.Format("/{0} {1} Tf\n", contentFont.Id, FontSize);

            result += string.Format("{0} TL\n", lineHeight);

            if (!string.IsNullOrEmpty(Color))
            {
                result += string.Format("{0} rg\n", ToPDFColor(Color));
            }
            else
            {
                result += "0 0 0 rg\n";
            }

            textLines = adjustedText.Split("\n");
            var count        = 0;
            var curX         = PosX;
            var curY         = PosY;
            var stringLength = 0;

            foreach (var line in textLines)
            {
                var prevLength = stringLength;

                var pureLine = line.Replace("{{B}}", "");
                pureLine = pureLine.Replace("{{I}}", "");
                pureLine = pureLine.Replace("{{BI}}", "");
                pureLine = pureLine.Replace("{{/B}}", "");
                pureLine = pureLine.Replace("{{/I}}", "");
                pureLine = pureLine.Replace("{{/BI}}", "");

                // TODO: apply the formatting to properly determine the length of the line.
                stringLength = StringLength(pureLine, FontSize, contentFont);

                count++;
                if (count > 1)
                {
                    curY = 0 - lineHeight;
                }

                switch (TextAlignment)
                {
                case Alignment.Center:
                    if (count == 1)
                    {
                        curX = PosX - (stringLength / 2);
                    }
                    else
                    {
                        curX = (prevLength - stringLength) / 2;
                    }

                    break;

                case Alignment.Right:
                    if (count == 1)
                    {
                        curX = (PosX - stringLength);
                    }
                    else
                    {
                        curX = (prevLength - stringLength);
                    }

                    break;

                case Alignment.Left:
                    if (count > 1)
                    {
                        curX = 0;
                    }

                    break;
                }

                result += string.Format("{0} {1} Td\n", curX, curY);

                // now we are ready to output the line we need to replace the PDF special characters with the their escaped equivalents
                //'(', '/' and ')' are escape characters in adobe so remove them - page 30 of adobe doco.

                var output = line.Replace("\\", "\\\\");
                output = output.Replace("(", "\\(");
                output = output.Replace(")", "\\)");

                // also need to replace any {{bold/italic}} tags with their PDF equivalents

                output = output.Replace("{{B}}", string.Format(") Tj\n/{0} {1} Tf\n(", fonts.Find(f => f.BaseFont == contentFont.BaseFont && f.Bold && !f.Italic).Id, FontSize));
                output = output.Replace("{{I}}", string.Format(") Tj\n/{0} {1} Tf\n(", fonts.Find(f => f.BaseFont == contentFont.BaseFont && !f.Bold && f.Italic).Id, FontSize));
                output = output.Replace("{{BI}}", string.Format(") Tj\n/{0} {1} Tf\n(", fonts.Find(f => f.BaseFont == contentFont.BaseFont && f.Bold && f.Italic).Id, FontSize));
                output = output.Replace("{{/B}}", string.Format(") Tj\n/{0} {1} Tf\n(", contentFont.Id, FontSize));
                output = output.Replace("{{/I}}", string.Format(") Tj\n/{0} {1} Tf\n(", contentFont.Id, FontSize));
                output = output.Replace("{{/BI}}", string.Format(") Tj\n/{0} {1} Tf\n(", contentFont.Id, FontSize));

                result += string.Format("({0}) Tj\n", output);
            }

            result += "ET";

            _encodedData = Encoding.UTF8.GetBytes(result);

            base.PrepareStream(compress);
        }
Example #33
0
        public override void onDraw(Graphics g)
        {
            int baseY = 5;

            foreach (AItem i in Singleton.player.itemList)
            {
                g.DrawString(i.itemName + ": " + Math.Round(i.remainingDuration, 2), Fonts.getFont("Arial", 8), Fonts.getSolidBrush(Color.Black), new Vector2(200, baseY));
                baseY += 12;
            }
        }
Example #34
0
        public ContentEditor_Text(DataStore dataStore, SelectButton control)
        {
            InitializeComponent();

            data = dataStore;
            cont = control;

            TB_Text.Text           = cont.Content.ToString();
            ComboBox_FontSize.Text = "" + cont.FontSize;
            TB_MarginLeft.Text     = "" + cont.Margin.Left;

            if (cont.Foreground is SolidColorBrush)
            {
                Rect_BackColor.Fill = cont.Foreground;
            }


            if (cont.FontWeight == FontWeights.Bold)
            {
                SButton_Bold.SetCheckedNoCall(true);
            }

            if (cont.FontStyle == FontStyles.Italic)
            {
                SButton_Italic.SetCheckedNoCall(true);
            }

            try
            {
                ComboBox_FontName.Text = cont.FontFamily.ToString();


                if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GoodTeacher\\Temp\\"))
                {
                    foreach (System.Windows.Media.FontFamily fm in Fonts.GetFontFamilies(new Uri(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GoodTeacher\\Temp\\")))
                    {
                        Label labelf = new Label();
                        labelf.Content    = fm.ToString().Substring(3);
                        labelf.FontFamily = fm;
                        labelf.FontSize   = 14;
                        labelf.ToolTip    = fm.ToString();
                        labelf.Foreground = new SolidColorBrush(Color.FromRgb(19, 87, 48));
                        ComboBox_FontName.Items.Add(labelf);
                    }
                }


                foreach (System.Windows.Media.FontFamily fm in Fonts.SystemFontFamilies)
                {
                    Label labelf = new Label();
                    labelf.Content    = fm;
                    labelf.FontFamily = fm;
                    labelf.FontSize   = 14;
                    labelf.ToolTip    = fm.ToString();
                    ComboBox_FontName.Items.Add(labelf);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Font not found: " + ex);
            }
        }
Example #35
0
        /// <summary>
        /// create the default excel formats.  These formats are required for the excel in order for it to render
        /// correctly.
        /// </summary>
        /// <returns></returns>
        private Stylesheet CreateDefaultStylesheet()
        {
            Stylesheet ss = new Stylesheet();

            Fonts fts = new Fonts();

            DocumentFormat.OpenXml.Spreadsheet.Font ft = new DocumentFormat.OpenXml.Spreadsheet.Font();
            FontName ftn = new FontName();

            ftn.Val = "Calibri";
            FontSize ftsz = new FontSize();

            ftsz.Val    = 11;
            ft.FontName = ftn;
            ft.FontSize = ftsz;
            fts.Append(ft);
            fts.Count = (uint)fts.ChildElements.Count;

            Fills       fills = new Fills();
            Fill        fill;
            PatternFill patternFill;

            //default fills used by Excel, don't changes these

            fill                    = new Fill();
            patternFill             = new PatternFill();
            patternFill.PatternType = PatternValues.None;
            fill.PatternFill        = patternFill;
            fills.AppendChild(fill);

            fill                    = new Fill();
            patternFill             = new PatternFill();
            patternFill.PatternType = PatternValues.Gray125;
            fill.PatternFill        = patternFill;
            fills.AppendChild(fill);



            fills.Count = (uint)fills.ChildElements.Count;

            Borders borders = new Borders();
            Border  border  = new Border();

            border.LeftBorder     = new LeftBorder();
            border.RightBorder    = new RightBorder();
            border.TopBorder      = new TopBorder();
            border.BottomBorder   = new BottomBorder();
            border.DiagonalBorder = new DiagonalBorder();
            borders.Append(border);
            borders.Count = (uint)borders.ChildElements.Count;

            CellStyleFormats csfs = new CellStyleFormats();
            CellFormat       cf   = new CellFormat();

            cf.NumberFormatId = 0;
            cf.FontId         = 0;
            cf.FillId         = 0;
            cf.BorderId       = 0;
            csfs.Append(cf);
            csfs.Count = (uint)csfs.ChildElements.Count;


            CellFormats cfs = new CellFormats();

            cf = new CellFormat();
            cf.NumberFormatId = 0;
            cf.FontId         = 0;
            cf.FillId         = 0;
            cf.BorderId       = 0;
            cf.FormatId       = 0;
            cfs.Append(cf);



            var nfs = new NumberingFormats();



            nfs.Count = (uint)nfs.ChildElements.Count;
            cfs.Count = (uint)cfs.ChildElements.Count;

            ss.Append(nfs);
            ss.Append(fts);
            ss.Append(fills);
            ss.Append(borders);
            ss.Append(csfs);
            ss.Append(cfs);

            CellStyles css = new CellStyles(
                new CellStyle()
            {
                Name      = "Normal",
                FormatId  = 0,
                BuiltinId = 0,
            }
                );

            css.Count = (uint)css.ChildElements.Count;
            ss.Append(css);

            DifferentialFormats dfs = new DifferentialFormats();

            dfs.Count = 0;
            ss.Append(dfs);

            TableStyles tss = new TableStyles();

            tss.Count             = 0;
            tss.DefaultTableStyle = "TableStyleMedium9";
            tss.DefaultPivotStyle = "PivotStyleLight16";
            ss.Append(tss);
            return(ss);
        }
Example #36
0
        public TabletDebugger()
        {
            Title = "Tablet Debugger";

            var debugger = new StackLayout
            {
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                Height  = 400,
                Padding = 5,
                Spacing = 5,
                Items   =
                {
                    new DebuggerGroup
                    {
                        Text    = "Device",
                        Content = deviceName = new Label
                        {
                            Font = Fonts.Monospace(10)
                        }
                    },
                    new StackLayoutItem
                    {
                        Expand  = true,
                        Control = new StackLayout
                        {
                            Orientation = Orientation.Horizontal,
                            VerticalContentAlignment = VerticalAlignment.Stretch,
                            Items =
                            {
                                new StackLayoutItem
                                {
                                    Expand  = true,
                                    Control = new DebuggerGroup
                                    {
                                        Text    = "Raw Tablet Data",
                                        Content = rawTablet = new Label
                                        {
                                            Font = Fonts.Monospace(10)
                                        }
                                    }
                                },
                                new StackLayoutItem
                                {
                                    Expand  = true,
                                    Control = new DebuggerGroup
                                    {
                                        Text    = "Tablet Report",
                                        Content = tablet = new Label
                                        {
                                            Font = Fonts.Monospace(10)
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new DebuggerGroup
                    {
                        Text    = "Report Rate",
                        Content = reportRate = new Label
                        {
                            Font = Fonts.Monospace(10)
                        }
                    },
                    new StackLayoutItem
                    {
                        Control = new StackLayout
                        {
                            Orientation = Orientation.Horizontal,
                            VerticalContentAlignment = VerticalAlignment.Bottom,
                            Items =
                            {
                                new StackLayoutItem
                                {
                                    Expand  = true,
                                    Control = new DebuggerGroup
                                    {
                                        Text    = "Reports Recorded",
                                        Content = reportsRecorded = new Label
                                        {
                                            Font = Fonts.Monospace(10)
                                        }
                                    }
                                },
                                new Group
                                {
                                    Text    = "Options",
                                    Content = enableDataRecording = new CheckBox
                                    {
                                        Text = "Enable Data Recording"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            this.Content = new Splitter
            {
                Orientation = Orientation.Vertical,
                Width       = 640,
                Height      = 800,
                FixedPanel  = SplitterFixedPanel.Panel2,
                Panel1      = new DebuggerGroup
                {
                    Text    = "Visualizer",
                    Content = tabletVisualizer = new TabletVisualizer()
                },
                Panel2 = debugger
            };

            var reportBinding = ReportDataBinding.Child(c => (c.ToObject() as IDeviceReport));

            deviceName.TextBinding.Bind(ReportDataBinding.Child(c => c.Tablet.Properties.Name));
            rawTablet.TextBinding.Bind(reportBinding.Child(c => ReportFormatter.GetStringRaw(c)));
            tablet.TextBinding.Bind(reportBinding.Child(c => ReportFormatter.GetStringFormat(c)));
            reportRate.TextBinding.Bind(ReportPeriodBinding.Convert(c => Math.Round(1000.0 / c) + "hz"));
            reportsRecorded.TextBinding.Bind(NumberOfReportsRecordedBinding.Convert(c => c.ToString()));
            tabletVisualizer.ReportDataBinding.Bind(ReportDataBinding);

            Application.Instance.AsyncInvoke(() =>
            {
                App.Driver.AddConnectionHook(ConnectionHook);
            });

            var outputStream = File.OpenWrite(Path.Join(AppInfo.Current.AppDataDirectory, "tablet-data.txt"));

            dataRecordingOutput = new StreamWriter(outputStream);
        }
Example #37
0
        IEnumerable <DrawInfo> GetDrawInfo()
        {
            yield return(new DrawInfo {
                Font = new Font(SystemFont.Default), Text = "System Font & Size"
            });

            yield return(new DrawInfo {
                Font = new Font(SystemFont.Default, 20), Text = "System Font, 20pt"
            });

            yield return(new DrawInfo {
                Font = Fonts.Sans(12)
            });

            yield return(new DrawInfo {
                Font = Fonts.Serif(12)
            });

            yield return(new DrawInfo {
                Font = Fonts.Monospace(12)
            });

            yield return(new DrawInfo {
                Font = Fonts.Cursive(12)
            });

            yield return(new DrawInfo {
                Font = Fonts.Fantasy(12)
            });

            yield return(new DrawInfo {
                Font = Fonts.Sans(12, FontStyle.Bold)
            });

            yield return(new DrawInfo {
                Font = Fonts.Serif(12, FontStyle.Bold)
            });

            yield return(new DrawInfo {
                Font = Fonts.Monospace(12, FontStyle.Bold)
            });

            yield return(new DrawInfo {
                Font = Fonts.Cursive(12, FontStyle.Bold)
            });

            yield return(new DrawInfo {
                Font = Fonts.Fantasy(12, FontStyle.Bold)
            });

            yield return(new DrawInfo {
                Font = Fonts.Sans(12, FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Serif(12, FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Monospace(12, FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Cursive(12, FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Fantasy(12, FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Sans(12, FontStyle.Bold | FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Serif(12, FontStyle.Bold | FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Monospace(12, FontStyle.Bold | FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Cursive(12, FontStyle.Bold | FontStyle.Italic)
            });

            yield return(new DrawInfo {
                Font = Fonts.Fantasy(12, FontStyle.Bold | FontStyle.Italic)
            });
        }
        private static Stylesheet SetDefault()
        {
            //Fonts
            var fonts = new Fonts();

            var font0     = new Font();
            var fontSize0 = new FontSize {
                Val = 10
            };

            font0.AppendChild(fontSize0);

            var font1     = new Font();
            var fontSize1 = new FontSize {
                Val = 12
            };
            var fontBold1  = new Bold();
            var fontColor1 = new Color {
                Rgb = "FFFFFF"
            };

            font1.AppendChild(fontSize1);
            font1.AppendChild(fontBold1);
            font1.AppendChild(fontColor1);

            fonts.AppendChild(font0);
            fonts.AppendChild(font1);

            // Alignments
            var alignmentCenter = new Alignment();

            alignmentCenter.Horizontal = HorizontalAlignmentValues.Center;

            //Fill
            var fills = new Fills();

            var fill0        = new Fill();
            var patternFill0 = new PatternFill {
                PatternType = PatternValues.None
            };

            fill0.Append(patternFill0);

            var fillSkip        = new Fill(); // Not valid needs to skip
            var patternFillSkip = new PatternFill {
                PatternType = PatternValues.None
            };

            fillSkip.Append(patternFillSkip);

            var fill1        = new Fill();
            var patternFill1 = new PatternFill {
                PatternType = PatternValues.Solid
            };
            var foregroundColor1 = new ForegroundColor {
                Rgb = "00000000"
            };
            var backgroundColor1 = new BackgroundColor {
                Indexed = 64U
            };

            patternFill1.Append(foregroundColor1);
            patternFill1.Append(backgroundColor1);
            fill1.Append(patternFill1);

            fills.Append(fill0);
            fills.Append(fillSkip);
            fills.Append(fill1);

            //Border
            var borders = new Borders();

            var border0 = new Border();
            var border1 = new Border();

            borders.AppendChild(border0);
            borders.AppendChild(border1);

            var cellFormats = new CellFormats(
                new CellFormat {
                FontId = 0, FillId = 0, BorderId = 0, ApplyFill = true
            },                                                                   // Index 0
                new CellFormat {
                FontId = 1, FillId = 2, BorderId = 1, ApplyFill = true, Alignment = alignmentCenter
            }                                                                                                // Index 1
                );

            return(new Stylesheet(fonts, fills, borders, cellFormats));
        }
        //описвывает форматы ячеек
        protected void GenWorkbookStylesPart(WorkbookStylesPart workbookStylesPart)
        {
            Stylesheet stylesheet = new Stylesheet();

            Fonts fonts1 = new Fonts();

            Font font1 = new Font();

            Font     font2     = new Font();
            FontSize fontSize2 = new FontSize()
            {
                Val = 11D
            };
            Color color1 = new Color()
            {
                Rgb = "FF00B050"
            };
            FontName fontName2 = new FontName()
            {
                Val = "Calibri"
            };
            FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering()
            {
                Val = 2
            };
            FontCharSet fontCharSet1 = new FontCharSet()
            {
                Val = 204
            };

            font2.Append(fontSize2);
            font2.Append(color1);
            font2.Append(fontName2);
            font2.Append(fontFamilyNumbering1);
            font2.Append(fontCharSet1);

            //fonts1.Append(font2);
            fonts1.Append(font1);


            Fills       fills1       = new Fills();
            Fill        fill1        = new Fill();
            Fill        fill2        = new Fill();
            Fill        fill3        = new Fill();
            PatternFill patternFill3 = new PatternFill()
            {
                PatternType = PatternValues.Solid
            };

            ForegroundColor foregroundColor1 = new ForegroundColor()
            {
                Rgb = "0000FF"
            };

            patternFill3.Append(foregroundColor1);
            fill3.Append(patternFill3);
            fills1.Append(fill1);
            fills1.Append(fill2);
            fills1.Append(fill3);

            Borders borders1 = new Borders();
            Border  border1  = new Border();

            borders1.Append(border1);

            //Переопределяем номера формата 164U, 166U, 167U, 168U,
            NumberingFormats numberingFormats1 = new NumberingFormats()
            {
                Count = (UInt32Value)3U
            };
            NumberingFormat numberingFormat1 = new NumberingFormat()
            {
                NumberFormatId = (UInt32Value)164U, FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy"
            };
            NumberingFormat numberingFormat2 = new NumberingFormat()
            {
                NumberFormatId = (UInt32Value)166U, FormatCode = "#,##0.000\"р.\""
            };
            NumberingFormat numberingFormat3 = new NumberingFormat()
            {
                NumberFormatId = (UInt32Value)167U, FormatCode = "#,##0\"р.\""
            };                                                                                                                           //"#,##0.00\"р.\"" };
            NumberingFormat numberingFormat4 = new NumberingFormat()
            {
                NumberFormatId = (UInt32Value)168U, FormatCode = "#,##0.00\"р.\""
            };

            numberingFormats1.Append(numberingFormat1);
            numberingFormats1.Append(numberingFormat2);
            numberingFormats1.Append(numberingFormat3);
            numberingFormats1.Append(numberingFormat4);

            CellFormats cellFormats1 = new CellFormats()
            {
                Count = (UInt32Value)6U
            };
            CellFormat cellFormat2 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U
            };                                                                              // Формат № 0 по умолчанию общий
            CellFormat cellFormat3 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)164U
            };                                                                                // Формат № 1 для дат FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy"
            CellFormat cellFormat4 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)166U
            };                                                                                //формат № 2 для денег по тысяч. ###,### <-- (number/ 1000)
            CellFormat cellFormat5 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)14U
            };                                                                               //формат № 3 для дат * 14.03.2015
            CellFormat cellFormat6 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)2U
            };                                                                              //формат № 4 для чисел
            CellFormat cellFormat7 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)1U
            };                                                                              //более подходящий формат № 5U для чисел (5U)
            CellFormat cellFormat8 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)165U
            };                                                                               //формат №6U для денег по умолчанию
            CellFormat cellFormat9 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)167U
            };                                                                               // формат №7U для денег(переопределенный) по три разряда ### ### р.
            CellFormat cellFormat10 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)168U
            };                                                                                // формат №8U для денег(переопределенный) ### ###,00 р.

            cellFormats1.Append(cellFormat2);
            cellFormats1.Append(cellFormat3);
            cellFormats1.Append(cellFormat4);
            cellFormats1.Append(cellFormat5);
            cellFormats1.Append(cellFormat6);
            cellFormats1.Append(cellFormat7);
            cellFormats1.Append(cellFormat8);
            cellFormats1.Append(cellFormat9);
            cellFormats1.Append(cellFormat10);

            stylesheet.Append(numberingFormats1);
            stylesheet.Append(fonts1);
            stylesheet.Append(fills1);
            stylesheet.Append(borders1);
            stylesheet.Append(cellFormats1);

            workbookStylesPart.Stylesheet = stylesheet;
        }
Example #40
0
        public void initializeAll()
        {
            //contextMenus
            addFrame = new MenuItem()
            {
                Header = "Add empty frame"
            }; addFrame.Click += addNextFrame_Click;
            addRootFrame       = new MenuItem()
            {
                Header = "Add empty frame"
            }; addRootFrame.Click += addNextFrame_Click;
            convertToFrame         = new MenuItem()
            {
                Header = "➤Frame"
            }; convertToFrame.Click += convertToFrame_Click;
            convertToMenu            = new MenuItem()
            {
                Header = "➤Menu"
            }; convertToMenu.Click += convertToMenu_Click;
            convertToPause          = new MenuItem()
            {
                Header = "➤Pause"
            }; convertToPause.Click += convertToPause_Click;
            deleteFrame              = new MenuItem()
            {
                Header = "Delete frame/menu"
            }; deleteFrame.Click += deleteFrame_Click;
            addMenu = new MenuItem()
            {
                Header = "Add menu"
            }; addMenu.Click += addNextFrame_Click;
            addPause          = new MenuItem()
            {
                Header = "Add pause"
            }; addPause.Click += addNextFrame_Click;
            addImage           = new MenuItem()
            {
                Header = "Add image"
            }; addImage.Click += imageImport_Click;
            reloadImage        = new MenuItem()
            {
                Header = "Reload image"
            }; reloadImage.Click += imageReload_Click;
            deleteImage           = new MenuItem()
            {
                Header = "Delete image"
            }; deleteImage.Click += imageDeleteFromList_Click;
            addAudio              = new MenuItem()
            {
                Header = "Add audio"
            }; addAudio.Click += audioImport_Click;
            reloadAudio        = new MenuItem()
            {
                Header = "Reload audio"
            }; reloadAudio.Click += audioReload_Click;
            deleteAudio           = new MenuItem()
            {
                Header = "Delete audio"
            }; deleteAudio.Click += audioDeleteFromList_Click;
            addMovie              = new MenuItem()
            {
                Header = "Add movie"
            }; addMovie.Click += movieImport_Click;
            reloadMovie        = new MenuItem()
            {
                Header = "Reload movie"
            }; reloadMovie.Click += movieReload_Click;
            deleteMovie           = new MenuItem()
            {
                Header = "Delete movie"
            }; deleteMovie.Click += deleteVideo_Click;
            addIcon = new MenuItem()
            {
                Header = "Add icon"
            }; addIcon.Click += imageImport_Click;
            reloadIcon        = new MenuItem()
            {
                Header = "Reload icon"
            }; reloadIcon.Click += imageReload_Click;
            deleteIcon           = new MenuItem()
            {
                Header = "Delete icon"
            }; deleteIcon.Click += imageDeleteFromList_Click;

            cmFrame = new ContextMenu {
                ItemsSource = new MenuItem[] { addRootFrame, convertToFrame, convertToMenu, convertToPause, deleteFrame }
            };
            cmLabel = new ContextMenu {
                ItemsSource = new MenuItem[] { addFrame, addMenu, addPause }
            };
            cmImage = new ContextMenu {
                ItemsSource = new MenuItem[] { addImage, reloadImage, deleteImage }
            };
            cmAudio = new ContextMenu {
                ItemsSource = new MenuItem[] { addAudio, reloadAudio, deleteAudio }
            };
            cmMovie = new ContextMenu {
                ItemsSource = new MenuItem[] { addMovie, reloadMovie, deleteMovie }
            };
            cmIcon = new ContextMenu {
                ItemsSource = new MenuItem[] { addIcon, reloadIcon, deleteIcon }
            };

            //menuOptions
            jumpAction = new ComboBoxItem()
            {
                Content = "jump"
            };
            callAction = new ComboBoxItem()
            {
                Content = "call"
            };
            passAction = new ComboBoxItem()
            {
                Content = "pass"
            };
            menuActions.Add(jumpAction);
            menuActions.Add(callAction);
            menuActions.Add(passAction);

            //image animations
            animationInTypeComboBox.ItemsSource  = animationIn;
            animationOutTypeComboBox.ItemsSource = animationOut;

            charNone.Selected            += uneditableCharacter_Selected;
            charNvl.Selected             += uneditableCharacter_Selected;
            charCentered.Selected        += uneditableCharacter_Selected;
            charExtend.Selected          += uneditableCharacter_Selected;
            charNone.CharView.Content     = "none";
            charNvl.CharView.Content      = "nvl";
            charCentered.CharView.Content = "centered";
            charExtend.CharView.Content   = "extend";
            characterSelector.Items.Add(charNone.CharView);
            characterSelector.Items.Add(charNvl.CharView);
            characterSelector.Items.Add(charCentered.CharView);
            characterSelector.Items.Add(charExtend.CharView);

            characterListView.ItemsSource = characterList;
            //characterSelector.ItemsSource = characterListView.Items;

            //project folder, start and characters
            emptyProject();

            //options
            title.Text = "default";
            gameOpenTransition.ItemsSource   = animationIn; gameOpenTransition.SelectedIndex = 1;
            gameExitTransition.ItemsSource   = animationOut; gameExitTransition.SelectedIndex = 1;
            gameStartTransition.ItemsSource  = animationIn; gameStartTransition.SelectedIndex = 0;
            gameIntraTransition.ItemsSource  = animationIn.Intersect(animationOut); gameIntraTransition.SelectedIndex = 1;
            gameEndTransition.ItemsSource    = animationOut; gameEndTransition.SelectedIndex = 0;
            dialogShowTransition.ItemsSource = animationIn; dialogShowTransition.SelectedIndex = 1;
            dialogHideTransition.ItemsSource = animationOut; dialogHideTransition.SelectedIndex = 1;

            //gui: fonts
            fonts = new List <ComboBoxItem> {
            };
            FileInfo[] fontFiles = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.Fonts)).GetFiles();
            foreach (FileInfo font in fontFiles)
            {
                if (Fonts.GetFontFamilies(font.FullName).Count != 0)
                {
                    Typeface type = Fonts.GetTypefaces(font.FullName).First();
                    string   style = ""; string weight = ""; string stretch = "";
                    if (type.Style != FontStyles.Normal)
                    {
                        style = " " + type.Style.ToString();
                    }
                    if (type.Weight != FontWeights.Normal)
                    {
                        weight = " " + type.Weight.ToString();
                    }
                    if (type.Stretch != FontStretches.Normal)
                    {
                        stretch = " " + type.Stretch.ToString();
                    }
                    ComboBoxItem newFont = new ComboBoxItem()
                    {
                        Content     = type.FontFamily.Source.Substring(type.FontFamily.Source.IndexOf('#') + 1) + style + weight + stretch,
                        FontFamily  = type.FontFamily,
                        FontStyle   = type.Style,
                        FontWeight  = type.Weight,
                        FontStretch = type.Stretch,
                        Tag         = font.Name
                    };
                    fonts.Add(newFont);
                }
            }
            comboBox_FontText.ItemsSource      = fonts;
            comboBox_FontChar.ItemsSource      = fonts;
            comboBox_FontInterface.ItemsSource = fonts;
            ComboBoxItem selectedfont = fonts.FirstOrDefault(font => font.Content.ToString().Equals("DejaVu Sans"));

            comboBox_FontText.SelectedItem      = selectedfont;
            comboBox_FontChar.SelectedItem      = selectedfont;
            comboBox_FontInterface.SelectedItem = selectedfont;

            //media:DispatcherTimer
            disptimer.Tick    += new EventHandler(mediaCurrentTime_Tick);
            disptimer.Interval = new TimeSpan(0, 0, 1);
        }
        /// <summary>
        /// Настройка стилей для файла
        /// </summary>
        /// <param name="workbookpart"></param>
        private static void CreateStyles(WorkbookPart workbookpart)
        {
            WorkbookStylesPart sp = workbookpart.AddNewPart <WorkbookStylesPart>();

            sp.Stylesheet = new Stylesheet();

            Fonts fonts = new Fonts()
            {
                Count = (UInt32Value)2U, KnownFonts = true
            };

            Font fontUsual = new Font();

            fontUsual.Append(new FontSize()
            {
                Val = 12D
            });
            fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
            {
                Theme = (UInt32Value)1U
            });
            fontUsual.Append(new FontName()
            {
                Val = "Times New Roman"
            });
            fontUsual.Append(new FontFamilyNumbering()
            {
                Val = 2
            });
            fontUsual.Append(new FontScheme()
            {
                Val = FontSchemeValues.Minor
            });

            Font fontTitle = new Font();

            fontTitle.Append(new Bold());
            fontTitle.Append(new FontSize()
            {
                Val = 14D
            });
            fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
            {
                Theme = (UInt32Value)1U
            });
            fontTitle.Append(new FontName()
            {
                Val = "Times New Roman"
            });
            fontTitle.Append(new FontFamilyNumbering()
            {
                Val = 2
            });
            fontTitle.Append(new FontScheme()
            {
                Val = FontSchemeValues.Minor
            });

            fonts.Append(fontUsual);
            fonts.Append(fontTitle);

            Fills fills = new Fills()
            {
                Count = (UInt32Value)2U
            };

            Fill fill1 = new Fill();

            fill1.Append(new PatternFill()
            {
                PatternType = PatternValues.None
            });

            Fill fill2 = new Fill();

            fill2.Append(new PatternFill()
            {
                PatternType = PatternValues.Gray125
            });

            fills.Append(fill1);
            fills.Append(fill2);

            Borders borders = new Borders()
            {
                Count = (UInt32Value)2U
            };

            Border borderNoBorder = new Border();

            borderNoBorder.Append(new LeftBorder());
            borderNoBorder.Append(new RightBorder());
            borderNoBorder.Append(new TopBorder());
            borderNoBorder.Append(new BottomBorder());
            borderNoBorder.Append(new DiagonalBorder());

            Border borderThin = new Border();

            LeftBorder leftBorder = new LeftBorder()
            {
                Style = BorderStyleValues.Thin
            };

            leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
            {
                Indexed = (UInt32Value)64U
            });

            RightBorder rightBorder = new RightBorder()
            {
                Style = BorderStyleValues.Thin
            };

            rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
            {
                Indexed = (UInt32Value)64U
            });

            TopBorder topBorder = new TopBorder()
            {
                Style = BorderStyleValues.Thin
            };

            topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
            {
                Indexed = (UInt32Value)64U
            });

            BottomBorder bottomBorder = new BottomBorder()
            {
                Style = BorderStyleValues.Thin
            };

            bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
            {
                Indexed = (UInt32Value)64U
            });

            borderThin.Append(leftBorder);
            borderThin.Append(rightBorder);
            borderThin.Append(topBorder);
            borderThin.Append(bottomBorder);
            borderThin.Append(new DiagonalBorder());

            borders.Append(borderNoBorder);
            borders.Append(borderThin);

            CellStyleFormats cellStyleFormats = new CellStyleFormats()
            {
                Count = (UInt32Value)1U
            };
            CellFormat cellFormatStyle = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U
            };

            cellStyleFormats.Append(cellFormatStyle);

            CellFormats cellFormats = new CellFormats()
            {
                Count = (UInt32Value)3U
            };

            CellFormat cellFormatFont = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U,
                FormatId       = (UInt32Value)0U,
                ApplyFont      = true
            };

            CellFormat cellFormatFontAndBorder = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)1U,
                FormatId       = (UInt32Value)0U,
                ApplyFont      = true,
                ApplyBorder    = true
            };

            CellFormat cellFormatTitle = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)1U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U,
                FormatId       = (UInt32Value)0U,
                Alignment      = new Alignment()
                {
                    Vertical   = VerticalAlignmentValues.Center,
                    WrapText   = true,
                    Horizontal = HorizontalAlignmentValues.Center
                },
                ApplyFont = true
            };

            cellFormats.Append(cellFormatFont);
            cellFormats.Append(cellFormatFontAndBorder);
            cellFormats.Append(cellFormatTitle);

            CellStyles cellStyles = new CellStyles()
            {
                Count = (UInt32Value)1U
            };

            cellStyles.Append(new CellStyle()
            {
                Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U
            });

            DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats differentialFormats =
                new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats()
            {
                Count = (UInt32Value)0U
            };

            TableStyles tableStyles = new TableStyles()
            {
                Count             = (UInt32Value)0U,
                DefaultTableStyle = "TableStyleMedium2",
                DefaultPivotStyle = "PivotStyleLight16"
            };

            StylesheetExtensionList stylesheetExtensionList = new StylesheetExtensionList();

            StylesheetExtension stylesheetExtension1 = new StylesheetExtension()
            {
                Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
            };

            stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
            stylesheetExtension1.Append(new SlicerStyles()
            {
                DefaultSlicerStyle = "SlicerStyleLight1"
            });

            StylesheetExtension stylesheetExtension2 = new StylesheetExtension()
            {
                Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
            };

            stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
            stylesheetExtension2.Append(new TimelineStyles()
            {
                DefaultTimelineStyle = "TimeSlicerStyleLight1"
            });

            stylesheetExtensionList.Append(stylesheetExtension1);
            stylesheetExtensionList.Append(stylesheetExtension2);

            sp.Stylesheet.Append(fonts);
            sp.Stylesheet.Append(fills);
            sp.Stylesheet.Append(borders);
            sp.Stylesheet.Append(cellStyleFormats);
            sp.Stylesheet.Append(cellFormats);
            sp.Stylesheet.Append(cellStyles);
            sp.Stylesheet.Append(differentialFormats);
            sp.Stylesheet.Append(tableStyles);
            sp.Stylesheet.Append(stylesheetExtensionList);
        }
Example #42
0
        private static Stylesheet GenerateStylesheet()
        {
            Fonts fonts = new Fonts(
                new Font(                 // Index 0 - default
                    new FontSize()
            {
                Val = 11
            }

                    ),
                new Font(                 // Index 1 - header
                    new FontSize()
            {
                Val = 11
            },
                    new Bold()
//					new Color() { Rgb = "FFFFFF" }

                    ));

            Fills fills = new Fills(
                new Fill(new PatternFill()
            {
                PatternType = PatternValues.None
            }),                                                                                             // Index 0 - default
                new Fill(new PatternFill()
            {
                PatternType = PatternValues.Gray125
            }),                                                                                                // Index 1 - default
                new Fill(new PatternFill(new ForegroundColor {
                Rgb = new HexBinaryValue("FF92D050")
            })
            {
                PatternType = PatternValues.Solid
            }),                                                                          // Index 2 - available
                new Fill(new PatternFill(new ForegroundColor {
                Rgb = new HexBinaryValue("FFFF0000")
            })
            {
                PatternType = PatternValues.Solid
            })                                                                          // Index 3 - not available
                );

            Borders borders = new Borders(
                new Border(),                       // index 0 default
                new Border(                         // index 1 black border
                    new LeftBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new RightBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new TopBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new BottomBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new DiagonalBorder())
                );

            CellFormats cellFormats = new CellFormats(
                new CellFormat(),                         // default
                new CellFormat(
                    new Alignment()
            {
                Horizontal = HorizontalAlignmentValues.Center,
                Vertical   = VerticalAlignmentValues.Center
            })
            {
                FontId = 1, FillId = 0
            },                                                              // Headers
                new CellFormat {
                FontId = 0, FillId = 2, BorderId = 1, ApplyBorder = true, ApplyFill = true
            },                                                                                                                         // avail
                new CellFormat {
                FontId = 0, FillId = 3, BorderId = 1, ApplyBorder = true, ApplyFill = true
            },                                                                                                                         // not avail
                new CellFormat(
                    new Alignment()
            {
                Horizontal = HorizontalAlignmentValues.Right,
                Vertical   = VerticalAlignmentValues.Center
            })                                                                                        // Dates
                );

            return(new Stylesheet(fonts, fills, borders, cellFormats));
        }
            public static void AddStylesToWorkbookPart(WorkbookPart part)
            {
                var workbookStylesPart = part.AddNewPart <WorkbookStylesPart>("WorkbookStyles");

                var stylesheet1 = new Stylesheet {
                    MCAttributes = new MarkupCompatibilityAttributes {
                        Ignorable = "x14ac"
                    }
                };

                stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
                stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

                var fonts1 = new Fonts {
                    Count = 1U, KnownFonts = true
                };

                var font1     = new Font();
                var fontSize1 = new FontSize {
                    Val = 11D
                };
                var color1 = new Color {
                    Theme = 1U
                };
                var fontName1 = new FontName {
                    Val = "Calibri"
                };
                var fontFamilyNumbering1 = new FontFamilyNumbering {
                    Val = 2
                };
                var fontScheme1 = new FontScheme {
                    Val = FontSchemeValues.Minor
                };

                font1.Append(fontSize1);
                font1.Append(color1);
                font1.Append(fontName1);
                font1.Append(fontFamilyNumbering1);
                font1.Append(fontScheme1);

                fonts1.Append(font1);

                var fills1 = new Fills {
                    Count = 2U
                };

                var fill1        = new Fill();
                var patternFill1 = new PatternFill {
                    PatternType = PatternValues.None
                };

                fill1.Append(patternFill1);

                var fill2        = new Fill();
                var patternFill2 = new PatternFill {
                    PatternType = PatternValues.Gray125
                };

                fill2.Append(patternFill2);

                fills1.Append(fill1);
                fills1.Append(fill2);

                var borders1 = new Borders {
                    Count = 1U
                };

                var border1         = new Border();
                var leftBorder1     = new LeftBorder();
                var rightBorder1    = new RightBorder();
                var topBorder1      = new TopBorder();
                var bottomBorder1   = new BottomBorder();
                var diagonalBorder1 = new DiagonalBorder();

                border1.Append(leftBorder1);
                border1.Append(rightBorder1);
                border1.Append(topBorder1);
                border1.Append(bottomBorder1);
                border1.Append(diagonalBorder1);

                borders1.Append(border1);

                var cellStyleFormats1 = new CellStyleFormats {
                    Count = 1U
                };
                var cellStyleFormat = new CellFormat {
                    NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U
                };

                cellStyleFormats1.Append(cellStyleFormat);

                var cellFormats = new CellFormats {
                    Count = 2U
                };

                // index 0 (default) => unlocked
                var cellFormat0 = new CellFormat {
                    NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyProtection = true
                }.AppendItem(new Protection {
                    Locked = false
                });
                // index 1 => locked
                var cellFormat1 = new CellFormat {
                    NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U
                };

                cellFormats.Append(cellFormat0);
                cellFormats.Append(cellFormat1);

                var cellStyles1 = new CellStyles {
                    Count = 1U
                };
                var cellStyle1 = new CellStyle {
                    Name = "Normal", FormatId = 0U, BuiltinId = 0U
                };

                cellStyles1.Append(cellStyle1);

                stylesheet1.Append(fonts1);
                stylesheet1.Append(fills1);
                stylesheet1.Append(borders1);
                stylesheet1.Append(cellStyleFormats1);
                stylesheet1.Append(cellFormats);
                stylesheet1.Append(cellStyles1);

                workbookStylesPart.Stylesheet = stylesheet1;
            }
Example #44
0
 public CustomStylesheet()
 {
     var fonts = new Fonts();
     var font = new DocumentFormat.OpenXml.Spreadsheet.Font();
     var fontName = new FontName { Val = StringValue.FromString("Arial") };
     var fontSize = new FontSize { Val = DoubleValue.FromDouble(11) };
     font.FontName = fontName;
     font.FontSize = fontSize;
     fonts.Append(font);
     //Font Index 1
     font = new DocumentFormat.OpenXml.Spreadsheet.Font();
     fontName = new FontName { Val = StringValue.FromString("Arial") };
     fontSize = new FontSize { Val = DoubleValue.FromDouble(12) };
     font.FontName = fontName;
     font.FontSize = fontSize;
     font.Bold = new Bold();
     fonts.Append(font);
     fonts.Count = UInt32Value.FromUInt32((uint)fonts.ChildElements.Count);
     var fills = new Fills();
     var fill = new Fill();
     var patternFill = new PatternFill { PatternType = PatternValues.None };
     fill.PatternFill = patternFill;
     fills.Append(fill);
     fill = new Fill();
     patternFill = new PatternFill { PatternType = PatternValues.Gray125 };
     fill.PatternFill = patternFill;
     fills.Append(fill);
     //Fill index  2
     fill = new Fill();
     patternFill = new PatternFill
     {
         PatternType = PatternValues.Solid,
         ForegroundColor = new ForegroundColor()
     };
     patternFill.ForegroundColor =
         TranslateForeground(System.Drawing.Color.LightBlue);
     patternFill.BackgroundColor =
         new BackgroundColor { Rgb = patternFill.ForegroundColor.Rgb };
     fill.PatternFill = patternFill;
     fills.Append(fill);
     //Fill index  3
     fill = new Fill();
     patternFill = new PatternFill
     {
         PatternType = PatternValues.Solid,
         ForegroundColor = new ForegroundColor()
     };
     patternFill.ForegroundColor =
         TranslateForeground(System.Drawing.Color.DodgerBlue);
     patternFill.BackgroundColor =
         new BackgroundColor { Rgb = patternFill.ForegroundColor.Rgb };
     fill.PatternFill = patternFill;
     fills.Append(fill);
     fills.Count = UInt32Value.FromUInt32((uint)fills.ChildElements.Count);
     var borders = new Borders();
     var border = new Border
     {
         LeftBorder = new LeftBorder(),
         RightBorder = new RightBorder(),
         TopBorder = new TopBorder(),
         BottomBorder = new BottomBorder(),
         DiagonalBorder = new DiagonalBorder()
     };
     borders.Append(border);
     //All Boarder Index 1
     border = new Border
     {
         LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin },
         RightBorder = new RightBorder { Style = BorderStyleValues.Thin },
         TopBorder = new TopBorder { Style = BorderStyleValues.Thin },
         BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin },
         DiagonalBorder = new DiagonalBorder()
     };
     borders.Append(border);
     //Top and Bottom Boarder Index 2
     border = new Border
     {
         LeftBorder = new LeftBorder(),
         RightBorder = new RightBorder(),
         TopBorder = new TopBorder { Style = BorderStyleValues.Thin },
         BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin },
         DiagonalBorder = new DiagonalBorder()
     };
     borders.Append(border);
     borders.Count = UInt32Value.FromUInt32((uint)borders.ChildElements.Count);
     var cellStyleFormats = new CellStyleFormats();
     var cellFormat = new CellFormat
     {
         NumberFormatId = 0,
         FontId = 0,
         FillId = 0,
         BorderId = 0
     };
     cellStyleFormats.Append(cellFormat);
     cellStyleFormats.Count =
         UInt32Value.FromUInt32((uint)cellStyleFormats.ChildElements.Count);
     uint iExcelIndex = 164;
     var numberingFormats = new NumberingFormats();
     var cellFormats = new CellFormats();
     cellFormat = new CellFormat
     {
         NumberFormatId = 0,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0
     };
     cellFormats.Append(cellFormat);
     var nformatDateTime = new NumberingFormat
     {
         NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
         FormatCode = StringValue.FromString("dd/mm/yyyy hh:mm:ss")
     };
     numberingFormats.Append(nformatDateTime);
     var nformat4Decimal = new NumberingFormat
     {
         NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
         FormatCode = StringValue.FromString("#,##0.0000")
     };
     numberingFormats.Append(nformat4Decimal);
     var nformat2Decimal = new NumberingFormat
     {
         NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
         FormatCode = StringValue.FromString("#,##0.00")
     };
     numberingFormats.Append(nformat2Decimal);
     var nformatForcedText = new NumberingFormat
     {
         NumberFormatId = UInt32Value.FromUInt32(iExcelIndex),
         FormatCode = StringValue.FromString("@")
     };
     numberingFormats.Append(nformatForcedText);
     // index 1
     // Cell Standard Date format
     cellFormat = new CellFormat
     {
         NumberFormatId = 14,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 2
     // Cell Standard Number format with 2 decimal placing
     cellFormat = new CellFormat
     {
         NumberFormatId = 4,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 3
     // Cell Date time custom format
     cellFormat = new CellFormat
     {
         NumberFormatId = nformatDateTime.NumberFormatId,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 4
     // Cell 4 decimal custom format
     cellFormat = new CellFormat
     {
         NumberFormatId = nformat4Decimal.NumberFormatId,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 5
     // Cell 2 decimal custom format
     cellFormat = new CellFormat
     {
         NumberFormatId = nformat2Decimal.NumberFormatId,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 6
     // Cell forced number text custom format
     cellFormat = new CellFormat
     {
         NumberFormatId = nformatForcedText.NumberFormatId,
         FontId = 0,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 7
     // Cell text with font 12
     cellFormat = new CellFormat
     {
         NumberFormatId = nformatForcedText.NumberFormatId,
         FontId = 1,
         FillId = 0,
         BorderId = 0,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 8
     // Cell text
     cellFormat = new CellFormat
     {
         NumberFormatId = nformatForcedText.NumberFormatId,
         FontId = 0,
         FillId = 0,
         BorderId = 1,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 9
     // Coloured 2 decimal cell text
     cellFormat = new CellFormat
     {
         NumberFormatId = nformat2Decimal.NumberFormatId,
         FontId = 0,
         FillId = 2,
         BorderId = 2,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 10
     // Coloured cell text
     cellFormat = new CellFormat
     {
         NumberFormatId = nformatForcedText.NumberFormatId,
         FontId = 0,
         FillId = 2,
         BorderId = 2,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     // Index 11
     // Coloured cell text
     cellFormat = new CellFormat
     {
         NumberFormatId = nformatForcedText.NumberFormatId,
         FontId = 1,
         FillId = 3,
         BorderId = 2,
         FormatId = 0,
         ApplyNumberFormat = BooleanValue.FromBoolean(true)
     };
     cellFormats.Append(cellFormat);
     numberingFormats.Count =
         UInt32Value.FromUInt32((uint)numberingFormats.ChildElements.Count);
     cellFormats.Count = UInt32Value.FromUInt32((uint)cellFormats.ChildElements.Count);
     this.Append(numberingFormats);
     this.Append(fonts);
     this.Append(fills);
     this.Append(borders);
     this.Append(cellStyleFormats);
     this.Append(cellFormats);
     var css = new CellStyles();
     var cs = new CellStyle
     {
         Name = StringValue.FromString("Normal"),
         FormatId = 0,
         BuiltinId = 0
     };
     css.Append(cs);
     css.Count = UInt32Value.FromUInt32((uint)css.ChildElements.Count);
     this.Append(css);
     var dfs = new DifferentialFormats { Count = 0 };
     this.Append(dfs);
     var tss = new TableStyles
     {
         Count = 0,
         DefaultTableStyle = StringValue.FromString("TableStyleMedium9"),
         DefaultPivotStyle = StringValue.FromString("PivotStyleLight16")
     };
     this.Append(tss);
 }
Example #45
0
        /// <summary>
        /// Create an stylesheet to use in excel files
        /// </summary>
        /// <returns></returns>
        private static Stylesheet VocStyleSheet()
        {
            Stylesheet styleSheet = new Stylesheet();

            Fonts fonts = new Fonts();
            // 0 - normal fonts
            DocumentFormat.OpenXml.Spreadsheet.Font myFont = new DocumentFormat.OpenXml.Spreadsheet.Font()
            {
                FontSize = new FontSize() { Val = 11 },
                Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "000000" } },
                FontName = new FontName() { Val = "Calibri" }
            };
            fonts.Append(myFont);

            //1 - font bold
            myFont = new DocumentFormat.OpenXml.Spreadsheet.Font()
            {
                Bold = new Bold(),
                FontSize = new FontSize() { Val = 11 },
                Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "000000" } },
                FontName = new FontName() { Val = "Calibri" }
            };
            fonts.Append(myFont);

            //2 - font title
            myFont = new DocumentFormat.OpenXml.Spreadsheet.Font()
            {
                Bold = new Bold(),
                FontSize = new FontSize() { Val = 20 },
                Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "FFFFFF" } },
                FontName = new FontName() { Val = "Verdana" }
            };
            fonts.Append(myFont);

            //3 - font bold
            myFont = new DocumentFormat.OpenXml.Spreadsheet.Font()
            {
                Bold = new Bold(),
                FontSize = new FontSize() { Val = 16 },
                Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "000000" } },
                FontName = new FontName() { Val = "Calibri" }
            };
            fonts.Append(myFont);

            //4 - small font white
            myFont = new DocumentFormat.OpenXml.Spreadsheet.Font()
            {
                FontSize = new FontSize() { Val = 11 },
                Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "FFFFFF" } },
                FontName = new FontName() { Val = "Calibri" }
            };
            fonts.Append(myFont);

            Fills fills = new Fills();
            //default fill
            Fill fill = new Fill()
            {
                PatternFill = new PatternFill() { PatternType = PatternValues.None }
            };
            fills.Append(fill);
            //default fill
            fill = new Fill()
            {
                PatternFill = new PatternFill() { PatternType = PatternValues.Gray125 }
            };
            fills.Append(fill);
            //title fill
            fill = new Fill()
            {
                PatternFill = new PatternFill()
                {
                    ForegroundColor = new ForegroundColor()
                    {
                        Rgb = new HexBinaryValue() { Value = "499EB1" }
                    },
                    PatternType = PatternValues.Solid
                }
            };
            fills.Append(fill);

            Borders borders = new Borders();
            //normal borders
            Border border = new Border()
            {
                LeftBorder = new LeftBorder(),
                RightBorder = new RightBorder(),
                TopBorder = new TopBorder(),
                BottomBorder = new BottomBorder(),
                DiagonalBorder = new DiagonalBorder()
            };
            borders.Append(border);

            //borders applied
            border = new Border()
            {
                LeftBorder = new LeftBorder() { Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true }, Style = BorderStyleValues.Thin },
                RightBorder = new RightBorder() { Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true }, Style = BorderStyleValues.Thin },
                TopBorder = new TopBorder() { Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true }, Style = BorderStyleValues.Thin },
                BottomBorder = new BottomBorder() { Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true }, Style = BorderStyleValues.Thin },
                DiagonalBorder = new DiagonalBorder()
            };
            borders.Append(border);

            CellFormats cellFormats = new CellFormats();
            //0- normal
            CellFormat cellFormat = new CellFormat()
            {
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //1 - border
            cellFormat = new CellFormat()
            {
                FontId = 0,
                FillId = 0,
                BorderId = 1,
                Alignment = new Alignment() { WrapText = true },
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //2 - border and bold
            cellFormat = new CellFormat()
            {
                FontId = 1,
                FillId = 0,
                BorderId = 1,
                Alignment = new Alignment() { WrapText = true },
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //3 -title
            cellFormat = new CellFormat()
            {
                FontId = 0,
                FillId = 2,
                BorderId = 0,
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //4 - title
            cellFormat = new CellFormat()
            {
                FontId = 2,
                FillId = 2,
                BorderId = 0,
                Alignment = new Alignment() { Horizontal = HorizontalAlignmentValues.Left, Vertical = VerticalAlignmentValues.Center },
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //5 - title
            cellFormat = new CellFormat()
            {
                FontId = 2,
                FillId = 2,
                BorderId = 0,
                Alignment = new Alignment() { Horizontal = HorizontalAlignmentValues.CenterContinuous, Vertical = VerticalAlignmentValues.Center },
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //6 - section title
            cellFormat = new CellFormat()
            {
                FontId = 3,
                FillId = 0,
                BorderId = 1,
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            //7 - section title filter values
            cellFormat = new CellFormat()
            {
                FontId = 4,
                FillId = 2,
                BorderId = 0,
                Alignment = new Alignment() { WrapText = false, Horizontal = HorizontalAlignmentValues.Left, Vertical = VerticalAlignmentValues.Center },
                ApplyFill = true
            };
            cellFormats.Append(cellFormat);

            styleSheet.Append(fonts);
            styleSheet.Append(fills);
            styleSheet.Append(borders);
            styleSheet.Append(cellFormats);

            return styleSheet;
        }
Example #46
0
 public static Font CreateCustomFont(
     Fonts fonts,
     DoubleValue fontSize,
     UInt32Value color,
     StringValue fontName,
     bool isBold = false,
     bool isItalic = false,
     bool isUnderline = false)
 {
     return CreateFont(fonts, fontSize, color, fontName, FamilyNumberingCustom, UsedCharSet, isBold, isItalic, isUnderline);
 }
 internal static Microsoft.SPOT.Font GetFont(Fonts.FontResources id)
 {
     return ((Microsoft.SPOT.Font)(Microsoft.SPOT.ResourceUtility.GetObject(ResourceManager, id)));
 }
Example #48
0
        public static Font CreateFont(
            Fonts fonts,
            DoubleValue fontSize,
            UInt32Value color,
            StringValue fontName,
            Int32Value fontFamilyNumbering,
            Int32Value fontCharSet,
            bool isBold,
            bool isItalic,
            bool isUnderline,
            FontSchemeValues? fontScheme = null)
        {
            var font = new Font();

            font.Append(new FontSize { Val = fontSize });
            font.Append(new Color { Theme = color });
            font.Append(new FontName { Val = fontName });
            font.Append(new FontFamilyNumbering { Val = fontFamilyNumbering });
            font.Append(new FontCharSet { Val = fontCharSet });

            if (fontScheme.HasValue)
            {
                font.Append(new FontScheme { Val = fontScheme.Value });
            }
            if (isBold)
            {
                font.Append(new Bold());
            }
            if (isItalic)
            {
                font.Append(new Italic());
            }
            if (isUnderline)
            {
                font.Append(new Underline());
            }

            fonts.Append(font);

            return font;
        }
        /*
         * Write code for workbook styles by giving your own
         * font size, color, font name, border properties, cell style formats etc.
         */
        private void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart1)
        {
            Stylesheet stylesheet1 = new Stylesheet()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "x14ac"
                }
            };

            stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

            Fonts fonts1 = new Fonts()
            {
                Count      = (UInt32Value)2U,
                KnownFonts = true
            };

            #region Fonts
            Font     font1     = new Font();
            FontSize fontSize1 = new FontSize()
            {
                Val = 11D
            };
            Color color1 = new Color()
            {
                Theme = (UInt32Value)1U
            };
            FontName fontName1 = new FontName()
            {
                Val = "Calibri"
            };
            FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering()
            {
                Val = 2
            };
            FontScheme fontScheme1 = new FontScheme()
            {
                Val = FontSchemeValues.Minor
            };

            font1.Append(fontSize1);
            font1.Append(color1);
            font1.Append(fontName1);
            font1.Append(fontFamilyNumbering1);
            font1.Append(fontScheme1);

            Font     font2     = new Font();
            Bold     bold1     = new Bold();
            FontSize fontSize2 = new FontSize()
            {
                Val = 11D
            };
            Color color2 = new Color()
            {
                Theme = (UInt32Value)1U
            };
            FontName fontName2 = new FontName()
            {
                Val = "Calibri"
            };
            FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering()
            {
                Val = 2
            };
            FontScheme fontScheme2 = new FontScheme()
            {
                Val = FontSchemeValues.Minor
            };

            font2.Append(bold1);
            font2.Append(fontSize2);
            font2.Append(color2);
            font2.Append(fontName2);
            font2.Append(fontFamilyNumbering2);
            font2.Append(fontScheme2);

            fonts1.Append(font1);
            fonts1.Append(font2);
            #endregion
            #region Fills
            Fills fills1 = new Fills()
            {
                Count = (UInt32Value)2U
            };

            Fill        fill1        = new Fill();
            PatternFill patternFill1 = new PatternFill()
            {
                PatternType = PatternValues.None
            };
            fill1.Append(patternFill1);

            Fill        fill2        = new Fill();
            PatternFill patternFill2 = new PatternFill()
            {
                PatternType = PatternValues.Gray125
            };
            fill2.Append(patternFill2);

            fills1.Append(fill1);
            fills1.Append(fill2);
            #endregion
            #region Borders
            Borders borders1 = new Borders()
            {
                Count = (UInt32Value)2U
            };

            Border         border1         = new Border();
            LeftBorder     leftBorder1     = new LeftBorder();
            RightBorder    rightBorder1    = new RightBorder();
            TopBorder      topBorder1      = new TopBorder();
            BottomBorder   bottomBorder1   = new BottomBorder();
            DiagonalBorder diagonalBorder1 = new DiagonalBorder();

            border1.Append(leftBorder1);
            border1.Append(rightBorder1);
            border1.Append(topBorder1);
            border1.Append(bottomBorder1);
            border1.Append(diagonalBorder1);

            Border border2 = new Border();

            LeftBorder leftBorder2 = new LeftBorder()
            {
                Style = BorderStyleValues.Thin
            };
            Color color3 = new Color()
            {
                Indexed = (UInt32Value)64U
            };
            leftBorder2.Append(color3);

            RightBorder rightBorder2 = new RightBorder()
            {
                Style = BorderStyleValues.Thin
            };
            Color color4 = new Color()
            {
                Indexed = (UInt32Value)64U
            };
            rightBorder2.Append(color4);

            TopBorder topBorder2 = new TopBorder()
            {
                Style = BorderStyleValues.Thin
            };
            Color color5 = new Color()
            {
                Indexed = (UInt32Value)64U
            };
            topBorder2.Append(color5);

            BottomBorder bottomBorder2 = new BottomBorder()
            {
                Style = BorderStyleValues.Thin
            };
            Color color6 = new Color()
            {
                Indexed = (UInt32Value)64U
            };
            bottomBorder2.Append(color6);

            DiagonalBorder diagonalBorder2 = new DiagonalBorder();

            border2.Append(leftBorder2);
            border2.Append(rightBorder2);
            border2.Append(topBorder2);
            border2.Append(bottomBorder2);
            border2.Append(diagonalBorder2);

            borders1.Append(border1);
            borders1.Append(border2);
            #endregion
            #region CellStyleFormats
            CellStyleFormats cellStyleFormats1 = new CellStyleFormats()
            {
                Count = (UInt32Value)1U
            };
            CellFormat cellFormat1 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U
            };
            cellStyleFormats1.Append(cellFormat1);

            CellFormats cellFormats1 = new CellFormats()
            {
                Count = (UInt32)3U
            };

            CellFormat cellFormat2 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U,
                FormatId       = (UInt32Value)0U
            };
            CellFormat cellFormat3 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U,
                FormatId       = (UInt32Value)0U,
                ApplyBorder    = true
            };
            CellFormat cellFormat4 = new CellFormat()
            {
                NumberFormatId = (UInt32Value)0U,
                FontId         = (UInt32Value)0U,
                FillId         = (UInt32Value)0U,
                BorderId       = (UInt32Value)0U,
                FormatId       = (UInt32Value)0U,
                ApplyFont      = true,
                ApplyBorder    = true
            };

            cellFormats1.Append(cellFormat2);
            cellFormats1.Append(cellFormat3);
            cellFormats1.Append(cellFormat4);

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

            cellStyle1.Append(cellStyle1);

            DifferentialFormats differentialFormats1 = new DifferentialFormats()
            {
                Count = (UInt32Value)0U
            };
            TableStyles tableStyles1 = new TableStyles()
            {
                Count             = (UInt32Value)0U,
                DefaultTableStyle = "TableStyleMedium2",
                DefaultPivotStyle = "PivotStyleLight16"
            };
            #endregion
            #region StylesheetExtensionLists
            StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList();

            StylesheetExtension stylesheetExtension1 = new StylesheetExtension()
            {
                Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
            };
            stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
            X14.SlicerStyles slicerStyles1 = new X14.SlicerStyles()
            {
                DefaultSlicerStyle = "SlicerStyleLight1"
            };

            stylesheetExtension1.Append(slicerStyles1);

            StylesheetExtension stylesheetExtension2 = new StylesheetExtension()
            {
                Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
            };
            stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
            X15.TimelineStyles timelineStyles1 = new X15.TimelineStyles()
            {
                DefaultTimelineStyle = "TimeSlicerStyleLight1"
            };

            stylesheetExtension2.Append(timelineStyles1);

            stylesheetExtensionList1.Append(stylesheetExtension1);
            stylesheetExtensionList1.Append(stylesheetExtension2);
            #endregion

            stylesheet1.Append(fonts1);
            stylesheet1.Append(fills1);
            stylesheet1.Append(borders1);
            stylesheet1.Append(cellStyleFormats1);
            stylesheet1.Append(cellFormats1);
            stylesheet1.Append(cellStyles1);
            stylesheet1.Append(differentialFormats1);
            stylesheet1.Append(tableStyles1);
            stylesheet1.Append(stylesheetExtensionList1);

            workbookStylesPart1.Stylesheet = stylesheet1;
        }
 public static Phrase GetPhrase(string text, Fonts type)
 {
     Phrase p;
     switch (type)
     {
         case Fonts.Large: p = new Phrase(text); break;
         case Fonts.Footer: p = new Phrase(text, FooterFont); break;
         case Fonts.Standard: p = new Phrase(text, StandardFont); break;
         case Fonts.ExtraLarge:
             p = new Phrase(text, ExtraLargeFont);
             break;
         default: throw new ArgumentOutOfRangeException("type");
     }
     return p;
 }
Example #51
0
 public static Font CreateDefaultFont(Fonts fonts)
 {
     return CreateFont(fonts, 11D, FontColorBlack, FontNameCalibri, FamilyNumberingSystem, UsedCharSet, false, false, false, FontSchemeValues.Minor);
 }
Example #52
0
 private void updateFontName()
 {
     lblFont.Text = $"{Fonts.GetFont(FontType.Medium).Name}, {Fonts.GetFont(FontType.Medium).Size}";
 }
Example #53
0
 public static Fonts CreateFontsCollection(Stylesheet stylesheet, UInt32Value capacity)
 {
     var fonts = new Fonts { Count = capacity, KnownFonts = true };
     stylesheet.Append(fonts);
     return fonts;
 }
Example #54
0
        }//экспорт в XLSX

        private void ExportDataSet(DataTable table, string destination)
        {
            using (var workbook = SpreadsheetDocument.Create(destination, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook))
            {
                //режем тэйбл от мусора
                table.Columns.Remove("Код");
                table.Columns.Remove("ID");

                //создание workbook+sheets
                var workbookPart = workbook.AddWorkbookPart();
                workbook.WorkbookPart.Workbook        = new DocumentFormat.OpenXml.Spreadsheet.Workbook();
                workbook.WorkbookPart.Workbook.Sheets = new DocumentFormat.OpenXml.Spreadsheet.Sheets();

                //собственный формат для даты
                //styles
                WorkbookStylesPart workbookStylesPart = workbookPart.AddNewPart <WorkbookStylesPart>("rId3");
                Stylesheet         stylesheet         = new Stylesheet();
                //  Date Time Display Format when s="1" is applied to cell
                NumberingFormats numberingFormats = new NumberingFormats()
                {
                    Count = (UInt32Value)1U
                };
                NumberingFormat numberingFormat = new NumberingFormat()
                {
                    NumberFormatId = (UInt32Value)164U, FormatCode = "dd.MM.yyyy"
                };
                numberingFormats.Append(numberingFormat);
                // Cell font
                Fonts fonts = new Fonts()
                {
                    Count = (UInt32Value)1U
                };
                DocumentFormat.OpenXml.Spreadsheet.Font font = new DocumentFormat.OpenXml.Spreadsheet.Font();
                FontSize fontSize = new FontSize()
                {
                    Val = 11D
                };
                FontName fontName = new FontName()
                {
                    Val = "Calibri"
                };
                font.Append(fontSize);
                font.Append(fontName);
                fonts.Append(font);
                // empty, but mandatory
                Fills fills = new Fills()
                {
                    Count = (UInt32Value)1U
                };
                Fill fill = new Fill();
                fills.Append(fill);
                Borders borders = new Borders()
                {
                    Count = (UInt32Value)1U
                };
                Border border = new Border();
                borders.Append(border);
                // cellFormat1 for text cell cellFormat2 for Datetime cell
                CellFormats cellFormats = new CellFormats()
                {
                    Count = (UInt32Value)2U
                };
                CellFormat cellFormat1 = new CellFormat()
                {
                    FontId = (UInt32Value)0U
                };
                CellFormat cellFormat2 = new CellFormat()
                {
                    NumberFormatId = (UInt32Value)164U, FontId = (UInt32Value)0U, ApplyNumberFormat = true
                };
                cellFormats.Append(cellFormat1);
                cellFormats.Append(cellFormat2);
                // Save as styles
                stylesheet.Append(numberingFormats);
                stylesheet.Append(fonts);
                stylesheet.Append(fills);
                stylesheet.Append(borders);
                stylesheet.Append(cellFormats);
                workbookStylesPart.Stylesheet = stylesheet;

                {
                    var sheetPart = workbook.WorkbookPart.AddNewPart <WorksheetPart>();
                    var sheetData = new DocumentFormat.OpenXml.Spreadsheet.SheetData();
                    sheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(sheetData);

                    DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = workbook.WorkbookPart.Workbook.GetFirstChild <DocumentFormat.OpenXml.Spreadsheet.Sheets>();
                    string relationshipId = workbook.WorkbookPart.GetIdOfPart(sheetPart);

                    uint sheetId = 1;
                    if (sheets.Elements <DocumentFormat.OpenXml.Spreadsheet.Sheet>().Count() > 0)
                    {
                        sheetId =
                            sheets.Elements <DocumentFormat.OpenXml.Spreadsheet.Sheet>().Select(s => s.SheetId.Value).Max() + 1;
                    }

                    DocumentFormat.OpenXml.Spreadsheet.Sheet sheet = new DocumentFormat.OpenXml.Spreadsheet.Sheet()
                    {
                        Id = relationshipId, SheetId = sheetId, Name = "Отчет"
                    };
                    sheets.Append(sheet);

                    DocumentFormat.OpenXml.Spreadsheet.Row headerRow = new DocumentFormat.OpenXml.Spreadsheet.Row();

                    List <String> columns = new List <string>();

                    //создаем header в xlsx
                    foreach (System.Data.DataColumn column in table.Columns)
                    {
                        columns.Add(column.ColumnName);
                        DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
                        cell.DataType  = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
                        cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(column.ColumnName);
                        headerRow.AppendChild(cell);
                    }
                    sheetData.AppendChild(headerRow);

                    //Перенос из datatable
                    foreach (System.Data.DataRow dsrow in table.Rows)
                    {
                        DocumentFormat.OpenXml.Spreadsheet.Row newRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
                        foreach (String col in columns)
                        {
                            DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
                            //проверка типа входных данных
                            Type dtype = dsrow[col].GetType();
                            switch (dtype.Name.ToString())
                            {
                            case "DateTime":
                                DateTime dt = Convert.ToDateTime(dsrow[col].ToString());
                                cell.DataType   = DocumentFormat.OpenXml.Spreadsheet.CellValues.Number;
                                cell.CellValue  = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dt.ToOADate().ToString());
                                cell.StyleIndex = 1;
                                break;

                            case "String":
                                cell.DataType  = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
                                cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dsrow[col].ToString());
                                break;

                            case "Int32":
                                cell.DataType  = DocumentFormat.OpenXml.Spreadsheet.CellValues.Number;
                                cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dsrow[col].ToString());
                                break;

                            default:
                                break;
                            }
                            newRow.AppendChild(cell);
                        }

                        sheetData.AppendChild(newRow);
                    }
                }
            }
        }//вывод dataTable в xlsx с учетом типа данных
Example #55
0
 public void setFonts(Fonts.FontCollection FontCollection)
 {
     this.fonts_ = FontCollection;
 }
        //.....................................................................
        /// <summary>
        /// Stylesheet class is used to add custom style to a spreadsheet.
        ///
        /// Stylesheet can accept different elements such as, Borders, Colors, Fills, and etc.
        /// as its child elements which specifies the look of a spreadsheet.
        ///
        /// The CellFormats stores the combination of different Styles
        /// which later can be applied on a cell.
        ///
        /// In order to add a Stylesheet to our workbook, we need to add a WorkbookStylePart
        /// to the Workbook part and initialize its StyleSheet property.
        ///
        /// We are going to make our header bold and white with dark background
        /// as well as adding border to all other cells.
        ///
        /// Create a new method GenerateStylesheet() which
        /// returns a StyleSheet object to the Report class.
        ///
        /// </summary>
        /// <returns></returns>
        private Stylesheet GenerateStylesheet( )
        {
            //  Fonts can have one or more Font children which each have different properties
            //  like FontSize, Bold, Color, and etc.
            //
            //  Take note that we add two Font children to the Fonts object.
            //  The first one is the default font use by all cells,
            //  and the second one is specific to header.
            //
            Color color = new Color( )
            {
                Rgb = "FFFFFF"
            };

            Font font1 = new Font(new FontSize( )
            {
                Val = 10
            });                                                                           // Index 0 - default
            Font font2 = new Font(new FontSize( )
            {
                Val = 10
            }, new Bold( ), color);                                                       // Index 1 - header

            Fonts fonts = new Fonts(font1, font2);

            //.............................................
            //  Fills can have one or more Fill children which you can set its ForegroundColor.
            //
            //  Excel needs to have the first two as the default.
            //  The 3rd one is the style we want to have for our header cells; a gray sold background.
            //
            ForegroundColor fcolor = new ForegroundColor {
                Rgb = new HexBinaryValue( )
                {
                    Value = "66666666"
                }
            };

            Fill fi1 = new Fill(new PatternFill( )
            {
                PatternType = PatternValues.None
            });                                                                                         // Index 0 - default
            Fill fi2 = new Fill(new PatternFill( )
            {
                PatternType = PatternValues.Gray125
            });                                                                                         // Index 1 - default
            Fill fi3 = new Fill(new PatternFill(fcolor)
            {
                PatternType = PatternValues.Solid
            });                                                                                         // Index 2 - header

            Fills fills = new Fills(fi1, fi2, fi3);

            //.............................................
            //  Borders can have one or more Border children which each defines how the border should look like:
            //  The 1st is the default border and the 2nd one is our customized border.
            //
            var brLF = new LeftBorder(new Color( )
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            };
            var brRT = new RightBorder(new Color( )
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            };
            var brTP = new TopBorder(new Color( )
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            };
            var brBT = new BottomBorder(new Color( )
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            };
            var brDG = new DiagonalBorder( );

            Border bd1 = new Border( );                                     // index 0 default
            Border bd2 = new Border(brLF, brRT, brTP, brBT, brDG);          // index 1 black border

            Borders borders = new Borders(bd1, bd2);

            //.............................................
            //  Now that we have defied our custom formats elements we can create CellFormats
            //  which has one or many CellFormat children.
            //  Each CellFormat gets the index of Font, Border, Fill, or etc. which it will associate with:
            //
            CellFormat cfmt1 = new CellFormat( ); // default
            CellFormat cfmt2 = new CellFormat {
                FontId = 0, FillId = 0, BorderId = 1, ApplyBorder = true
            };                                                                                              // body
            CellFormat cfmt3 = new CellFormat {
                FontId = 1, FillId = 2, BorderId = 1, ApplyFill = true
            };                                                                                            // header

            CellFormats cellFormats = new CellFormats(cfmt1, cfmt2, cfmt3);

            Stylesheet styleSheet = new Stylesheet(fonts, fills, borders, cellFormats);

            return(styleSheet);
        }
        public CustomStylesheet()
        {
            NumberStyles = new Dictionary<NumberStyle, NumberingFormat>();
            CellFormatStyles = new Dictionary<CellFormatId, uint>();

            Borders = new Borders();
            BorderStyles = new Dictionary<string, uint>();

            Fonts = new Fonts();
            FontStyles = new Dictionary<string, uint>();

            RegisterBorder("None");
            RegisterFont("Default", new Font
            {
             				FontName = new FontName { Val = StringValue.FromString("Calibri") },
                FontSize = new FontSize { Val = DoubleValue.FromDouble(10) }
            });

            var fills = CreateFills();

            var numberingFormats = CreateNumberFormats();

            MyCellFormats = new DocumentFormat.OpenXml.Spreadsheet.CellFormats();
            MyCellFormats.Append(new CellFormat
            {
                NumberFormatId = 0,
                FontId = 0,
                FillId = 0,
                BorderId = 0,
                FormatId = 0
            });

            //BuildCellFormat(BorderStyle.All, NumberStyle.ForcedText);

            var cellStyleFormats = new CellStyleFormats();

            var cellFormat = new CellFormat
            {
                Alignment = new Alignment() { Horizontal = HorizontalAlignmentValues.Center },
                NumberFormatId = 0,
                FontId = 0,
                FillId = 0,
                BorderId = 0
            };
            cellStyleFormats.Append(cellFormat);
            cellStyleFormats.Count =
                 UInt32Value.FromUInt32((uint)cellStyleFormats.ChildElements.Count);

            //var cellFormats = CreateCellFormats();

            this.Append(numberingFormats);
            this.Append(Fonts);	//	OK
            this.Append(fills);
            this.Append(Borders);	//	OK
            this.Append(cellStyleFormats);
            this.Append(MyCellFormats);
            var css = new CellStyles();
            var cs = new CellStyle
            {
                Name = StringValue.FromString("Normal"),
                FormatId = 0,
                BuiltinId = 0
            };
            css.Append(cs);
            css.Count = UInt32Value.FromUInt32((uint)css.ChildElements.Count);
            this.Append(css);
            var dfs = new DifferentialFormats { Count = 0 };
            this.Append(dfs);
            var tss = new TableStyles
            {
                Count = 0,
                DefaultTableStyle = StringValue.FromString("TableStyleMedium9"),
                DefaultPivotStyle = StringValue.FromString("PivotStyleLight16")
            };
            this.Append(tss);
        }
Example #58
0
        private Stylesheet GenerateStylesheet()
        {
            Stylesheet styleSheet = null;

            Fonts fonts = new Fonts(
                new Font( // Index 0 - default
                    new FontSize()
            {
                Val = 10
            }
                    )
                , new Font( // Index 1 - header
                    new FontSize()
            {
                Val = 10
            },
                    new Bold(),
                    new Color()
            {
                Rgb = "FFFFFF"
            }
                    ),
                new Font(
                    new FontSize()
            {
                Val = 12
            },
                    new Bold())
                );

            Fills fills = new Fills(
                new Fill(new PatternFill()
            {
                PatternType = PatternValues.None
            })                                                                       // Index 0 - default
                , new Fill(new PatternFill()
            {
                PatternType = PatternValues.Gray125
            }),                                                                            // Index 1 - default
                new Fill(new PatternFill(new ForegroundColor {
                Rgb = new HexBinaryValue()
                {
                    Value = "66666666"
                }
            })
            {
                PatternType = PatternValues.Solid
            })                                             // Index 2 - header
                );

            Borders borders = new Borders(
                new Border()     // index 0 default
                , new Border(    // index 1 black border
                    new LeftBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new RightBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new TopBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new BottomBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new DiagonalBorder())
                );

            CellFormats cellFormats = new CellFormats(
                new CellFormat()    // default
                , new CellFormat {
                FontId = 0, FillId = 0, BorderId = 1, ApplyBorder = true
            },                                                                                     // body
                new CellFormat {
                FontId = 1, FillId = 2, BorderId = 1, ApplyFill = true
            },                                                                                 // header
                                                                                               // Here is the CellFormat object you will need to create in order to have the 0.00% mask applied to your number.
                                                                                               // In this case you want the predefined format number 10 or 0.00%:
                new CellFormat()
            {
                NumberFormatId    = (UInt32Value)10U,
                FontId            = (UInt32Value)2U,
                FillId            = (UInt32Value)0U,
                BorderId          = (UInt32Value)0U,
                FormatId          = (UInt32Value)0U,
                ApplyNumberFormat = true
            }
                );

            styleSheet = new Stylesheet(fonts, fills, borders, cellFormats);
            //styleSheet = new Stylesheet();
            //styleSheet.Fills = fills;
            //styleSheet.Borders = borders;
            //styleSheet.CellFormats = cellFormats;


            return(styleSheet);
        }
Example #59
0
        private Stylesheet GenerateStylesheetOriginal()
        {
            Stylesheet styleSheet = null;

            Fonts fonts = new Fonts(
                new Font( // Index 0 - default
                    new FontSize()
            {
                Val = 10
            }

                    ),
                new Font( // Index 1 - header
                    new FontSize()
            {
                Val = 10
            },
                    new Bold(),
                    new Color()
            {
                Rgb = "FFFFFF"
            }

                    ));

            Fills fills = new Fills(
                new Fill(new PatternFill()
            {
                PatternType = PatternValues.None
            }),                                                                       // Index 0 - default
                new Fill(new PatternFill()
            {
                PatternType = PatternValues.Gray125
            }),                                                                          // Index 1 - default
                new Fill(new PatternFill(new ForegroundColor {
                Rgb = new HexBinaryValue()
                {
                    Value = "66666666"
                }
            })
            {
                PatternType = PatternValues.Solid
            })                                             // Index 2 - header
                );

            Borders borders = new Borders(
                new Border(),   // index 0 default
                new Border(     // index 1 black border
                    new LeftBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new RightBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new TopBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new BottomBorder(new Color()
            {
                Auto = true
            })
            {
                Style = BorderStyleValues.Thin
            },
                    new DiagonalBorder())
                );

            CellFormats cellFormats = new CellFormats(
                new CellFormat(),     // default
                new CellFormat {
                FontId = 0, FillId = 0, BorderId = 1, ApplyBorder = true
            },                                                                                   // body
                new CellFormat {
                FontId = 1, FillId = 2, BorderId = 1, ApplyFill = true
            }                                                                                 // header
                );

            styleSheet = new Stylesheet(fonts, fills, borders, cellFormats);

            return(styleSheet);
        }
Example #60
0
        // Generates content of fontTablePart1.
        private void GenerateFontTablePart1Content(FontTablePart fontTablePart1)
        {
            Fonts fonts1 = new Fonts();
            fonts1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            fonts1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");

            Font font1 = new Font() { Name = "Times New Roman" };
            FontCharSet fontCharSet1 = new FontCharSet() { Val = "00", StrictCharacterSet = new EnumValue<StrictCharacterSet>() { InnerText = "windows-1252" } };
            FontFamily fontFamily1 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch1 = new Pitch() { Val = FontPitchValues.Variable };

            font1.Append(fontCharSet1);
            font1.Append(fontFamily1);
            font1.Append(pitch1);

            Font font2 = new Font() { Name = "Symbol" };
            FontCharSet fontCharSet2 = new FontCharSet() { Val = "02" };
            FontFamily fontFamily2 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch2 = new Pitch() { Val = FontPitchValues.Variable };

            font2.Append(fontCharSet2);
            font2.Append(fontFamily2);
            font2.Append(pitch2);

            Font font3 = new Font() { Name = "Arial" };
            FontCharSet fontCharSet3 = new FontCharSet() { Val = "00", StrictCharacterSet = new EnumValue<StrictCharacterSet>() { InnerText = "windows-1252" } };
            FontFamily fontFamily3 = new FontFamily() { Val = FontFamilyValues.Swiss };
            Pitch pitch3 = new Pitch() { Val = FontPitchValues.Variable };

            font3.Append(fontCharSet3);
            font3.Append(fontFamily3);
            font3.Append(pitch3);

            Font font4 = new Font() { Name = "Liberation Serif" };
            AltName altName1 = new AltName() { Val = "Times New Roman" };
            FontCharSet fontCharSet4 = new FontCharSet() { Val = "cc", StrictCharacterSet = StrictCharacterSet.chsRussian };
            FontFamily fontFamily4 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch4 = new Pitch() { Val = FontPitchValues.Variable };

            font4.Append(altName1);
            font4.Append(fontCharSet4);
            font4.Append(fontFamily4);
            font4.Append(pitch4);

            Font font5 = new Font() { Name = "Times New Roman" };
            FontCharSet fontCharSet5 = new FontCharSet() { Val = "cc", StrictCharacterSet = StrictCharacterSet.chsRussian };
            FontFamily fontFamily5 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch5 = new Pitch() { Val = FontPitchValues.Variable };

            font5.Append(fontCharSet5);
            font5.Append(fontFamily5);
            font5.Append(pitch5);

            Font font6 = new Font() { Name = "Liberation Sans" };
            AltName altName2 = new AltName() { Val = "Arial" };
            FontCharSet fontCharSet6 = new FontCharSet() { Val = "cc", StrictCharacterSet = StrictCharacterSet.chsRussian };
            FontFamily fontFamily6 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch6 = new Pitch() { Val = FontPitchValues.Variable };

            font6.Append(altName2);
            font6.Append(fontCharSet6);
            font6.Append(fontFamily6);
            font6.Append(pitch6);

            Font font7 = new Font() { Name = "Symbol" };
            FontCharSet fontCharSet7 = new FontCharSet() { Val = "cc", StrictCharacterSet = StrictCharacterSet.chsRussian };
            FontFamily fontFamily7 = new FontFamily() { Val = FontFamilyValues.Roman };
            Pitch pitch7 = new Pitch() { Val = FontPitchValues.Variable };

            font7.Append(fontCharSet7);
            font7.Append(fontFamily7);
            font7.Append(pitch7);

            fonts1.Append(font1);
            fonts1.Append(font2);
            fonts1.Append(font3);
            fonts1.Append(font4);
            fonts1.Append(font5);
            fonts1.Append(font6);
            fonts1.Append(font7);

            fontTablePart1.Fonts = fonts1;
        }