From 1b1aaa6f5d614769c44fe86694509896ac9864dc Mon Sep 17 00:00:00 2001 From: mongo Date: Tue, 2 May 2017 11:26:36 -0300 Subject: Add subtotal to doc file --- src/cmds_command.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/cmds_command.c') diff --git a/src/cmds_command.c b/src/cmds_command.c index 9adca55..5331006 100644 --- a/src/cmds_command.c +++ b/src/cmds_command.c @@ -57,14 +57,12 @@ L"e! xlsx", L"datefmt", L"delfilter", L"delfilters", -L"fcopy", L"file", L"fill", L"filteron", L"filteroff", L"format", L"freeze", -L"fsum", L"h", L"help", L"hiddencols", @@ -107,6 +105,7 @@ L"showmaps", L"showrow", L"showrows", L"sort", +L"subtotal", L"trigger", L"untrigger", L"unformat", @@ -429,6 +428,50 @@ void do_commandmode(struct block * sb) { } send_to_interp(interp_line); + } else if ( ! wcsncmp(inputline, L"subtotal ", 9) ) { + int r = currow, c = curcol, rf = currow, cf = curcol, pos; + if (p != -1) { + c = sr->tlcol; + r = sr->tlrow; + rf = sr->brrow; + cf = sr->brcol; + } + if (any_locked_cells(r, c, rf, cf)) { + sc_error("Locked cells encountered. Nothing changed"); + return; + } + wchar_t line [BUFFERSIZE]; + wcscpy(line, inputline); + del_range_wchars(line, 0, 8); + if ( + (pos = wstr_in_wstr(line, L"@sum")) != -1 || + (pos = wstr_in_wstr(line, L"@avg")) != -1 || + (pos = wstr_in_wstr(line, L"@max")) != -1 || + (pos = wstr_in_wstr(line, L"@min")) != -1 ) { + add_wchar(line, L'\"', pos); + add_wchar(line, L'\"', pos+5); + } else if ( + (pos = wstr_in_wstr(line, L"@prod")) != -1) { + add_wchar(line, L'\"', pos); + add_wchar(line, L'\"', pos+6); + } else if ( + (pos = wstr_in_wstr(line, L"@count")) != -1) { + add_wchar(line, L'\"', pos); + add_wchar(line, L'\"', pos+7); + } else if ( + (pos = wstr_in_wstr(line, L"@stddev")) == -1) { + add_wchar(line, L'\"', pos); + add_wchar(line, L'\"', pos+8); + } else { + sc_error("Please specify a function to apply the subtotals."); + return; + } + swprintf(interp_line, BUFFERSIZE, L"subtotal %s%d:", coltoa(c), r); + swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%s%d ", coltoa(cf), rf); + swprintf(interp_line + wcslen(interp_line), BUFFERSIZE, L"%ls", line); + send_to_interp(interp_line); + unselect_ranges(); + } else if ( ! wcsncmp(inputline, L"freeze ", 7) ) { wcscpy(interp_line, inputline); send_to_interp(interp_line); -- cgit v1.2.3