示例#1
0
 public void Add(String elementNumber, XLSortOrder sortOrder, Boolean ignoreBlanks, Boolean matchCase)
 {
     elements.Add(new XLSortElement()
     {
         ElementNumber = XLHelper.GetColumnNumberFromLetter(elementNumber),
         SortOrder = sortOrder,
         IgnoreBlanks = ignoreBlanks,
         MatchCase = matchCase
     });
 }
示例#2
0
 public void Add(Int32 elementNumber, XLSortOrder sortOrder, Boolean ignoreBlanks, Boolean matchCase)
 {
     elements.Add(new XLSortElement()
     {
         ElementNumber = elementNumber,
         SortOrder = sortOrder,
         IgnoreBlanks = ignoreBlanks,
         MatchCase = matchCase
     });
 }
示例#3
0
 public void Add(String elementNumber, XLSortOrder sortOrder)
 {
     Add(elementNumber, sortOrder, true);
 }
示例#4
0
 public void Add(Int32 elementNumber, XLSortOrder sortOrder)
 {
     Add(elementNumber, sortOrder, true);
 }
示例#5
0
 public new IXLRange SortLeftToRight(XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     return(base.SortLeftToRight(sortOrder, matchCase, ignoreBlanks).AsRange());
 }
示例#6
0
 public void Add(Int32 elementNumber, XLSortOrder sortOrder)
 {
     Add(elementNumber, sortOrder, true);
 }
示例#7
0
 public new IXLRange SortLeftToRight(XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     return base.SortLeftToRight(sortOrder, matchCase, ignoreBlanks).AsRange();
 }
示例#8
0
 public new IXLRange Sort(String columnsToSortBy, XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     return(base.Sort(columnsToSortBy, sortOrder, matchCase, ignoreBlanks).AsRange());
 }
示例#9
0
 public IXLRangeColumn Sort(XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     base.Sort(1, sortOrder, matchCase, ignoreBlanks);
     return(this);
 }
示例#10
0
        public XLAutoFilter Sort(Int32 columnToSortBy, XLSortOrder sortOrder, Boolean matchCase, Boolean ignoreBlanks)
        {
            var ws = Range.Worksheet as XLWorksheet;
            ws.SuspendEvents();
            Range.Range(Range.FirstCell().CellBelow(), Range.LastCell()).Sort(columnToSortBy, sortOrder, matchCase,
                                                                              ignoreBlanks);

            Sorted = true;
            SortOrder = sortOrder;
            SortColumn = columnToSortBy;

            if (Enabled)
            {
                using (var rows = Range.Rows(2, Range.RowCount()))
                {
                    foreach (IXLRangeRow row in rows)
                        row.WorksheetRow().Unhide();
                }

                foreach (KeyValuePair<int, List<XLFilter>> kp in Filters)
                {
                    Boolean firstFilter = true;
                    foreach (XLFilter filter in kp.Value)
                    {
                        Boolean isText = filter.Value is String;
                        using (var rows = Range.Rows(2, Range.RowCount()))
                        {
                            foreach (IXLRangeRow row in rows)
                            {
                                Boolean match = isText
                                                    ? filter.Condition(row.Cell(kp.Key).GetString())
                                                    : row.Cell(kp.Key).DataType == XLCellValues.Number &&
                                                      filter.Condition(row.Cell(kp.Key).GetDouble());
                                if (firstFilter)
                                {
                                    if (match)
                                        row.WorksheetRow().Unhide();
                                    else
                                        row.WorksheetRow().Hide();
                                }
                                else
                                {
                                    if (filter.Connector == XLConnector.And)
                                    {
                                        if (!row.WorksheetRow().IsHidden)
                                        {
                                            if (match)
                                                row.WorksheetRow().Unhide();
                                            else
                                                row.WorksheetRow().Hide();
                                        }
                                    }
                                    else if (match)
                                        row.WorksheetRow().Unhide();
                                }
                            }
                            firstFilter = false;
                        }
                    }
                }
            }
            ws.ResumeEvents();
            return this;
        }
 public new IXLRange Sort(String columnsToSortBy, XLSortOrder sortOrder = XLSortOrder.Ascending,
                          Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     return GetRangeForSort().Sort(columnsToSortBy, sortOrder, matchCase, ignoreBlanks);
 }
