Exemplo n.º 1
0
        /// <summary>
        /// Clone a new instance of SLFont with identical font settings.
        /// </summary>
        /// <returns>An SLFont object with identical font settings.</returns>
        public SLFont Clone()
        {
            SLFont font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);

            font.FontName             = this.FontName;
            font.CharacterSet         = this.CharacterSet;
            font.FontFamily           = this.FontFamily;
            font.Bold                 = this.Bold;
            font.Italic               = this.Italic;
            font.Strike               = this.Strike;
            font.Outline              = this.Outline;
            font.Shadow               = this.Shadow;
            font.Condense             = this.Condense;
            font.Extend               = this.Extend;
            font.clrFontColor         = this.clrFontColor.Clone();
            font.HasFontColor         = this.HasFontColor;
            font.FontSize             = this.FontSize;
            font.vUnderline           = this.vUnderline;
            font.HasUnderline         = this.HasUnderline;
            font.vVerticalAlignment   = this.vVerticalAlignment;
            font.HasVerticalAlignment = this.HasVerticalAlignment;
            font.vFontScheme          = this.vFontScheme;
            font.HasFontScheme        = this.HasFontScheme;

            return(font);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Append given text in the current theme's minor font and default font size.
        /// </summary>
        /// <param name="Text">The text.</param>
        public void AppendText(string Text)
        {
            SLFont font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
            font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);

            this.AppendText(Text, font);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Append given text in the current theme's minor font and default font size.
        /// </summary>
        /// <param name="Text">The text.</param>
        public void AppendText(string Text)
        {
            SLFont font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);

            font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);

            this.AppendText(Text, font);
        }
Exemplo n.º 4
0
        internal void FromDifferentialType(X14.DifferentialType dt)
        {
            this.SetAllNull();

            List <System.Drawing.Color> listempty = new List <System.Drawing.Color>();

            if (dt.Font != null)
            {
                HasFont       = true;
                this.fontReal = new SLFont(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, listempty, listempty);
                this.fontReal.FromFont(dt.Font);
            }

            if (dt.NumberingFormat != null)
            {
                HasNumberingFormat = true;
                this.nfFormatCode  = new SLNumberingFormat();
                this.nfFormatCode.FromNumberingFormat(dt.NumberingFormat);
            }

            if (dt.Fill != null)
            {
                HasFill       = true;
                this.fillReal = new SLFill(listempty, listempty);
                this.fillReal.FromFill(dt.Fill);
            }

            if (dt.Alignment != null)
            {
                HasAlignment   = true;
                this.alignReal = new SLAlignment();
                this.alignReal.FromAlignment(dt.Alignment);
            }

            if (dt.Border != null)
            {
                HasBorder       = true;
                this.borderReal = new SLBorder(listempty, listempty);
                this.borderReal.FromBorder(dt.Border);
            }

            if (dt.Protection != null)
            {
                HasProtection       = true;
                this.protectionReal = new SLProtection();
                this.protectionReal.FromProtection(dt.Protection);
            }

            Sync();
        }
