diff options
author | mongo <andmarti@gmail.com> | 2017-05-02 11:26:36 -0300 |
---|---|---|
committer | mongo <andmarti@gmail.com> | 2017-05-02 11:26:36 -0300 |
commit | 1b1aaa6f5d614769c44fe86694509896ac9864dc (patch) | |
tree | 5e57162da661da44e0c7e7abc32064ded4c9731f /src/cmds_command.c | |
parent | b2f62651fdfa7626c5340229e1499262b13a618f (diff) |
Add subtotal to doc file
Diffstat (limited to 'src/cmds_command.c')
-rw-r--r-- | src/cmds_command.c | 47 |
1 files changed, 45 insertions, 2 deletions
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); |