private void ResolveBorders(SpreadsheetSelection selection, Worksheet worksheet)
        {
            if (selection.CellRanges[0].IsSingleCell)
            {
                var range      = selection.CellRanges[0];
                var cellFormat = worksheet.Rows[range.FirstRow].Cells[range.FirstColumn].CellFormat;
                this.TopBorder    = cellFormat.TopBorderStyle;
                this.BottomBorder = cellFormat.BottomBorderStyle;
                this.LeftBorder   = cellFormat.LeftBorderStyle;
                this.RightBorder  = cellFormat.RightBorderStyle;
                //this.DiagonalUpBorder = cellFormat.DiagonalBorders == DiagonalBorders.
                //this.RightBorder = cellFormat.RightBorderStyle;
            }
            foreach (var range in selection.CellRanges)
            {
                if (range.IsSingleCell)
                {
                }

                for (int i = range.FirstRow; i <= range.LastRow; i++)
                {
                    var row = worksheet.Rows[i];

                    for (int j = range.FirstColumn; j <= range.LastColumn; j++)
                    {
                        if (i == range.FirstRow)
                        {
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DimensionDialog"/> class.
        /// </summary>
        /// <param name="dimension">The dimension.</param>
        /// <param name="activeWorksheet">The active worksheet.</param>
        /// <param name="selection">The selection.</param>
        internal DimensionDialog(DimensionMode dimension, Worksheet activeWorksheet, SpreadsheetSelection selection)
        {
            this.InitializeComponent();

            this.dimension       = dimension;
            this.activeWorksheet = activeWorksheet;
            this.selection       = selection;
            this.InitializeUI();
        }
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            this.selection       = (SpreadsheetSelection)navigationContext.Parameters[FormatAsTableDialogParameters.SelectionKey];
            this.activeWorksheet = (Worksheet)navigationContext.Parameters[FormatAsTableDialogParameters.WorksheetKey];
            this.workbook        = (Workbook)navigationContext.Parameters[FormatAsTableDialogParameters.WorkbookKey];
            this.tableStyle      = (string)navigationContext.Parameters[FormatAsTableDialogParameters.TableStyleKey];

            this.RangeAddress = selection.CellRanges[0].ToString(this.workbook.CellReferenceMode);
        }
Example #4
0
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            this.mode            = (DimensionDialogMode)navigationContext.Parameters[DimensionDialogViewParameters.DialogModeKey];
            this.selection       = (SpreadsheetSelection)navigationContext.Parameters[FormatAsTableDialogParameters.SelectionKey];
            this.activeWorksheet = (Worksheet)navigationContext.Parameters[FormatAsTableDialogParameters.WorksheetKey];

            SetStrings(this.mode);
            ReadDimension(this.mode, this.selection, this.activeWorksheet);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormatAsTableDialog"/> class.
        /// </summary>
        /// <param name="workbook">The workbook.</param>
        /// <param name="activeWorksheet">The active worksheet.</param>
        /// <param name="selection">The selection.</param>
        /// <param name="tableStyle">The table style.</param>
        internal FormatAsTableDialog(Workbook workbook, Worksheet activeWorksheet, SpreadsheetSelection selection, string tableStyle)
        {
            this.InitializeComponent();

            this.workbook        = workbook;
            this.activeWorksheet = activeWorksheet;
            this.selection       = selection;
            this.tableStyle      = tableStyle;

            this.InitializeUI();
        }
        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            this.SelectedItemName = (string)navigationContext.Parameters[FormatCellsDialogParameters.InitialTabNameKey];
            this.activeSelection  = (SpreadsheetSelection)navigationContext.Parameters[FormatCellsDialogParameters.SelectionKey];
            this.activeWorksheet  = (Worksheet)navigationContext.Parameters[FormatCellsDialogParameters.WorksheetKey];
            this.CellFormat       = (SpreadsheetCellRangeFormat)navigationContext.Parameters[FormatCellsDialogParameters.SelectionFormatsKey];

            ResolveCellFormats(this.activeSelection, this.activeWorksheet);

            this.trackChanges = true;
        }
Example #7
0
        // This seems to not be used.
        #region Commented out
        //private bool IntersectsWith(int rowXFirst, int columnXFirst, int rowXLast, int columnXLast, int rowYFirst, int columnYFirst, int rowYLast, int columnYLast)
        //{
        //    Rectangle rectX = GetRectangleFromCoordinates(rowXFirst, columnXFirst, rowXLast, columnXLast);
        //    Rectangle rectY = GetRectangleFromCoordinates(rowYFirst, columnYFirst, rowYLast, columnYLast);

        //    return rectX.IntersectsWith(rectY);
        //}
        #endregion // Commented out

        #endregion //Private Methods

        #region OnDispose

        protected override void OnDispose()
        {
            this.selectedTable = null;
            this.selection     = null;
            this.SpreadSheet   = null;
        }
Example #8
0
        private void ReadDimension(DimensionDialogMode dialogMode, SpreadsheetSelection selection, Worksheet worksheet)
        {
            switch (dialogMode)
            {
            case DimensionDialogMode.RowHeight:
                var rowHeight = this.activeWorksheet.Rows[this.selection.CellRanges[0].FirstRow].GetCellBoundsInTwips(this.selection.CellRanges[0].FirstColumn).Height;

                foreach (var range in this.selection.CellRanges)
                {
                    for (int i = range.FirstRow; i <= range.LastRow; i++)
                    {
                        var row = this.activeWorksheet.Rows[i];
                        if (rowHeight != row.GetCellBoundsInTwips(range.FirstColumn).Height)
                        {
                            rowHeight = -1;
                            break;
                        }
                    }

                    if (rowHeight == -1)
                    {
                        break;
                    }
                }

                if (rowHeight != -1)
                {
                    this.DimensionValue = rowHeight / 20;
                }
                break;

            case DimensionDialogMode.ColumnWidth:
                var columnWidth = this.activeWorksheet.Columns[this.selection.CellRanges[0].FirstColumn].Width;

                foreach (var range in this.selection.CellRanges)
                {
                    for (int i = range.FirstColumn; i <= range.LastColumn; i++)
                    {
                        if (columnWidth != this.activeWorksheet.Columns[i].Width)
                        {
                            columnWidth = -2;
                        }
                    }

                    if (columnWidth == -2)
                    {
                        break;
                    }
                }

                if (columnWidth == -1)
                {
                    this.DimensionValue = worksheet.GetDefaultColumnWidth(WorksheetColumnWidthUnit.CharacterPaddingExcluded);
                }
                else if (columnWidth != -2)
                {
                    this.DimensionValue = this.activeWorksheet.Columns[this.selection.CellRanges[0].FirstColumn].GetWidth(WorksheetColumnWidthUnit.CharacterPaddingExcluded);
                }
                break;

            case DimensionDialogMode.DeafaultWidth:
                this.DimensionValue = worksheet.GetDefaultColumnWidth(WorksheetColumnWidthUnit.CharacterPaddingExcluded);
                break;
            }
        }
        private void ResolveCellFormats(SpreadsheetSelection selection, Worksheet worksheet)
        {
            List <IWorksheetCellFormat> cellFormats = new List <IWorksheetCellFormat>();

            //Take all ResolvedCellFormats
            foreach (var range in selection.CellRanges)
            {
                for (int i = range.FirstRow; i <= range.LastRow; i++)
                {
                    var row = worksheet.Rows[i];

                    for (int j = range.FirstColumn; j <= range.LastColumn; j++)
                    {
                        cellFormats.Add(row.GetResolvedCellFormat(j));
                    }
                }
            }


            this.FontName                = cellFormats[0].Font.Name;
            this.FontSize                = cellFormats[0].Font.Height;
            this.FontColor               = cellFormats[0].Font.ColorInfo.GetResolvedColor(this.activeWorksheet.Workbook);
            this.Superscript             = IsSuperscript(cellFormats[0].Font.SuperscriptSubscriptStyle);
            this.Subscript               = IsSubscript(cellFormats[0].Font.SuperscriptSubscriptStyle);
            this.HorizontalCellAlignment = cellFormats[0].Alignment;
            this.VerticalCellAlignment   = cellFormats[0].VerticalAlignment;
            this.Indent = cellFormats[0].Indent;
            this.Fill   = cellFormats[0].Fill;

            ExcelDefaultableBoolean?strikeout        = cellFormats[0].Font.Strikeout;
            ExcelDefaultableBoolean?bold             = cellFormats[0].Font.Bold;
            ExcelDefaultableBoolean?italic           = cellFormats[0].Font.Italic;
            ExcelDefaultableBoolean?wrapTextLocal    = cellFormats[0].WrapText;
            ExcelDefaultableBoolean?shrinkToFitLocal = cellFormats[0].ShrinkToFit;

            CellBorderLineStyle?topBorderStyle = cellFormats[0].TopBorderStyle;


            string formatString = cellFormats[0].FormatString;


            for (int i = 1; i < cellFormats.Count; i++)
            {
                if (formatString != cellFormats[i].FormatString && formatString != null)
                {
                    formatString = null;
                }

                if (this.FontName != cellFormats[i].Font.Name && this.FontName != null)
                {
                    this.FontName = null;
                }

                if (this.FontSize != cellFormats[i].Font.Height && this.FontSize != null)
                {
                    this.FontSize = null;
                }

                if (this.FontColor != cellFormats[i].Font.ColorInfo.GetResolvedColor(this.activeWorksheet.Workbook) && this.FontColor != Colors.Transparent)
                {
                    this.FontColor = Colors.Transparent;
                }

                if (strikeout != cellFormats[i].Font.Strikeout && strikeout != null)
                {
                    strikeout = null;
                }

                if (bold != cellFormats[i].Font.Bold && bold != null)
                {
                    bold = null;
                }

                if (italic != cellFormats[i].Font.Italic && italic != null)
                {
                    italic = null;
                }

                if (this.superscript != IsSuperscript(cellFormats[i].Font.SuperscriptSubscriptStyle) && this.Superscript != null)
                {
                    this.Superscript = null;
                }

                if (this.subscript != IsSubscript(cellFormats[i].Font.SuperscriptSubscriptStyle) && this.Subscript != null)
                {
                    this.Subscript = null;
                }

                if (this.horizontalCellAlignment != cellFormats[i].Alignment && this.horizontalCellAlignment != null)
                {
                    this.HorizontalCellAlignment = null;
                }

                if (this.verticalCellAlignment != cellFormats[i].VerticalAlignment && this.VerticalCellAlignment != null)
                {
                    this.VerticalCellAlignment = null;
                }

                if (this.indent != cellFormats[i].Indent && this.Indent != null)
                {
                    this.Indent = null;
                }

                if (wrapTextLocal != cellFormats[i].WrapText && wrapTextLocal != null)
                {
                    wrapTextLocal = null;
                }

                if (shrinkToFitLocal != cellFormats[i].ShrinkToFit && shrinkToFitLocal != null)
                {
                    shrinkToFitLocal = null;
                }

                if (this.fill != cellFormats[i].Fill && this.fill != null)
                {
                    this.Fill = null;
                }
            }

            this.FontStyle     = ResolveFontStyle(bold, italic);
            this.Strikethrough = ExcelDefaultableBooleanToNullableBool(strikeout);
            this.WrapText      = ExcelDefaultableBooleanToNullableBool(wrapTextLocal);
            this.ShrinkToFit   = ExcelDefaultableBooleanToNullableBool(shrinkToFitLocal);

            InitFormatString(formatString);
            InitFillTab();

            this.FontSize = this.FontSize / 20;
        }