示例#12
0
 public void Add(String elementNumber, XLSortOrder sortOrder, Boolean ignoreBlanks)
 {
     Add(elementNumber, sortOrder, ignoreBlanks, false);
 }
示例#13
0
 public void Add(String elementNumber, XLSortOrder sortOrder)
 {
     Add(elementNumber, sortOrder, true);
 }
示例#14
0
 public void Add(String elementNumber, XLSortOrder sortOrder, Boolean ignoreBlanks)
 {
     Add(elementNumber, sortOrder, ignoreBlanks, false);
 }
示例#15
0
 IXLAutoFilter IXLAutoFilter.Sort(Int32 columnToSortBy, XLSortOrder sortOrder, Boolean matchCase,
     Boolean ignoreBlanks)
 {
     return Sort(columnToSortBy, sortOrder, matchCase, ignoreBlanks);
 }
示例#16
0
 public IXLRangeColumn Sort(XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     base.Sort(1, sortOrder, matchCase, ignoreBlanks);
     return this;
 }
示例#17
0
        public XLAutoFilter Sort(Int32 columnToSortBy, XLSortOrder sortOrder, Boolean matchCase, Boolean ignoreBlanks)
        {
            if (!Enabled)
            {
                throw new ApplicationException("Filter has not been enabled.");
            }

            var ws = Range.Worksheet as XLWorksheet;

            ws.SuspendEvents();
            Range.Range(Range.FirstCell().CellBelow(), Range.LastCell()).Sort(columnToSortBy, sortOrder, matchCase,
                                                                              ignoreBlanks);

            Sorted     = true;
            SortOrder  = sortOrder;
            SortColumn = columnToSortBy;

            if (Enabled)
            {
                using (var rows = Range.Rows(2, Range.RowCount()))
                {
                    foreach (IXLRangeRow row in rows)
                    {
                        row.WorksheetRow().Unhide();
                    }
                }

                foreach (KeyValuePair <int, List <XLFilter> > kp in Filters)
                {
                    Boolean firstFilter = true;
                    foreach (XLFilter filter in kp.Value)
                    {
                        Boolean isText = filter.Value is String;
                        using (var rows = Range.Rows(2, Range.RowCount()))
                        {
                            foreach (IXLRangeRow row in rows)
                            {
                                Boolean match = isText
                                                    ? filter.Condition(row.Cell(kp.Key).GetString())
                                                    : row.Cell(kp.Key).DataType == XLCellValues.Number &&
                                                filter.Condition(row.Cell(kp.Key).GetDouble());
                                if (firstFilter)
                                {
                                    if (match)
                                    {
                                        row.WorksheetRow().Unhide();
                                    }
                                    else
                                    {
                                        row.WorksheetRow().Hide();
                                    }
                                }
                                else
                                {
                                    if (filter.Connector == XLConnector.And)
                                    {
                                        if (!row.WorksheetRow().IsHidden)
                                        {
                                            if (match)
                                            {
                                                row.WorksheetRow().Unhide();
                                            }
                                            else
                                            {
                                                row.WorksheetRow().Hide();
                                            }
                                        }
                                    }
                                    else if (match)
                                    {
                                        row.WorksheetRow().Unhide();
                                    }
                                }
                            }
                            firstFilter = false;
                        }
                    }
                }
            }
            ws.ResumeEvents();
            return(this);
        }
示例#18
0
 public new IXLRow SortLeftToRight(XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false,
                                   Boolean ignoreBlanks  = true)
 {
     base.SortLeftToRight(sortOrder, matchCase, ignoreBlanks);
     return(this);
 }
示例#19
0
 IXLBaseAutoFilter IXLBaseAutoFilter.Sort(Int32 columnToSortBy, XLSortOrder sortOrder, Boolean matchCase,
                                          Boolean ignoreBlanks)
 {
     return(Sort(columnToSortBy, sortOrder, matchCase, ignoreBlanks));
 }
示例#20
0
 public new IXLRange Sort(Int32 columnToSortBy, XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false, Boolean ignoreBlanks = true)
 {
     return base.Sort(columnToSortBy, sortOrder, matchCase, ignoreBlanks).AsRange();
 }
