-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgxls_calc_mode.m
68 lines (60 loc) · 2.28 KB
/
gxls_calc_mode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
% [GSheet, status] = gxls_calc_mode(filename,calc_mode)
%-------------------------------------------------------------------------------
% Description:
% Change the calc mode of the spread sheet
%
% Input
% url_file: path or GSheet structure of the spreadsheet to modify
% calc_mode: calculation mode
% 1 for automatic (ON_CHANGE)
% 0 for manual (ON_HOUR)
%
%-------------------------------------------------------------------------------
% Raymond Olympio, 2018, [email protected]
%-------------------------------------------------------------------------------
function [GSheet, status] = gxls_calc_mode(url_file, calc_mode)
status = 0;
GSheet = [];
if ~exist('url_file','var') || isempty(url_file)
fprintf(2,'%s::No file provided\n',mfilename);
return;
end
if ~exist('calc_mode','var') || isempty(calc_mode)
calc_mode = -1;
end
% --------------------------- Get Constant for proper work with google sheet API
gxls_constants;
if ischar(url_file) %URL of the spreadsheet and sheetid
%convert file into Gsheet structure
GSheet = url2gsheet(url_file);
elseif isstruct(url_file) && isfield(url_file,'spreadsheetID')
GSheet = url_file;
clear file
end
switch calc_mode
case xlCalculateManual
calc_mode_str = 'HOUR';
%calc_mode_str = 'MINUTE';
case xlCalculationAutomatic
calc_mode_str = 'ON_CHANGE';
otherwise
calc_mode_str = 'ON_CHANGE';
end
% ------------------------------------------------------------- Generate request
request = ['''requests'': [',...
'{',...
'''updateSpreadsheetProperties'': {',...
'''properties'': {',...
'''autoRecalc'': ', '''' calc_mode_str '''',...
'},',...
'''fields'': ''autoRecalc''',...
'}',...
'}',...
'],',...
'''includeSpreadsheetInResponse'': false'];
% ----------------------------------------------------------------- Send request
[success, GSheet, connection] = gxls_send_req(GSheet, request);
%
if ~success
display(['Failed trying to change calculation mode of the spreadsheet. Last response was: ' num2str(connection.getResponseCode) '/' connection.getResponseMessage().toCharArray()']);
end