-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveCSR.m
More file actions
112 lines (105 loc) · 4.14 KB
/
saveCSR.m
File metadata and controls
112 lines (105 loc) · 4.14 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function saveCSR(config,membMap,msg)
% The function output the results of the CSR procedure to a .xlsx file
[file,path] = uiputfile('.xlsx');
filename = [path,file];
data = cell(max(20,size(membMap,1)+7),4+size(membMap,1));
data{1,1} = 'Model';
data(2,1:2) = {'Partnership Cost',config.Model.club_membership_cost};
data(3,1:2) = {'Delta',config.Model.delta};
data(4:6,1:2) = {'w^h_h',config.Model.w(1);...
'w^h_l',config.Model.w(2);'w^l_l',config.Model.w(3)};
data{8,1} = 'Environment';
data(9,1:2) = {'number of Agents',config.Environment.number_of_agents};
color = find(config.Model.color == 2);
for i = 1:config.Environment.number_of_agents
data{1+i,4} = ['Agent ' num2str(i)];
data{1,4+i} = ['Agent ' num2str(i)];
end
data(2:1+config.Environment.number_of_agents,5:4+config.Environment.number_of_agents)=...
num2cell(membMap);
data{3+config.Environment.number_of_agents,4} = msg;
nAgents = config.Environment.number_of_agents;
nClubs = config.Environment.number_of_agents;
sheetId = 'Results';
hExcel = actxserver('excel.application');
%% Store the data in Excel:
try
% If a file by this name already exists:
hWorkbook = hExcel.Workbooks.Open(filename);
newFile = false;
catch
% If no file by this name exists:
hWorkbook = hExcel.Workbooks.Add();
newFile = true;
end
try
% If this sheet already exists:
hSheets = hWorkbook.WorkSheets;
if ischar(sheetId)
sheetNames = {};
for idx = 1 : hSheets.Count
sheetNames{end+1} = hSheets.Item(idx).name; %#ok<AGROW>
end
iSheet = find(strcmpi(sheetId,sheetNames));
end
hSheet = hSheets.Item(iSheet);
catch
hSheet = hSheets.Add([], hSheets.Item(hSheets.Count));
if ischar(sheetId)
hSheet.name = sheetId;
end
end
%%
temp = xlsColNum2Str(4+nClubs);
rangeMembmapTitles = ['D1:D' num2str(nAgents+1) ',' 'D1:' temp{1} '1'];
range2Write = ['A1:' char(xlsColNum2Str(size(data,2))) num2str(size(data,1))];
hSheet.Range(range2Write).Value = data;
%% Design customization:
% Borders:
% hRange = hSheet.Range('D1:D10,D1:O1,A1:B9,B1,A11:B14,B11,A16:B20,B15');
hRange = hSheet.Range([rangeMembmapTitles ',A1:B9']);
hRange.Borders.Item('xlEdgeLeft').LineStyle = 1; % xlContinuous
hRange.Borders.Item('xlEdgeLeft').Weight = 2; %xlThin
hRange.Borders.Item('xlEdgeTop').LineStyle = 1; % xlContinuous
hRange.Borders.Item('xlEdgeTop').Weight = 2; %xlThin
hRange.Borders.Item('xlEdgeBottom').LineStyle = 1; % xlContinuous
hRange.Borders.Item('xlEdgeBottom').Weight = 2; %xlThin
hRange.Borders.Item('xlEdgeRight').LineStyle = 1; % xlContinuous
hRange.Borders.Item('xlEdgeRight').Weight = 2; %xlThin
hRange.Borders.Item('xlInsideVertical').LineStyle = 1; % xlContinuous
hRange.Borders.Item('xlInsideVertical').Weight = 2; %xlThin
hRange.Borders.Item('xlInsideHorizontal').LineStyle = 1; % xlContinuous
hRange.Borders.Item('xlInsideHorizontal').Weight = 2; %xlThin
% Color Gray:
% hRange = hSheet.Range('D1:O1,D1:D10,A2:A9,A12:A15,A18:A20');
hRange = hSheet.Range([rangeMembmapTitles ',A2:A9']);
hRange.Interior.Pattern = 1; %xlSolid
hRange.Interior.Color = 12566463; % Gray
% Color Blue:
hRange = hSheet.Range(['A1,A4,A8,D2:D',num2str(1+nAgents)]);
hRange.Font.Bold = true;
hRange.Interior.Color = 15773696; % light blue
% Auto fit first 2 columns
hRange.Columns.Item('A:B').EntireColumn.AutoFit;
% catch
% end
first = 'A6';
if ~isempty(color)
first = [first,',D' num2str(1+color(1))];
for i = 2:length(color)
first = [first,',D' ,num2str(1+color(i))];
end
end
hRange = hSheet.Range(first);
hRange.Font.Bold = true;
hRange.Interior.Colorindex = 3; % red
%% Save:
if newFile
hWorkbook.SaveAs(filename, 51); % 51 = xlOpenXMLWorkbook
else
hWorkbook.Save;
end % if newFile
% hWorkbook.Save;
hWorkbook.Close;
hExcel.Quit;
end