TX Sheet Control

Sorting and Filtering

Topic

Sorting and AutoFilter operate on the data of a worksheet. Beside them, the Data tab offers transformations that split text into columns, remove duplicate rows and consolidate ranges, each with a preview. Dashboard filters are a different mechanism. They operate on analytics and do not rewrite worksheet values or AutoFilter settings.

Sort and Filter on the Data Tab

Select a rectangular data range with intentional headers. Then use the commands of the Data tab, shown in Ribbon and Contextual Commands, to:

  • sort by supported keys
  • open filter menus and clear criteria
  • split text into columns
  • remove duplicate rows
  • consolidate supported ranges of the same worksheet

In Sort, use Add Level to sort by another column and order. In Advanced Filter, use Add Condition to add a criterion. The × button beside each row removes that level or condition; the dialog retains at least one row.

Split Text Into Columns

Select the source cells and choose Data → Text to Columns. The dialog separates Data & Destination, Split Settings and Output into exclusive accordion sections. Choose delimited text or fixed-width positions, configure the split and choose the output format. Text (Keep Leading Zeros) is useful for identifiers that must remain text.

Text to Columns with delimiter settings and a right Live Preview of two destination columns

Inspect the right Live Preview, destination and replacement count before choosing Finish. Enable replacement only when the existing destination cells may be overwritten. Cancel discards the draft.

Remove Duplicate Records

Select the range and choose Data → Remove Duplicates. In Source Data, check the range and whether it has headers. In Comparison, choose the columns to compare and whether matching is case-sensitive. The preview lists retained records and reports the duplicate and unique row counts.

Remove Duplicates with comparison-column switches and a right preview of retained records and row counts

Choose Remove Duplicates to keep the first matching record and compact the selected range. Check the comparison columns before applying: rows with different values outside those columns can still count as duplicates. Use Cancel to leave the data unchanged.

Consolidate Worksheet Ranges

Choose Data → Consolidate and enter the source ranges and operation in Source Data. Set the destination and replacement policy in Output. In Labels & Links, choose whether the top row and left column supply labels and whether the output creates links to source data.

Consolidate with label and link switches beside a preview of the consolidated values and destination

Check the result and destination in Live Preview, then choose Consolidate to apply or Cancel to discard the draft. All three transformation dialogs use the same fixed settings frame: opening a section or changing an option keeps the header, preview and actions in place while longer content scrolls internally.

Sort and Filter in Code

The workbook API exposes four methods for sorting and AutoFilter:

MethodPurpose
sortRangeSorts a range of the active sheet in one undoable operation. Rejects merged ranges and invalid keys.
setAutoFilterSets or removes the filter of the active sheet.
getAutoFilterReturns the filter of the active sheet as a detached snapshot.
clearFiltersRemoves the filter criteria and keeps the filter range.

Sort options and filter criteria are typed definitions. Use the reference, such as SortOptions, rather than constructing undocumented criterion objects. Merged ranges and protected targets can reject transformations.

Preview a Transformation Before You Apply It

Text to columns, duplicate removal and consolidation provide preview operations: previewTextToColumns, previewRemoveDuplicates and previewConsolidate. Inspect the preview and the destination before you apply the operation.

  • Text to columns. A text split can require overwrite permission if the target cells already contain data.
  • Duplicate removal. It compares the configured columns and the header policy, not merely the visible formatting.

The following code previews which rows a duplicate removal in A1:D100 would keep and remove:

const book = editor.workbook;
const preview = book.previewRemoveDuplicates('A1:D100', { hasHeaders: true });
console.log(preview);
// Confirm the intended keys/options before calling removeDuplicates.

The code works as follows:

  • Workbook.previewRemoveDuplicates previews the retained and removed rows without changing the data or the history. The option hasHeaders: true sets the header policy of the range.
  • The result is a RemoveDuplicatesPreview, the plan of the removal, which the code writes to the console.
  • After you have confirmed the keys and options, removeDuplicates removes the duplicates in one undo operation.

Use the relevant options reference, such as RemoveDuplicatesOptions, to select the comparison columns and policies for your data. Transformations are bounded operations and participate in supported transactions and undo. Avoid applying a preview from one document to another without recomputing it.

Sort Typed Values

Sort and compare typed numbers as numbers. How dates behave depends on serial or ISO values, the date system and explicit number formatting. A formatted currency or date string is not automatically equivalent to a numeric or date value.

Next Steps

  • Cells and Ranges: write typed values instead of formatted strings.
  • Tables: give the data a table with named columns and filter buttons.
  • Dates and Locales: see how serial values, date systems and formats affect dates.
  • Filters and Drill-Down: filter the analytics of a dashboard without changing the worksheet.