Ejemplo n.º 1
0
        private void UiStyleManager_IsStyleChanged(object sender, StyleChangeEventArgs e)
        {
            var accentColor = e.Accent.Resources["AccentColorBrush"] as SolidColorBrush;

            if (_taskbarIcon.TrayToolTip is Tray.ToolTip toolTip)
            {
                toolTip.AccentColor = accentColor;
            }
            if (_taskbarIcon.TrayPopup is Tray.ContextMenu contextMenu)
            {
                contextMenu.AccentColor = accentColor;
            }
        }
Ejemplo n.º 2
0
 private void AddNewStyleColumn(StyleBase sender, StyleChangeEventArgs e, ExcelWorksheet ws, Dictionary <int, int> styleCashe, ExcelColumn column, int s)
 {
     if (styleCashe.ContainsKey(s))
     {
         ws.SetStyleInner(0, column.ColumnMin, styleCashe[s]);
     }
     else
     {
         ExcelXfs st    = CellXfs[s];
         int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
         styleCashe.Add(s, newId);
         ws.SetStyleInner(0, column.ColumnMin, newId);
     }
 }
Ejemplo n.º 3
0
        private void SetStyleFullRow(StyleBase sender, StyleChangeEventArgs e, ExcelAddressBase address, ExcelWorksheet ws, Dictionary <int, int> styleCashe)
        {
            for (int rowNum = address.Start.Row; rowNum <= address.End.Row; rowNum++)
            {
                var s = ws.GetStyleInner(rowNum, 0);
                if (s == 0)
                {
                    //iterate all columns and set the row to the style of the last column
                    var cse = new CellStoreEnumerator <ExcelValue>(ws._values, 0, 1, 0, ExcelPackage.MaxColumns);
                    while (cse.Next())
                    {
                        s = cse.Value._styleId;
                        if (s == 0)
                        {
                            continue;
                        }
                        var c = ws.GetValueInner(cse.Row, cse.Column) as ExcelColumn;
                        if (c != null && c.ColumnMax < ExcelPackage.MaxColumns)
                        {
                            for (int col = c.ColumnMin; col < c.ColumnMax; col++)
                            {
                                if (!ws.ExistsStyleInner(rowNum, col))
                                {
                                    ws.SetStyleInner(rowNum, col, s);
                                }
                            }
                        }
                    }
                    ws.SetStyleInner(rowNum, 0, s);
                    cse.Dispose();
                }
                if (styleCashe.ContainsKey(s))
                {
                    ws.SetStyleInner(rowNum, 0, styleCashe[s]);
                }
                else
                {
                    ExcelXfs st    = CellXfs[s];
                    int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                    styleCashe.Add(s, newId);
                    ws.SetStyleInner(rowNum, 0, newId);
                }
            }

            //Update individual cells
            var cse2 = new CellStoreEnumerator <ExcelValue>(ws._values, address._fromRow, address._fromCol, address._toRow, address._toCol);

            while (cse2.Next())
            {
                var s = cse2.Value._styleId;
                if (s == 0)
                {
                    continue;
                }
                if (styleCashe.ContainsKey(s))
                {
                    ws.SetStyleInner(cse2.Row, cse2.Column, styleCashe[s]);
                }
                else
                {
                    ExcelXfs st    = CellXfs[s];
                    int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                    styleCashe.Add(s, newId);
                    ws.SetStyleInner(cse2.Row, cse2.Column, newId);
                }
            }

            //Update cells with styled rows
            cse2 = new CellStoreEnumerator <ExcelValue>(ws._values, 0, 1, 0, address._toCol);
            while (cse2.Next())
            {
                if (cse2.Value._styleId == 0)
                {
                    continue;
                }
                for (int r = address._fromRow; r <= address._toRow; r++)
                {
                    if (!ws.ExistsStyleInner(r, cse2.Column))
                    {
                        var s = cse2.Value._styleId;
                        if (styleCashe.ContainsKey(s))
                        {
                            ws.SetStyleInner(r, cse2.Column, styleCashe[s]);
                        }
                        else
                        {
                            ExcelXfs st    = CellXfs[s];
                            int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                            styleCashe.Add(s, newId);
                            ws.SetStyleInner(r, cse2.Column, newId);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void SetStyleFullColumn(StyleBase sender, StyleChangeEventArgs e, ExcelAddressBase address, ExcelWorksheet ws, Dictionary <int, int> styleCashe)
        {
            ExcelColumn column;
            int         col = address.Start.Column, row = 0;
            bool        isNew;
            //Get the startcolumn
            object o = null;

            if (!ws.ExistsValueInner(0, address.Start.Column, ref o))
            {
                column = ws.Column(address.Start.Column);
                isNew  = true;
            }
            else
            {
                column = (ExcelColumn)o;
                isNew  = false;
            }
            var prevColumMax = column.ColumnMax;

            while (column.ColumnMin <= address.End.Column)
            {
                if (column.ColumnMin > prevColumMax + 1)
                {
                    var newColumn = ws.Column(prevColumMax + 1);
                    newColumn.ColumnMax = column.ColumnMin - 1;
                    AddNewStyleColumn(sender, e, ws, styleCashe, newColumn, newColumn.StyleID);
                }
                if (column.ColumnMax > address.End.Column)
                {
                    var newCol = ws.CopyColumn(column, address.End.Column + 1, column.ColumnMax);
                    column.ColumnMax = address.End.Column;
                }
                var s = ws.GetStyleInner(0, column.ColumnMin);
                AddNewStyleColumn(sender, e, ws, styleCashe, column, s);

                //index++;
                prevColumMax = column.ColumnMax;
                if (!ws._values.NextCell(ref row, ref col) || row > 0)
                {
                    if (column._columnMax == address.End.Column)
                    {
                        break;
                    }

                    if (isNew)
                    {
                        column._columnMax = address.End.Column;
                    }
                    else
                    {
                        var newColumn = ws.Column(column._columnMax + 1);
                        newColumn.ColumnMax = address.End.Column;
                        AddNewStyleColumn(sender, e, ws, styleCashe, newColumn, newColumn.StyleID);
                        column = newColumn;
                    }
                    break;
                }
                else
                {
                    column = (ws.GetValueInner(0, col) as ExcelColumn);
                }
            }

            if (column._columnMax < address.End.Column)
            {
                var newCol = ws.Column(column._columnMax + 1) as ExcelColumn;
                newCol._columnMax = address.End.Column;

                var s = ws.GetStyleInner(0, column.ColumnMin);
                if (styleCashe.ContainsKey(s))
                {
                    ws.SetStyleInner(0, column.ColumnMin, styleCashe[s]);
                }
                else
                {
                    ExcelXfs st    = CellXfs[s];
                    int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                    styleCashe.Add(s, newId);
                    ws.SetStyleInner(0, column.ColumnMin, newId);
                }

                column._columnMax = address.End.Column;
            }

            //Set for individual cells in the span. We loop all cells here since the cells are sorted with columns first.
            var cse = new CellStoreEnumerator <ExcelValue>(ws._values, 1, address._fromCol, address._toRow, address._toCol);

            while (cse.Next())
            {
                if (cse.Column >= address.Start.Column &&
                    cse.Column <= address.End.Column &&
                    cse.Value._styleId != 0)
                {
                    if (styleCashe.ContainsKey(cse.Value._styleId))
                    {
                        ws.SetStyleInner(cse.Row, cse.Column, styleCashe[cse.Value._styleId]);
                    }
                    else
                    {
                        ExcelXfs st    = CellXfs[cse.Value._styleId];
                        int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                        styleCashe.Add(cse.Value._styleId, newId);
                        ws.SetStyleInner(cse.Row, cse.Column, newId);
                    }
                }
            }

            if (!(address._fromCol == 1 && address._toCol == ExcelPackage.MaxColumns))
            {
                //Update cells with styled columns
                cse = new CellStoreEnumerator <ExcelValue>(ws._values, 1, 0, address._toRow, 0);
                while (cse.Next())
                {
                    if (cse.Value._styleId == 0)
                    {
                        continue;
                    }
                    for (int c = address._fromCol; c <= address._toCol; c++)
                    {
                        if (!ws.ExistsStyleInner(cse.Row, c))
                        {
                            if (styleCashe.ContainsKey(cse.Value._styleId))
                            {
                                ws.SetStyleInner(cse.Row, c, styleCashe[cse.Value._styleId]);
                            }
                            else
                            {
                                ExcelXfs st    = CellXfs[cse.Value._styleId];
                                int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                                styleCashe.Add(cse.Value._styleId, newId);
                                ws.SetStyleInner(cse.Row, c, newId);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void SetStyleCells(StyleBase sender, StyleChangeEventArgs e, ExcelAddressBase address, ExcelWorksheet ws, Dictionary <int, int> styleCashe)
        {
            var rowCache     = new Dictionary <int, int>(address.End.Row - address.Start.Row + 1);
            var colCache     = new Dictionary <int, ExcelValue>(address.End.Column - address.Start.Column + 1);
            var cellEnum     = new CellStoreEnumerator <ExcelValue>(ws._values, address.Start.Row, address.Start.Column, address.End.Row, address.End.Column);
            var hasEnumValue = cellEnum.Next();

            for (int row = address._fromRow; row <= address._toRow; row++)
            {
                for (int col = address._fromCol; col <= address._toCol; col++)
                {
                    ExcelValue value;
                    if (hasEnumValue && row == cellEnum.Row && col == cellEnum.Column)
                    {
                        value        = cellEnum.Value;
                        hasEnumValue = cellEnum.Next();
                    }
                    else
                    {
                        value = new ExcelValue {
                            _styleId = 0
                        };
                    }
                    var s = value._styleId;
                    if (s == 0)
                    {
                        // get row styleId with cache
                        if (rowCache.ContainsKey(row))
                        {
                            s = rowCache[row];
                        }
                        else
                        {
                            s = ws._values.GetValue(row, 0)._styleId;
                            rowCache.Add(row, s);
                        }
                        if (s == 0)
                        {
                            // get column styleId with cache
                            if (colCache.ContainsKey(col))
                            {
                                s = colCache[col]._styleId;
                            }
                            else
                            {
                                var v = ws._values.GetValue(0, col);
                                colCache.Add(col, v);
                                s = v._styleId;
                            }
                            if (s == 0)
                            {
                                int r = 0, c = col;
                                if (ws._values.PrevCell(ref r, ref c))
                                {
                                    if (!colCache.ContainsKey(c))
                                    {
                                        colCache.Add(c, ws._values.GetValue(0, c));
                                    }
                                    var val    = colCache[c];
                                    var colObj = (ExcelColumn)(val._value);
                                    if (colObj != null && colObj.ColumnMax >= col) //Fixes issue 15174
                                    {
                                        s = val._styleId;
                                    }
                                }
                            }
                        }
                    }
                    if (styleCashe.ContainsKey(s))
                    {
                        ws._values.SetValue(row, col, new ExcelValue {
                            _value = value._value, _styleId = styleCashe[s]
                        });
                    }
                    else
                    {
                        ExcelXfs st    = CellXfs[s];
                        int      newId = st.GetNewID(CellXfs, sender, e.StyleClass, e.StyleProperty, e.Value);
                        styleCashe.Add(s, newId);
                        ws._values.SetValue(row, col, new ExcelValue {
                            _value = value._value, _styleId = newId
                        });
                    }
                }
            }
        }