コード例 #1
0
        internal SLDifferentialFormat Clone()
        {
            SLDifferentialFormat df = new SLDifferentialFormat();

            df.HasAlignment       = this.HasAlignment;
            df.alignReal          = this.alignReal.Clone();
            df.HasProtection      = this.HasProtection;
            df.protectionReal     = this.protectionReal.Clone();
            df.HasNumberingFormat = this.HasNumberingFormat;
            df.nfFormatCode       = this.nfFormatCode.Clone();
            df.HasFont            = this.HasFont;
            df.fontReal           = this.fontReal.Clone();
            df.HasFill            = this.HasFill;
            df.fillReal           = this.fillReal.Clone();
            df.HasBorder          = this.HasBorder;
            df.borderReal         = this.borderReal.Clone();

            return(df);
        }
コード例 #2
0
        private void HighlightCellsWithUniques(SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.UniqueValues;

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #3
0
        private void HighlightCellsWithFormula(string Formula, SLDifferentialFormat HighlightStyle)
        {
            if (Formula.StartsWith("=")) Formula = Formula.Substring(1);

            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.Expression;
            cfr.Formulas.Add(new DocumentFormat.OpenXml.Spreadsheet.Formula(Formula));
            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #4
0
        private void HighlightCellsWithDatesOccurring(TimePeriodValues DatePeriod, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.TimePeriod;
            cfr.TimePeriod = DatePeriod;
            cfr.HasTimePeriod = true;

            Formula f = new Formula();
            string sRef = string.Empty;
            if (this.SequenceOfReferences.Count > 0)
            {
                sRef = SLTool.ToCellReference(this.SequenceOfReferences[0].StartRowIndex, this.SequenceOfReferences[0].StartColumnIndex);
            }
            switch (DatePeriod)
            {
                case TimePeriodValues.Yesterday:
                    f.Text = string.Format("FLOOR({0},1)=TODAY()-1", sRef);
                    break;
                case TimePeriodValues.Today:
                    f.Text = string.Format("FLOOR({0},1)=TODAY()", sRef);
                    break;
                case TimePeriodValues.Tomorrow:
                    f.Text = string.Format("FLOOR({0},1)=TODAY()+1", sRef);
                    break;
                case TimePeriodValues.Last7Days:
                    f.Text = string.Format("AND(TODAY()-FLOOR({0},1)<=6,FLOOR({0},1)<=TODAY())", sRef);
                    break;
                case TimePeriodValues.LastWeek:
                    f.Text = string.Format("AND(TODAY()-ROUNDDOWN({0},0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN({0},0)<(WEEKDAY(TODAY())+7))", sRef);
                    break;
                case TimePeriodValues.ThisWeek:
                    f.Text = string.Format("AND(TODAY()-ROUNDDOWN({0},0)<=WEEKDAY(TODAY())-1,ROUNDDOWN({0},0)-TODAY()<=7-WEEKDAY(TODAY()))", sRef);
                    break;
                case TimePeriodValues.NextWeek:
                    f.Text = string.Format("AND(ROUNDDOWN({0},0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN({0},0)-TODAY()<(15-WEEKDAY(TODAY())))", sRef);
                    break;
                case TimePeriodValues.LastMonth:
                    f.Text = string.Format("AND(MONTH({0})=MONTH(EDATE(TODAY(),0-1)),YEAR({0})=YEAR(EDATE(TODAY(),0-1)))", sRef);
                    break;
                case TimePeriodValues.ThisMonth:
                    f.Text = string.Format("AND(MONTH({0})=MONTH(TODAY()),YEAR({0})=YEAR(TODAY()))", sRef);
                    break;
                case TimePeriodValues.NextMonth:
                    f.Text = string.Format("AND(MONTH({0})=MONTH(TODAY())+1,OR(YEAR({0})=YEAR(TODAY()),AND(MONTH({0})=12,YEAR({0})=YEAR(TODAY())+1)))", sRef);
                    break;
            }
            cfr.Formulas.Add(f);

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #5
0
        private void HighlightCellsLessThan(bool IncludeEquality, string Value, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.CellIs;
            cfr.Operator = IncludeEquality ? ConditionalFormattingOperatorValues.LessThanOrEqual : ConditionalFormattingOperatorValues.LessThan;
            cfr.HasOperator = true;

            cfr.Formulas.Add(this.GetFormulaFromText(Value));

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #6
0
        private void HighlightCellsInTopRange(bool IsTopRange, uint Rank, bool IsPercent, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.Top10;
            cfr.Bottom = !IsTopRange;
            cfr.Rank = Rank;
            cfr.Percent = IsPercent;

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #7
0
        private void HighlightCellsEndingWith(string Value, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Text = Value;

            Formula f = new Formula();
            string sRef = string.Empty;
            if (this.SequenceOfReferences.Count > 0)
            {
                sRef = SLTool.ToCellReference(this.SequenceOfReferences[0].StartRowIndex, this.SequenceOfReferences[0].StartColumnIndex);
            }
            cfr.Type = ConditionalFormatValues.EndsWith;
            cfr.Operator = ConditionalFormattingOperatorValues.EndsWith;
            cfr.HasOperator = true;
            f.Text = string.Format("RIGHT({0},{1})={2}", sRef, Value.Length, this.GetCleanedStringFromText(Value));
            cfr.Formulas.Add(f);

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #8
0
        private void HighlightCellsContainingText(bool IsContaining, string Value, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Text = Value;

            Formula f = new Formula();
            string sRef = string.Empty;
            if (this.SequenceOfReferences.Count > 0)
            {
                sRef = SLTool.ToCellReference(this.SequenceOfReferences[0].StartRowIndex, this.SequenceOfReferences[0].StartColumnIndex);
            }
            if (IsContaining)
            {
                cfr.Type = ConditionalFormatValues.ContainsText;
                cfr.Operator = ConditionalFormattingOperatorValues.ContainsText;
                cfr.HasOperator = true;
                f.Text = string.Format("NOT(ISERROR(SEARCH({0},{1})))", this.GetCleanedStringFromText(Value), sRef);
            }
            else
            {
                cfr.Type = ConditionalFormatValues.NotContainsText;
                cfr.Operator = ConditionalFormattingOperatorValues.NotContains;
                cfr.HasOperator = true;
                f.Text = string.Format("ISERROR(SEARCH({0},{1}))", this.GetCleanedStringFromText(Value), sRef);
            }
            cfr.Formulas.Add(f);

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #9
0
        private void HighlightCellsContainingErrors(bool ContainsErrors, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();

            Formula f = new Formula();
            string sRef = string.Empty;
            if (this.SequenceOfReferences.Count > 0)
            {
                sRef = SLTool.ToCellReference(this.SequenceOfReferences[0].StartRowIndex, this.SequenceOfReferences[0].StartColumnIndex);
            }
            if (ContainsErrors)
            {
                cfr.Type = ConditionalFormatValues.ContainsErrors;
                f.Text = string.Format("ISERROR({0})", sRef);
            }
            else
            {
                cfr.Type = ConditionalFormatValues.NotContainsErrors;
                f.Text = string.Format("NOT(ISERROR({0}))", sRef);
            }
            cfr.Formulas.Add(f);

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #10
0
        private void HighlightCellsBetween(bool IsBetween, string Value1, string Value2, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.CellIs;
            cfr.Operator = IsBetween ? ConditionalFormattingOperatorValues.Between : ConditionalFormattingOperatorValues.NotBetween;
            cfr.HasOperator = true;

            cfr.Formulas.Add(this.GetFormulaFromText(Value1));
            cfr.Formulas.Add(this.GetFormulaFromText(Value2));

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #11
0
        private void HighlightCellsAboveAverage(SLHighlightCellsAboveAverageValues AverageType, SLDifferentialFormat HighlightStyle)
        {
            SLConditionalFormattingRule cfr = new SLConditionalFormattingRule();
            cfr.Type = ConditionalFormatValues.AboveAverage;

            switch (AverageType)
            {
                case SLHighlightCellsAboveAverageValues.Above:
                    // that's all is needed!
                    break;
                case SLHighlightCellsAboveAverageValues.Below:
                    cfr.AboveAverage = false;
                    break;
                case SLHighlightCellsAboveAverageValues.EqualOrAbove:
                    cfr.EqualAverage = true;
                    break;
                case SLHighlightCellsAboveAverageValues.EqualOrBelow:
                    cfr.EqualAverage = true;
                    cfr.AboveAverage = false;
                    break;
                case SLHighlightCellsAboveAverageValues.OneStdDevAbove:
                    cfr.StdDev = 1;
                    break;
                case SLHighlightCellsAboveAverageValues.OneStdDevBelow:
                    cfr.AboveAverage = false;
                    cfr.StdDev = 1;
                    break;
                case SLHighlightCellsAboveAverageValues.TwoStdDevAbove:
                    cfr.StdDev = 2;
                    break;
                case SLHighlightCellsAboveAverageValues.TwoStdDevBelow:
                    cfr.AboveAverage = false;
                    cfr.StdDev = 2;
                    break;
                case SLHighlightCellsAboveAverageValues.ThreeStdDevAbove:
                    cfr.StdDev = 3;
                    break;
                case SLHighlightCellsAboveAverageValues.ThreeStdDevBelow:
                    cfr.AboveAverage = false;
                    cfr.StdDev = 3;
                    break;
            }

            cfr.DifferentialFormat = HighlightStyle.Clone();
            cfr.HasDifferentialFormat = true;

            this.AppendRule(cfr);
        }
コード例 #12
0
        internal SLDifferentialFormat TranslateToDifferentialFormat(SLStyle style)
        {
            style.Sync();
            SLDifferentialFormat df = new SLDifferentialFormat();
            if (style.HasNumberingFormat) df.FormatCode = style.FormatCode;

            if (style.Font.Italic != null && style.Font.Italic.Value) df.Font.Italic = true;
            if (style.Font.Bold != null && style.Font.Bold.Value) df.Font.Bold = true;
            if (style.Font.HasUnderline) df.Font.Underline = style.Font.Underline;
            if (style.Font.HasFontColor)
            {
                df.Font.clrFontColor = style.Font.clrFontColor.Clone();
                df.Font.HasFontColor = true;
            }
            if (style.Font.Strike != null && style.Font.Strike.Value) df.Font.Strike = true;

            if (style.HasBorder) df.Border = style.Border.Clone();
            if (style.HasFill) df.Fill = style.Fill.Clone();

            df.Sync();
            return df;
        }
コード例 #13
0
        internal SLDifferentialFormat TranslateToDifferentialFormat(SLHighlightCellsStyleValues style)
        {
            SLDifferentialFormat df = new SLDifferentialFormat();
            switch (style)
            {
                case SLHighlightCellsStyleValues.LightRedFillWithDarkRedText:
                    df.Font.Condense = false;
                    df.Font.Extend = false;
                    df.Font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x00, 0x06);
                    df.Fill.SetPatternBackgroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xC7, 0xCE));
                    break;
                case SLHighlightCellsStyleValues.YellowFillWithDarkYellowText:
                    df.Font.Condense = false;
                    df.Font.Extend = false;
                    df.Font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x65, 0x00);
                    df.Fill.SetPatternBackgroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xEB, 0x9C));
                    break;
                case SLHighlightCellsStyleValues.GreenFillWithDarkGreenText:
                    df.Font.Condense = false;
                    df.Font.Extend = false;
                    df.Font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x00, 0x61, 0x00);
                    df.Fill.SetPatternBackgroundColor(System.Drawing.Color.FromArgb(0xFF, 0xC6, 0xEF, 0xCE));
                    break;
                case SLHighlightCellsStyleValues.LightRedFill:
                    df.Fill.SetPatternBackgroundColor(System.Drawing.Color.FromArgb(0xFF, 0xFF, 0xC7, 0xCE));
                    break;
                case SLHighlightCellsStyleValues.RedText:
                    df.Font.Condense = false;
                    df.Font.Extend = false;
                    df.Font.FontColor = System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x00, 0x06);
                    break;
                case SLHighlightCellsStyleValues.RedBorder:
                    df.Border.SetLeftBorder(BorderStyleValues.Thin, System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x00, 0x06));
                    df.Border.SetRightBorder(BorderStyleValues.Thin, System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x00, 0x06));
                    df.Border.SetTopBorder(BorderStyleValues.Thin, System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x00, 0x06));
                    df.Border.SetBottomBorder(BorderStyleValues.Thin, System.Drawing.Color.FromArgb(0xFF, 0x9C, 0x00, 0x06));
                    break;
            }

            df.Sync();
            return df;
        }
コード例 #14
0
ファイル: StyleFunctions.cs プロジェクト: mousetwentytwo/test
        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;
            }
        }
コード例 #15
0
        internal SLDifferentialFormat Clone()
        {
            SLDifferentialFormat df = new SLDifferentialFormat();
            df.HasAlignment = this.HasAlignment;
            df.alignReal = this.alignReal.Clone();
            df.HasProtection = this.HasProtection;
            df.protectionReal = this.protectionReal.Clone();
            df.HasNumberingFormat = this.HasNumberingFormat;
            df.nfFormatCode = this.nfFormatCode.Clone();
            df.HasFont = this.HasFont;
            df.fontReal = this.fontReal.Clone();
            df.HasFill = this.HasFill;
            df.fillReal = this.fillReal.Clone();
            df.HasBorder = this.HasBorder;
            df.borderReal = this.borderReal.Clone();

            return df;
        }