-
Notifications
You must be signed in to change notification settings - Fork 0
/
gxls_numformat.m
95 lines (84 loc) · 2.99 KB
/
gxls_numformat.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
% Excel = xls_numformat(filename,sheetname,range, format_str)
%-------------------------------------------------------------------------------
% Description:
%
%
% Input
%
%
%
%
%
%-------------------------------------------------------------------------------
% Raymond OLYMPIO, raymond.olympio@airbus.com
%-------------------------------------------------------------------------------
function [GSheet, status] = gxls_numformat(url_file, sheetname, range, format_str)
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)
format_str = 'normal';
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
% ---------------------------------------------------------------------- Options
%Process format
if strcmp(format_str,'percent')
numfmt_type = 'PERCENT';
numfmt_pattern = '0.00%';
elseif strcmp(format_str,'scientific')
numfmt_type = 'SCIENTIFIC';
numfmt_pattern = '0.00E+00';
elseif strcmp(format_str,'normal')
numfmt_type = 'NUMBER';
numfmt_pattern= '0.00';
elseif strcmp(format_str,'integer')
numfmt_type = 'NUMBER';
numfmt_pattern='0';
else
numfmt_type = 'NUMBER';
numfmt_pattern=format_str;
end
% ------------------------------------------------------------- Generate request
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
% ------------------------------------------------------------ Processed options
[sheetId, GSheet] = gxls_sheetname2sheetid(GSheet, sheetname);
%Process range
range = convert_range(range);
range.sheetId = sheetId;
%
% ------------------------------------------------------------- Generate request
request = ['''requests'': [',...
'{',...
'''repeatCell'': {',...
'''range'': ' gxls_req_gridrange(range) ',',...
'''cell'': {',...
'''userEnteredFormat'': {',...
'''numberFormat'': ',...
gxls_req_numfmt(numfmt_type,numfmt_pattern),...
'}',...
'},',...
'''fields'': ''userEnteredFormat.numberFormat'''...
'}}]'];
% ----------------------------------------------------------------- Send request
[success, GSheet, connection] = gxls_send_req(GSheet, request);
%
if ~success
display(['Failed trying to change number format in sheet ' sheetname '. Last response was: ' num2str(connection.getResponseCode) '/' connection.getResponseMessage().toCharArray()']);
end