Exemplo n.º 5
0
        private void SetAllNull()
        {
            List <System.Drawing.Color> listempty = new List <System.Drawing.Color>();

            this.alignReal      = new SLAlignment();
            HasAlignment        = false;
            this.protectionReal = new SLProtection();
            HasProtection       = false;
            this.nfFormatCode   = new SLNumberingFormat();
            HasNumberingFormat  = false;
            this.fontReal       = new SLFont(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, listempty, listempty);
            HasFont             = false;
            this.fillReal       = new SLFill(listempty, listempty);
            HasFill             = false;
            this.borderReal     = new SLBorder(listempty, listempty);
            HasBorder           = false;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Append given text with a given font style.
        /// </summary>
        /// <param name="Text">The text.</param>
        /// <param name="TextFont">The font style.</param>
        public void AppendText(string Text, SLFont TextFont)
        {
            Run           run      = new Run();
            RunProperties runprops = new RunProperties();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            bool           bFound = false;
            OpenXmlElement oxe    = istrReal.FirstChild;

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

            if (bFound)
            {
                istrReal.InsertAfter(run, oxe);
            }
            else
            {
                istrReal.PrependChild(run);
            }
        }
Exemplo n.º 7
0
        private string StyleToAppend(SLFont ft)
        {
            string result = string.Empty;

            string sBoldItalic = string.Empty;
            if ((ft.Bold != null && ft.Bold.Value) && (ft.Italic != null && ft.Italic.Value))
            {
                sBoldItalic = "Bold Italic";
            }
            else if (ft.Bold != null && ft.Bold.Value)
            {
                sBoldItalic = "Bold";
            }
            else if (ft.Italic != null && ft.Italic.Value)
            {
                sBoldItalic = "Italic";
            }
            else
            {
                sBoldItalic = "Regular";
            }

            // if it's bold or italic, there must at least be a font name or font scheme
            if (!sBoldItalic.Equals("Regular"))
            {
                if (ft.FontName == null || ft.FontName.Length == 0)
                {
                    if (ft.FontScheme == FontSchemeValues.None) ft.FontScheme = FontSchemeValues.Minor;
                }
            }

            string sFontStyle = string.Empty;
            if (this.FontStyleSwitch)
            {
                sFontStyle = this.FontStyleToAppend(ft, sBoldItalic);
                // must write something
                if (sFontStyle.Length == 0) sFontStyle = "&\"-,Regular\"";
            }
            else
            {
                sFontStyle = this.FontStyleToAppend(ft, sBoldItalic);
            }
            
            if (sFontStyle.Length == 0 || sFontStyle.Equals("&\"-,Regular\""))
            {
                this.FontStyleSwitch = false;
            }
            else
            {
                this.FontStyleSwitch = true;
            }

            result += sFontStyle;

            if (this.FontSizeSwitch)
            {
                // font size switch is on, so must write something
                if (ft.FontSize != null)
                {
                    result += string.Format("&{0}", (int)ft.FontSize);
                }
                else
                {
                    result += string.Format("&{0}", (int)SLConstants.DefaultFontSize);
                }
                this.FontSizeSwitch = false;
            }
            else
            {
                if (ft.FontSize != null && (int)ft.FontSize != (int)SLConstants.DefaultFontSize)
                {
                    result += string.Format("&{0}", (int)ft.FontSize);
                    this.FontSizeSwitch = true;
                }
            }

            if (this.StrikeSwitch)
            {
                // already in strikethrough mode
                // so only write something if given font style has no strikethrough
                if (ft.Strike == null || (ft.Strike != null && !ft.Strike.Value))
                {
                    result += "&S";
                    this.StrikeSwitch = false;
                }
            }
            else
            {
                if (ft.Strike != null && ft.Strike.Value)
                {
                    result += "&S";
                    this.StrikeSwitch = true;
                }
            }

            if (this.SuperscriptSwitch)
            {
                // already in superscript mode
                // so only write something if given font style has no superscript
                if (!ft.HasVerticalAlignment
                    || (ft.HasVerticalAlignment && ft.VerticalAlignment != VerticalAlignmentRunValues.Superscript))
                {
                    result += "&X";
                    this.SuperscriptSwitch = false;
                }
            }
            else
            {
                if (ft.HasVerticalAlignment && ft.VerticalAlignment == VerticalAlignmentRunValues.Superscript)
                {
                    result += "&X";
                    this.SuperscriptSwitch = true;
                }
            }

            if (this.SubscriptSwitch)
            {
                // already in subscript mode
                // so only write something if given font style has no subscript
                if (!ft.HasVerticalAlignment
                    || (ft.HasVerticalAlignment && ft.VerticalAlignment != VerticalAlignmentRunValues.Subscript))
                {
                    result += "&Y";
                    this.SubscriptSwitch = false;
                }
            }
            else
            {
                if (ft.HasVerticalAlignment && ft.VerticalAlignment == VerticalAlignmentRunValues.Subscript)
                {
                    result += "&Y";
                    this.SubscriptSwitch = true;
                }
            }

            if (this.UnderlineSwitch)
            {
                // already in underline mode
                // so only write something if given font style has no underline
                if (!ft.HasUnderline
                    || (ft.HasUnderline && ft.Underline != UnderlineValues.Single))
                {
                    // take care of SingleAccounting?
                    result += "&U";
                    this.UnderlineSwitch = false;
                }
            }
            else
            {
                if (ft.HasUnderline && ft.Underline == UnderlineValues.Single)
                {
                    // take care of SingleAccounting?
                    result += "&U";
                    this.UnderlineSwitch = true;
                }
            }

            if (this.DoubleUnderlineSwitch)
            {
                // already in double underline mode
                // so only write something if given font style has no double underline
                if (!ft.HasUnderline
                    || (ft.HasUnderline && ft.Underline == UnderlineValues.Double))
                {
                    // take cae of DoubleAccounting?
                    result += "&E";
                    this.DoubleUnderlineSwitch = false;
                }
            }
            else
            {
                if (ft.HasUnderline && ft.Underline == UnderlineValues.Double)
                {
                    // take cae of DoubleAccounting?
                    result += "&E";
                    this.DoubleUnderlineSwitch = true;
                }
            }

            if (this.FontColorSwitch)
            {
                if (ft.HasFontColor)
                {
                    result += this.FontColorToAppend(ft.clrFontColor);
                }
                else
                {
                    result += "&K01+000";
                    this.FontColorSwitch = false;
                }
            }
            else
            {
                if (ft.HasFontColor)
                {
                    result += this.FontColorToAppend(ft.clrFontColor);
                    this.FontColorSwitch = true;
                }
            }

            return result;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Append text to the first page footer.
 /// </summary>
 /// <param name="FontStyle">The font style of the text.</param>
 /// <param name="Text">The text to be appended.</param>
 public void AppendFirstFooter(SLFont FontStyle, string Text)
 {
     if (this.HFSection != SLHeaderFooterSection.FirstFooter) ResetSwitches();
     this.FirstFooterText += string.Format("{0}{1}", this.StyleToAppend(FontStyle), Text);
     this.HFSection = SLHeaderFooterSection.FirstFooter;
 }
Exemplo n.º 9
0
        private string FontStyleToAppend(SLFont ft, string BoldItalic)
        {
            string result = string.Empty;

            if (ft.HasFontScheme)
            {
                if (ft.FontScheme == FontSchemeValues.Minor)
                {
                    result = string.Format("&\"-,{0}\"", BoldItalic);
                }
                else if (ft.FontScheme == FontSchemeValues.Major)
                {
                    result = string.Format("&\"+,{0}\"", BoldItalic);
                }
                else
                {
                    if (ft.FontName != null && ft.FontName.Length > 0)
                    {
                        result = string.Format("&\"{1},{0}\"", BoldItalic, ft.FontName);
                    }
                    else
                    {
                        result = string.Format("&\"-,{0}\"", BoldItalic);
                    }
                }
            }
            else if (ft.FontName != null && ft.FontName.Length > 0)
            {
                result = string.Format("&\"{1},{0}\"", BoldItalic, ft.FontName);
            }

            return result;
        }
Exemplo n.º 10
0
        internal void LoadStylesheet()
        {
            countStyle = 0;
            listStyle = new List<string>();
            dictStyleHash = new Dictionary<string, int>();

            NumberFormatGeneralId = -1;
            NumberFormatGeneralText = SLConstants.NumberFormatGeneral;
            NextNumberFormatId = SLConstants.CustomNumberFormatIdStartIndex;
            dictStyleNumberingFormat = new Dictionary<int, string>();
            dictStyleNumberingFormatHash = new Dictionary<string, int>();

            countStyleFont = 0;
            listStyleFont = new List<string>();
            dictStyleFontHash = new Dictionary<string, int>();

            countStyleFill = 0;
            listStyleFill = new List<string>();
            dictStyleFillHash = new Dictionary<string, int>();

            countStyleBorder = 0;
            listStyleBorder = new List<string>();
            dictStyleBorderHash = new Dictionary<string, int>();

            countStyleCellStyle = 0;
            listStyleCellStyle = new List<string>();
            dictStyleCellStyleHash = new Dictionary<string, int>();

            countStyleCellStyleFormat = 0;
            listStyleCellStyleFormat = new List<string>();
            dictStyleCellStyleFormatHash = new Dictionary<string, int>();

            countStyleDifferentialFormat = 0;
            listStyleDifferentialFormat = new List<string>();
            dictStyleDifferentialFormatHash = new Dictionary<string, int>();

            countStyleTableStyle = 0;
            listStyleTableStyle = new List<string>();
            dictStyleTableStyleHash = new Dictionary<string, int>();

            int i = 0;
            string sHash = string.Empty;

            if (wbp.WorkbookStylesPart != null)
            {
                WorkbookStylesPart wbsp = wbp.WorkbookStylesPart;

                this.NextNumberFormatId = SLConstants.CustomNumberFormatIdStartIndex;
                this.StylesheetColors = null;

                using (OpenXmlReader oxr = OpenXmlReader.Create(wbsp))
                {
                    while (oxr.Read())
                    {
                        if (oxr.ElementType == typeof(NumberingFormats))
                        {
                            NumberingFormat nf;
                            using (OpenXmlReader oxrNF = OpenXmlReader.Create((NumberingFormats)oxr.LoadCurrentElement()))
                            {
                                while (oxrNF.Read())
                                {
                                    if (oxrNF.ElementType == typeof(NumberingFormat))
                                    {
                                        nf = (NumberingFormat)oxrNF.LoadCurrentElement();
                                        if (nf.NumberFormatId != null && nf.FormatCode != null)
                                        {
                                            i = (int)nf.NumberFormatId.Value;
                                            sHash = nf.FormatCode.Value;
                                            dictStyleNumberingFormat[i] = sHash;
                                            dictStyleNumberingFormatHash[sHash] = i;

                                            if (sHash.Equals(SLConstants.NumberFormatGeneral, StringComparison.InvariantCultureIgnoreCase))
                                            {
                                                this.NumberFormatGeneralText = sHash;
                                                this.NumberFormatGeneralId = i;
                                            }

                                            // if there's a number format greater than the next number,
                                            // obviously we want to increment.
                                            // if there's a current number equal to the next number,
                                            // we want to increment because this number exists!
                                            // Emphasis on *next* number
                                            if (i >= this.NextNumberFormatId)
                                            {
                                                this.NextNumberFormatId = this.NextNumberFormatId + 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (oxr.ElementType == typeof(Fonts))
                        {
                            SLFont fontSL;
                            using (OpenXmlReader oxrFont = OpenXmlReader.Create((Fonts)oxr.LoadCurrentElement()))
                            {
                                while (oxrFont.Read())
                                {
                                    if (oxrFont.ElementType == typeof(Font))
                                    {
                                        fontSL = new SLFont(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                                        fontSL.FromFont((Font)oxrFont.LoadCurrentElement());
                                        this.ForceSaveToStylesheetFont(fontSL.ToHash());
                                    }
                                }
                            }
                            countStyleFont = listStyleFont.Count;
                        }
                        else if (oxr.ElementType == typeof(Fills))
                        {
                            SLFill fillSL;
                            using (OpenXmlReader oxrFill = OpenXmlReader.Create((Fills)oxr.LoadCurrentElement()))
                            {
                                while (oxrFill.Read())
                                {
                                    if (oxrFill.ElementType == typeof(Fill))
                                    {
                                        fillSL = new SLFill(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                                        fillSL.FromFill((Fill)oxrFill.LoadCurrentElement());
                                        this.ForceSaveToStylesheetFill(fillSL.ToHash());
                                    }
                                }
                            }
                            countStyleFill = listStyleFill.Count;
                        }
                        else if (oxr.ElementType == typeof(Borders))
                        {
                            SLBorder borderSL;
                            using (OpenXmlReader oxrBorder = OpenXmlReader.Create((Borders)oxr.LoadCurrentElement()))
                            {
                                while (oxrBorder.Read())
                                {
                                    if (oxrBorder.ElementType == typeof(Border))
                                    {
                                        borderSL = new SLBorder(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                                        borderSL.FromBorder((Border)oxrBorder.LoadCurrentElement());
                                        this.ForceSaveToStylesheetBorder(borderSL.ToHash());
                                    }
                                }
                            }
                            countStyleBorder = listStyleBorder.Count;
                        }
                        else if (oxr.ElementType == typeof(CellStyleFormats))
                        {
                            SLStyle styleSL;
                            using (OpenXmlReader oxrCellStyleFormats = OpenXmlReader.Create((CellStyleFormats)oxr.LoadCurrentElement()))
                            {
                                while (oxrCellStyleFormats.Read())
                                {
                                    if (oxrCellStyleFormats.ElementType == typeof(CellFormat))
                                    {
                                        styleSL = new SLStyle(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                                        styleSL.FromCellFormat((CellFormat)oxrCellStyleFormats.LoadCurrentElement());
                                        this.TranslateStyleIdsToStyles(ref styleSL);
                                        this.ForceSaveToStylesheetCellStylesFormat(styleSL.ToHash());
                                    }
                                }
                            }
                            countStyleCellStyleFormat = listStyleCellStyleFormat.Count;
                        }
                        else if (oxr.ElementType == typeof(CellFormats))
                        {
                            SLStyle styleSL;
                            using (OpenXmlReader oxrCellFormats = OpenXmlReader.Create((CellFormats)oxr.LoadCurrentElement()))
                            {
                                while (oxrCellFormats.Read())
                                {
                                    if (oxrCellFormats.ElementType == typeof(CellFormat))
                                    {
                                        styleSL = new SLStyle(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                                        styleSL.FromCellFormat((CellFormat)oxrCellFormats.LoadCurrentElement());
                                        this.TranslateStyleIdsToStyles(ref styleSL);
                                        this.ForceSaveToStylesheet(styleSL.ToHash());
                                    }
                                }
                            }
                            countStyle = listStyle.Count;
                        }
                        else if (oxr.ElementType == typeof(CellStyles))
                        {
                            SLCellStyle csSL;
                            using (OpenXmlReader oxrCellStyles = OpenXmlReader.Create((CellStyles)oxr.LoadCurrentElement()))
                            {
                                while (oxrCellStyles.Read())
                                {
                                    if (oxrCellStyles.ElementType == typeof(CellStyle))
                                    {
                                        csSL = new SLCellStyle();
                                        csSL.FromCellStyle((CellStyle)oxrCellStyles.LoadCurrentElement());
                                        this.ForceSaveToStylesheetCellStyle(csSL.ToHash());
                                    }
                                }
                            }
                            countStyleCellStyle = listStyleCellStyle.Count;
                        }
                        else if (oxr.ElementType == typeof(DifferentialFormats))
                        {
                            SLDifferentialFormat dfSL;
                            using (OpenXmlReader oxrDiff = OpenXmlReader.Create((DifferentialFormats)oxr.LoadCurrentElement()))
                            {
                                while (oxrDiff.Read())
                                {
                                    if (oxrDiff.ElementType == typeof(DifferentialFormat))
                                    {
                                        dfSL = new SLDifferentialFormat();
                                        dfSL.FromDifferentialFormat((DifferentialFormat)oxrDiff.LoadCurrentElement());
                                        this.ForceSaveToStylesheetDifferentialFormat(dfSL.ToHash());
                                    }
                                }
                            }
                            countStyleDifferentialFormat = listStyleDifferentialFormat.Count;
                        }
                        else if (oxr.ElementType == typeof(TableStyles))
                        {
                            TableStyles tss = (TableStyles)oxr.LoadCurrentElement();
                            SLTableStyle tsSL;
                            i = 0;
                            using (OpenXmlReader oxrTableStyles = OpenXmlReader.Create(tss))
                            {
                                while (oxrTableStyles.Read())
                                {
                                    if (oxrTableStyles.ElementType == typeof(TableStyle))
                                    {
                                        tsSL = new SLTableStyle();
                                        tsSL.FromTableStyle((TableStyle)oxrTableStyles.LoadCurrentElement());
                                        sHash = tsSL.ToHash();
                                        listStyleTableStyle.Add(sHash);
                                        dictStyleTableStyleHash[sHash] = i;
                                        ++i;
                                    }
                                }
                            }
                            countStyleTableStyle = listStyleTableStyle.Count;

                            if (tss.DefaultTableStyle != null)
                            {
                                this.TableStylesDefaultTableStyle = tss.DefaultTableStyle.Value;
                            }
                            else
                            {
                                this.TableStylesDefaultTableStyle = string.Empty;
                            }

                            if (tss.DefaultPivotStyle != null)
                            {
                                this.TableStylesDefaultPivotStyle = tss.DefaultPivotStyle.Value;
                            }
                            else
                            {
                                this.TableStylesDefaultPivotStyle = string.Empty;
                            }
                        }
                        else if (oxr.ElementType == typeof(Colors))
                        {
                            this.StylesheetColors = (Colors)(oxr.LoadCurrentElement().CloneNode(true));
                        }
                    }
                }

                // Force a "General" number format to be saved.
                // Upper case is used by LibreOffice. Is it case insensitive?
                if (this.NumberFormatGeneralId < 0)
                {
                    if (!dictStyleNumberingFormat.ContainsKey(0))
                    {
                        this.NumberFormatGeneralId = 0;
                        this.NumberFormatGeneralText = SLConstants.NumberFormatGeneral;
                        dictStyleNumberingFormat[this.NumberFormatGeneralId] = this.NumberFormatGeneralText;
                        dictStyleNumberingFormatHash[this.NumberFormatGeneralText] = this.NumberFormatGeneralId;
                    }
                    else
                    {
                        this.NumberFormatGeneralId = this.NextNumberFormatId;
                        this.NumberFormatGeneralText = SLConstants.NumberFormatGeneral;
                        dictStyleNumberingFormat[this.NumberFormatGeneralId] = this.NumberFormatGeneralText;
                        dictStyleNumberingFormatHash[this.NumberFormatGeneralText] = this.NumberFormatGeneralId;

                        ++this.NextNumberFormatId;
                    }
                }

                if (listStyleFont.Count == 0)
                {
                    SLFont fontSL = new SLFont(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                    fontSL.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    fontSL.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.SaveToStylesheetFont(fontSL.ToHash());
                }

                if (listStyleFill.Count == 0)
                {
                    SLFill fillNone = new SLFill(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                    fillNone.SetPatternType(PatternValues.None);
                    this.SaveToStylesheetFill(fillNone.ToHash());

                    SLFill fillGray125 = new SLFill(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                    fillGray125.SetPatternType(PatternValues.Gray125);
                    this.SaveToStylesheetFill(fillGray125.ToHash());
                }
                else
                {
                    // make sure there's at least a "none" pattern
                    SLFill fillNone = new SLFill(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                    fillNone.SetPatternType(PatternValues.None);
                    this.SaveToStylesheetFill(fillNone.ToHash());
                }

                // make sure there's at least an empty border
                SLBorder borderEmpty = new SLBorder(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                this.SaveToStylesheetBorder(borderEmpty.ToHash());

                int iCanonicalCellStyleFormatId = 0;
                SLStyle style = new SLStyle(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                style.FormatCode = this.NumberFormatGeneralText;
                style.fontReal.FromHash(listStyleFont[0]);
                style.Fill.SetPatternType(PatternValues.None);
                style.Border = new SLBorder(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);

                // there's at least one cell style format
                iCanonicalCellStyleFormatId = this.SaveToStylesheetCellStylesFormat(style.ToHash());

                // there's at least one style
                style.CellStyleFormatId = (uint)iCanonicalCellStyleFormatId;
                this.SaveToStylesheet(style.ToHash());

                if (listStyleCellStyle.Count == 0)
                {
                    SLCellStyle csNormal = new SLCellStyle();
                    csNormal.Name = "Normal";
                    //csNormal.FormatId = 0;
                    csNormal.FormatId = (uint)iCanonicalCellStyleFormatId;
                    csNormal.BuiltinId = 0;
                    this.SaveToStylesheetCellStyle(csNormal.ToHash());
                }
            }
            else
            {
                // no numbering format by default
                this.NextNumberFormatId = SLConstants.CustomNumberFormatIdStartIndex;

                this.NumberFormatGeneralId = 0;
                this.NumberFormatGeneralText = SLConstants.NumberFormatGeneral;
                dictStyleNumberingFormat[this.NumberFormatGeneralId] = this.NumberFormatGeneralText;
                dictStyleNumberingFormatHash[this.NumberFormatGeneralText] = this.NumberFormatGeneralId;

                SLFont fontDefault = new SLFont(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                fontDefault.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                fontDefault.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                this.SaveToStylesheetFont(fontDefault.ToHash());

                SLFill fillNone = new SLFill(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                fillNone.SetPatternType(PatternValues.None);
                this.SaveToStylesheetFill(fillNone.ToHash());

                SLFill fillGray125 = new SLFill(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                fillGray125.SetPatternType(PatternValues.Gray125);
                this.SaveToStylesheetFill(fillGray125.ToHash());

                SLBorder borderEmpty = new SLBorder(SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                this.SaveToStylesheetBorder(borderEmpty.ToHash());

                int iCanonicalCellStyleFormatId = 0;
                SLStyle style = new SLStyle(SimpleTheme.MajorLatinFont, SimpleTheme.MinorLatinFont, SimpleTheme.listThemeColors, SimpleTheme.listIndexedColors);
                style.FormatCode = this.NumberFormatGeneralText;
                style.Font = fontDefault;
                style.Fill = fillNone;
                style.Border = borderEmpty;
                iCanonicalCellStyleFormatId = this.SaveToStylesheetCellStylesFormat(style.ToHash());

                style.CellStyleFormatId = (uint)iCanonicalCellStyleFormatId;
                this.SaveToStylesheet(style.ToHash());

                SLCellStyle csNormal = new SLCellStyle();
                csNormal.Name = "Normal";
                //csNormal.FormatId = 0;
                csNormal.FormatId = (uint)iCanonicalCellStyleFormatId;
                csNormal.BuiltinId = 0;
                this.SaveToStylesheetCellStyle(csNormal.ToHash());

                this.TableStylesDefaultTableStyle = SLConstants.DefaultTableStyle;
                this.TableStylesDefaultPivotStyle = SLConstants.DefaultPivotStyle;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Apply a named cell style. Existing styles are kept, unless the chosen named cell style overrides those styles.
        /// </summary>
        /// <param name="NamedCellStyle">The named cell style to be applied.</param>
        public void ApplyNamedCellStyle(SLNamedCellStyleValues NamedCellStyle)
        {
            SLFont font;
            SLFill fill;
            SLBorder border;

            switch (NamedCellStyle)
            {
                case SLNamedCellStyleValues.Normal:
                    RemoveFormatCode();

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    this.Font = font;

                    RemoveFill();
                    RemoveBorder();

                    // normal is the only one that removes alignment
                    RemoveAlignment();
                    break;
                case SLNamedCellStyleValues.Bad:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x9C, 0, 0x06);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xC7, 0xCE));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Good:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0, 0x61, 0);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xC6, 0xEF, 0xCE));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Neutral:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x65, 0);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xEB, 0x9C));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Calculation:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Bold = true;
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0xFA, 0x7D, 0);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.LeftBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                    border.RightBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                    border.TopBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                    border.BottomBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.CheckCell:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xA5, 0xA5, 0xA5));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.LeftBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.LeftBorder.BorderStyle = BorderStyleValues.Double;
                    border.RightBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.RightBorder.BorderStyle = BorderStyleValues.Double;
                    border.TopBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.TopBorder.BorderStyle = BorderStyleValues.Double;
                    border.BottomBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Double;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.ExplanatoryText:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Italic = true;
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    this.Font = font;

                    // no change to fill

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Input:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x76);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xCC, 0x99));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.LeftBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                    border.RightBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                    border.TopBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                    border.BottomBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x7F, 0x7F, 0x7F);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.LinkedCell:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0xFA, 0x7D, 0);
                    this.Font = font;

                    // no change to fill

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.BottomBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0xFF, 0x80, 0x01);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Double;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.Note:
                    // no change to format code

                    // Note doesn't change font or font size

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xFF, 0xCC));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.LeftBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0xB2, 0xB2, 0xB2);
                    border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                    border.RightBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0xB2, 0xB2, 0xB2);
                    border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                    border.TopBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0xB2, 0xB2, 0xB2);
                    border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                    border.BottomBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0xB2, 0xB2, 0xB2);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.Output:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Bold = true;
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(System.Drawing.Color.FromArgb(0xFF, 0xF2, 0xF2, 0xF2));
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.LeftBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.LeftBorder.BorderStyle = BorderStyleValues.Thin;
                    border.RightBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.RightBorder.BorderStyle = BorderStyleValues.Thin;
                    border.TopBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                    border.BottomBorder.Color = System.Drawing.Color.FromArgb(0xFF, 0x3F, 0x3F, 0x3F);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Thin;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.WarningText:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0xFF, 0, 0);
                    this.Font = font;

                    // no change to fill

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Heading1:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.Heading1FontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark2Color);
                    this.Font = font;

                    // no change to fill

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.BottomBorder.SetBorderThemeColor(SLThemeColorIndexValues.Accent1Color);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Thick;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.Heading2:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.Heading2FontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark2Color);
                    this.Font = font;

                    // no change to fill

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.BottomBorder.SetBorderThemeColor(SLThemeColorIndexValues.Accent1Color, 0.499984740745262);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Thick;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.Heading3:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark2Color);
                    this.Font = font;

                    // no change to fill

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.BottomBorder.SetBorderThemeColor(SLThemeColorIndexValues.Accent1Color, 0.399975585192419);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Medium;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.Heading4:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark2Color);
                    this.Font = font;

                    // no change to fill

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Title:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Major, SLConstants.TitleFontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark2Color);
                    this.Font = font;

                    // no change to fill

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Total:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.Bold = true;
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    // no change to fill

                    border = new SLBorder(this.listThemeColors, this.listIndexedColors);
                    border.TopBorder.SetBorderThemeColor(SLThemeColorIndexValues.Accent1Color);
                    border.TopBorder.BorderStyle = BorderStyleValues.Thin;
                    border.BottomBorder.SetBorderThemeColor(SLThemeColorIndexValues.Accent1Color);
                    border.BottomBorder.BorderStyle = BorderStyleValues.Double;
                    this.Border = border;
                    break;
                case SLNamedCellStyleValues.Accent1:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent1Color);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent1Percentage20:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent1Color, 0.799981688894314);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent1Percentage40:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent1Color, 0.599993896298105);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent1Percentage60:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent1Color, 0.399975585192419);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent2:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent2Color);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent2Percentage20:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent2Color, 0.799981688894314);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent2Percentage40:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent2Color, 0.599993896298105);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent2Percentage60:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent2Color, 0.399975585192419);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent3:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent3Color);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent3Percentage20:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent3Color, 0.799981688894314);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent3Percentage40:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent3Color, 0.599993896298105);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent3Percentage60:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent3Color, 0.399975585192419);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent4:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent4Color);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent4Percentage20:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent4Color, 0.799981688894314);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent4Percentage40:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent4Color, 0.599993896298105);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent4Percentage60:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent4Color, 0.399975585192419);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent5:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent5Color);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent5Percentage20:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent5Color, 0.799981688894314);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent5Percentage40:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent5Color, 0.599993896298105);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent5Percentage60:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent5Color, 0.399975585192419);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent6:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent6Color);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent6Percentage20:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent6Color, 0.799981688894314);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent6Percentage40:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Dark1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent6Color, 0.599993896298105);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Accent6Percentage60:
                    // no change to format code

                    font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
                    font.SetFont(FontSchemeValues.Minor, SLConstants.DefaultFontSize);
                    font.SetFontThemeColor(SLThemeColorIndexValues.Light1Color);
                    this.Font = font;

                    fill = new SLFill(this.listThemeColors, this.listIndexedColors);
                    fill.SetPatternForegroundColor(SLThemeColorIndexValues.Accent6Color, 0.399975585192419);
                    fill.SetPatternType(PatternValues.Solid);
                    this.Fill = fill;

                    // no change to border
                    break;
                case SLNamedCellStyleValues.Comma:
                    this.FormatCode = "_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)";
                    // not using the "builtin" format ID
                    //this.nfFormatCode.NumberFormatId = 43;

                    // the font, fill and border are not changed

                    // TODO get "actual" comma character from regional settings?
                    break;
                case SLNamedCellStyleValues.Comma0:
                    this.FormatCode = "_(* #,##0_);_(* \\(#,##0\\);_(* \"-\"_);_(@_)";
                    // not using the "builtin" format ID
                    //this.nfFormatCode.NumberFormatId = 41;

                    // the font, fill and border are not changed

                    // TODO get "actual" comma character from regional settings?
                    break;
                case SLNamedCellStyleValues.Currency:
                    this.FormatCode = "_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)";
                    // not using the "builtin" format ID
                    //this.nfFormatCode.NumberFormatId = 44;

                    // the font, fill and border are not changed

                    // TODO get "actual" currency character from regional settings?
                    break;
                case SLNamedCellStyleValues.Currency0:
                    this.FormatCode = "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)";
                    // not using the "builtin" format ID
                    //this.nfFormatCode.NumberFormatId = 42;

                    // the font, fill and border are not changed

                    // TODO get "actual" currency character from regional settings?
                    break;
                case SLNamedCellStyleValues.Percentage:
                    this.FormatCode = "0%";
                    // not using the "builtin" format ID
                    //this.nfFormatCode.NumberFormatId = 9;

                    // the font, fill and border are not changed
                    break;
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Remove any existing font properties.
 /// </summary>
 public void RemoveFont()
 {
     this.FontId = null;
     this.fontReal = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);
     HasFont = false;
 }
        private void SetAllNull()
        {
            List<System.Drawing.Color> listempty = new List<System.Drawing.Color>();

            this.alignReal = new SLAlignment();
            HasAlignment = false;
            this.protectionReal = new SLProtection();
            HasProtection = false;
            this.nfFormatCode = new SLNumberingFormat();
            HasNumberingFormat = false;
            this.fontReal = new SLFont(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, listempty, listempty);
            HasFont = false;
            this.fillReal = new SLFill(listempty, listempty);
            HasFill = false;
            this.borderReal = new SLBorder(listempty, listempty);
            HasBorder = false;
        }
        internal void FromDifferentialType(X14.DifferentialType dt)
        {
            this.SetAllNull();

            List<System.Drawing.Color> listempty = new List<System.Drawing.Color>();

            if (dt.Font != null)
            {
                HasFont = true;
                this.fontReal = new SLFont(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, listempty, listempty);
                this.fontReal.FromFont(dt.Font);
            }

            if (dt.NumberingFormat != null)
            {
                HasNumberingFormat = true;
                this.nfFormatCode = new SLNumberingFormat();
                this.nfFormatCode.FromNumberingFormat(dt.NumberingFormat);
            }

            if (dt.Fill != null)
            {
                HasFill = true;
                this.fillReal = new SLFill(listempty, listempty);
                this.fillReal.FromFill(dt.Fill);
            }

            if (dt.Alignment != null)
            {
                HasAlignment = true;
                this.alignReal = new SLAlignment();
                this.alignReal.FromAlignment(dt.Alignment);
            }

            if (dt.Border != null)
            {
                HasBorder = true;
                this.borderReal = new SLBorder(listempty, listempty);
                this.borderReal.FromBorder(dt.Border);
            }

            if (dt.Protection != null)
            {
                HasProtection = true;
                this.protectionReal = new SLProtection();
                this.protectionReal.FromProtection(dt.Protection);
            }

            Sync();
        }
