Assuming the question is basically: “sort each row individually?” and also: “no need for keeping Formatting?” →→
# off topic:
# some grazy Variations of sort_key:
# key=lambda x: sum(map(ord, f"{x}"))
# key=lambda x: len(f"{x}")
def sort_rows( _range, reverse=False, key=lambda x: f"{x}"):
data = _range.DataArray
_range.DataArray = [sorted(row, reverse=reverse, key=key) for row in data]
def main_sort_row_by_row(*_):
doc = XSCRIPTCONTEXT.getDocument()
selection = doc.CurrentSelection
if selection.Rows.Count < 3000:
sort_rows(selection)
return
# below th switch to big-data-fans ;-)
# works so far with #300000 rows * 26 columns
OFFSET = 2500
sheet = selection.Spreadsheet
_by_pos = sheet.getCellRangeByPosition
_address = selection.RangeAddress
_left, _right, first, last = (_address.StartColumn,
_address.EndColumn,
_address.StartRow,
_address.EndRow )
for row in range(first, last, OFFSET+1):
slicerange = _by_pos(_left, row, _right, min(row+OFFSET, last ))
print(slicerange.AbsoluteName)
sort_rows(slicerange)