/// <summary> /// To sort data within the table. Note that the sorting is only done when the table is inserted into the worksheet. /// </summary> /// <param name="TableColumnIndex"> /// The table column index. For example, 1 for the 1st table column, 2 for the 2nd table /// column and so on. /// </param> /// <param name="SortAscending">True to sort in ascending order. False to sort in descending order.</param> public void Sort(int TableColumnIndex, bool SortAscending) { --TableColumnIndex; if ((TableColumnIndex < 0) || (TableColumnIndex >= TableColumns.Count)) { return; } var iStartRowIndex = -1; var iEndRowIndex = -1; if (HeaderRowCount > 0) { iStartRowIndex = StartRowIndex + 1; } else { iStartRowIndex = StartRowIndex; } // not inclusive of the last totals row if (TotalsRowCount > 0) { iEndRowIndex = EndRowIndex - 1; } else { iEndRowIndex = EndRowIndex; } SortState = new SLSortState(); SortState.StartRowIndex = iStartRowIndex; SortState.EndRowIndex = iEndRowIndex; SortState.StartColumnIndex = StartColumnIndex; SortState.EndColumnIndex = EndColumnIndex; var sc = new SLSortCondition(); sc.StartRowIndex = iStartRowIndex; sc.StartColumnIndex = StartColumnIndex + TableColumnIndex; sc.EndRowIndex = iEndRowIndex; sc.EndColumnIndex = sc.StartColumnIndex; if (!SortAscending) { sc.Descending = true; } SortState.SortConditions.Add(sc); HasSortState = true; }
internal void SetAllNull() { IsNewTable = true; RelationshipID = string.Empty; AutoFilter = new SLAutoFilter(); HasAutoFilter = false; SortState = new SLSortState(); HasSortState = false; TableColumns = new List <SLTableColumn>(); TableNames = new HashSet <string>(); TableStyleInfo = new SLTableStyleInfo(); HasTableStyleInfo = false; Id = 0; Name = null; sDisplayName = string.Empty; Comment = null; StartRowIndex = 1; StartColumnIndex = 1; EndRowIndex = 1; EndColumnIndex = 1; TableType = TableValues.Worksheet; HasTableType = false; HeaderRowCount = 1; InsertRow = null; InsertRowShift = null; TotalsRowCount = 0; TotalsRowShown = null; Published = null; HeaderRowFormatId = null; DataFormatId = null; TotalsRowFormatId = null; HeaderRowBorderFormatId = null; BorderFormatId = null; TotalsRowBorderFormatId = null; HeaderRowCellStyle = null; DataCellStyle = null; TotalsRowCellStyle = null; ConnectionId = null; }