Exemple #1
0
 private static IEnumerable<string> GetMergedCells(DocumentWorksheet worksheet)
 {
     foreach (var mergedRange in worksheet.Cells.GetMergedCellRanges())
     {
         yield return NameConverter.ConvertCellRangeToName(mergedRange.FromIndex, mergedRange.ToIndex);
     }
 }
Exemple #2
0
        private static IEnumerable<Column> GetColumns(DocumentWorksheet worksheet)
        {
            var ranges = worksheet.Columns.PropertyBag.GetPropertyValueCollection(ColumnsPropertyBag.WidthProperty).GetNonDefaultRanges();

            foreach (var range in ranges)
            {
                var width = range.Value.Value;
                for (var i = range.Start; i <= range.End; i++)
                {
                    yield return new Column
                    {
                        Index = (int)i,
                        Width = width
                    };
                }
            }
        }
Exemple #3
0
        private static Sort GetSorting(DocumentWorksheet worksheet)
        {
            var range = worksheet.SortState.SortRange;

            if (range == null)
            {
                return null;
            }

            return new Sort
            {
                Ref = NameConverter.ConvertCellRangeToName(range.FromIndex, range.ToIndex),
                Columns = worksheet.SortState.SortConditions.OfType<ValuesSortCondition>().Select(cond => new SortColumn
                {
                    Ascending = cond.SortOrder == SortOrder.Ascending,
                    Index = cond.RelativeIndex
                }).ToList()
            };
        }
Exemple #4
0
        private void SetSortState(DocumentWorksheet documentWorksheet, Sort sort)
        {
            if (sort == null)
            {
                return;
            }

            var conditions = sort.Columns.Select(column => new ValuesSortCondition((int)column.Index, column.Ascending.Value ? SortOrder.Ascending : SortOrder.Descending)).ToArray();
            var range = sort.Ref.ToCellRange().First();

            documentWorksheet.SortState.Set(range, conditions);
        }
Exemple #5
0
        private void SetCells(Row srcRow, DocumentWorksheet documentSheet)
        {
            foreach (var cell in srcRow.Cells.GetOrDefault())
            {
                var stringValue = cell.Value == null ? null : cell.Value.ToString();
                var selection = documentSheet.Cells[srcRow.Index.Value, cell.Index.Value];
                double numericValue;

                var formula = cell.Formula;
                if (!string.IsNullOrEmpty(formula))
                {
                    selection.SetValueAsFormula("=" + formula);
                }
                else if (double.TryParse(stringValue, out numericValue))
                {
                    selection.SetValue(numericValue);
                }
                else if (!string.IsNullOrEmpty(stringValue))
                {
                    selection.SetValueAsText(stringValue);
                }

                if (!string.IsNullOrEmpty(cell.Format))
                {
                    selection.SetFormat(new CellValueFormat(cell.Format));
                }

                if (!string.IsNullOrEmpty(cell.Color))
                {
                    selection.SetForeColor(new ThemableColor(cell.Color.ToColor()));
                }

                if (!string.IsNullOrEmpty(cell.Background))
                {
                    var fill = PatternFill.CreateSolidFill(cell.Background.ToColor());
                    selection.SetFill(fill);
                }

                if (cell.Bold.HasValue)
                {
                    selection.SetIsBold(cell.Bold.Value);
                }

                if (cell.Italic.HasValue)
                {
                    selection.SetIsItalic(cell.Italic.Value);
                }

                if (cell.Wrap.HasValue)
                {
                    selection.SetIsWrapped(cell.Wrap.Value);
                }

                if (cell.Underline.HasValue)
                {
                    selection.SetUnderline(UnderlineType.Single);
                }

                selection.SetBorders(CreateCellBorders(cell));

                if (!string.IsNullOrEmpty(cell.VerticalAlign))
                {
                    selection.SetVerticalAlignment(cell.VerticalAlign.ToVerticalAlignment());
                }

                if (!string.IsNullOrEmpty(cell.TextAlign))
                {
                    selection.SetHorizontalAlignment(ConvertToHorizontalAlignment(cell.TextAlign));
                }

                if (!string.IsNullOrEmpty(cell.FontFamily))
                {
                    selection.SetFontFamily(new ThemableFontFamily(cell.FontFamily));
                }

                if (cell.FontSize.HasValue)
                {
                    selection.SetFontSize(UnitHelper.PointToDip(cell.FontSize.Value));
                }
            }
        }
Exemple #6
0
 private SelectionState CreateSelectionState(Worksheet sheet, DocumentWorksheet documentSheet)
 {
     if (sheet.Selection != null)
     {
         return new SelectionState(sheet.Selection.ToCellRange(), sheet.ActiveCell.ToCellIndex(), documentSheet.ViewState.SelectionState.Pane);
     }
     else
     {
         return new SelectionState();
     }
 }