示例#21
0
        public new IXLRange Sort(String columnsToSortBy, XLSortOrder sortOrder = XLSortOrder.Ascending,
            Boolean matchCase = false, Boolean ignoreBlanks = true)
        {
            var toSortBy = new StringBuilder();
            foreach (string coPairTrimmed in columnsToSortBy.Split(',').Select(coPair => coPair.Trim()))
            {
                String coString;
                String order;
                if (coPairTrimmed.Contains(' '))
                {
                    var pair = coPairTrimmed.Split(' ');
                    coString = pair[0];
                    order = pair[1];
                }
                else
                {
                    coString = coPairTrimmed;
                    order = "ASC";
                }

                Int32 co;
                if (!Int32.TryParse(coString, out co))
                    co = Field(coString).Index + 1;

                toSortBy.Append(co);
                toSortBy.Append(" ");
                toSortBy.Append(order);
                toSortBy.Append(",");
            }
            return DataRange.Sort(toSortBy.ToString(0, toSortBy.Length - 1), sortOrder, matchCase, ignoreBlanks);
        }
示例#22
0
 public new IXLRow SortLeftToRight(XLSortOrder sortOrder = XLSortOrder.Ascending, Boolean matchCase = false,
                                   Boolean ignoreBlanks = true)
 {
     base.SortLeftToRight(sortOrder, matchCase, ignoreBlanks);
     return this;
 }
示例#23
0
        public XLAutoFilter Sort(Int32 columnToSortBy, XLSortOrder sortOrder, Boolean matchCase, Boolean ignoreBlanks)
        {
            if (!Enabled)
            {
                throw new InvalidOperationException("Filter has not been enabled.");
            }

            var ws = Range.Worksheet as XLWorksheet;

            ws.SuspendEvents();
            Range.Range(Range.FirstCell().CellBelow(), Range.LastCell()).Sort(columnToSortBy, sortOrder, matchCase,
                                                                              ignoreBlanks);

            Sorted     = true;
            SortOrder  = sortOrder;
            SortColumn = columnToSortBy;

            // Recalculate shown / hidden rows
            if (Enabled)
            {
                using (var rows = Range.Rows(2, Range.RowCount()))
                {
                    foreach (IXLRangeRow row in rows)
                    {
                        row.WorksheetRow().Unhide();
                    }
                }

                foreach (var kp in Filters)
                {
                    Boolean firstFilter = true;
                    foreach (XLFilter filter in kp.Value)
                    {
                        var condition  = filter.Condition;
                        var isText     = filter.Value is String;
                        var isDateTime = filter.Value is DateTime;

                        using (var rows = Range.Rows(2, Range.RowCount()))
                        {
                            foreach (IXLRangeRow row in rows)
                            {
                                //TODO : clean up filter matching - it's done in different place
                                Boolean match;

                                if (isText)
                                {
                                    match = condition(row.Cell(kp.Key).GetFormattedString());
                                }
                                else if (isDateTime)
                                {
                                    match = row.Cell(kp.Key).DataType == XLDataType.DateTime && condition(row.Cell(kp.Key).GetDateTime());
                                }
                                else
                                {
                                    match = row.Cell(kp.Key).DataType == XLDataType.Number && condition(row.Cell(kp.Key).GetDouble());
                                }

                                if (firstFilter)
                                {
                                    if (match)
                                    {
                                        row.WorksheetRow().Unhide();
                                    }
                                    else
                                    {
                                        row.WorksheetRow().Hide();
                                    }
                                }
                                else
                                {
                                    if (filter.Connector == XLConnector.And)
                                    {
                                        if (!row.WorksheetRow().IsHidden)
                                        {
                                            if (match)
                                            {
                                                row.WorksheetRow().Unhide();
                                            }
                                            else
                                            {
                                                row.WorksheetRow().Hide();
                                            }
                                        }
                                    }
                                    else if (match)
                                    {
                                        row.WorksheetRow().Unhide();
                                    }
                                }
                            }
                            firstFilter = false;
                        }
                    }
                }
            }
            ws.ResumeEvents();
            return(this);
        }