Exemplo n.º 15
0
        internal SLFont Clone()
        {
            SLFont font = new SLFont(this.MajorFont, this.MinorFont, this.listThemeColors, this.listIndexedColors);

            font.FontName = this.FontName;
            font.CharacterSet = this.CharacterSet;
            font.FontFamily = this.FontFamily;
            font.Bold = this.Bold;
            font.Italic = this.Italic;
            font.Strike = this.Strike;
            font.Outline = this.Outline;
            font.Shadow = this.Shadow;
            font.Condense = this.Condense;
            font.Extend = this.Extend;
            font.clrFontColor = this.clrFontColor.Clone();
            font.HasFontColor = this.HasFontColor;
            font.FontSize = this.FontSize;
            font.vUnderline = this.vUnderline;
            font.HasUnderline = this.HasUnderline;
            font.vVerticalAlignment = this.vVerticalAlignment;
            font.HasVerticalAlignment = this.HasVerticalAlignment;
            font.vFontScheme = this.vFontScheme;
            font.HasFontScheme = this.HasFontScheme;

            return font;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Append given text with a given font style.
        /// </summary>
        /// <param name="Text">The text.</param>
        /// <param name="TextFont">The font style.</param>
        public void AppendText(string Text, SLFont TextFont)
        {
            Run run = new Run();
            RunProperties runprops = new RunProperties();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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