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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| function forfreedom
clc clear close all stu_ppt = 0.2; score_mdf = 60; disp('开始工作咯, 计时, 滴~'); tic e = actxserver('excel.application'); path = pwd; xlsfiles = dir(fullfile(path, '*.xls')); disp(['这个目录下有' num2str(size(xlsfiles, 1)) '张表格']); for j = 1 : size(xlsfiles) disp(['正在处理第' num2str(j) '张表格>>>>>>>>>>>>>>>>>>>>>>>>>>>>>!']); xls_file_name = xlsfiles(j).name; WorkBook = e.Workbooks.Open([path '/' xls_file_name]);
sheets = e.ActiveWorkBook.Sheets; sheet1 = sheets.Item(1);
[~, xls] = xlsread([path '/' xls_file_name], 1); [xls_n, xls_p] = size(xls);
xls_title = xls{1, 1}; stu_num = xls_n - 5; stu_nam = xls(6 : end, 4); course_nam = xls(3, 5 : end - 3); course_cred = str2num(cell2mat(xls(4, 5 : end - 3))); score_matrix = xls(6 : end, 5 : end - 3); [score_matrix_n, score_matrix_p] = size(score_matrix); appendx = xls(6 : end, end - 2 : end);
toc fprintf('表格基本信息: \n表格标题: %s\n班级人数: %d\n总课程数: %d\n', ... xls_title, stu_num, length(course_nam));
[score_matrix{strncmp({'优'}, score_matrix, 1)}] = deal('95.0'); [score_matrix{strncmp({'良'}, score_matrix, 1)}] = deal('85'); [score_matrix{strncmp({'及格'}, score_matrix, 1)}] = deal('65.0'); [score_matrix{strncmp({'不及格'}, score_matrix, 1)}] = deal('50'); [score_matrix{strncmp({'-'}, score_matrix, 1)}] = deal('-1'); score_matrix_num = cellfun(@str2num, score_matrix); score_matrix_mark = score_matrix_num;
threshold = ceil(stu_num * stu_ppt); course_stu_num = sum(score_matrix_num ~= -1); course_delete_mask = course_stu_num <= threshold; course_delete_nam = course_nam(:, course_delete_mask); course_delete_stu_num = course_stu_num(course_delete_mask);
toc if (~isempty(course_delete_mask)) fprintf('忽略课程信息: \n有%d门课的成绩没有纳入计算绩点, 这些课可能是重修或双学位课程\n这些课程是:\n', ... sum(course_delete_mask)); for i = 1 : sum(course_delete_mask) fprintf('%-30s选课人数: %d\n', course_delete_nam{i}, course_delete_stu_num(i)); end end
score_matrix_num(:, course_delete_mask) = []; course_cred(:, course_delete_mask) = []; course_nam(:, course_delete_mask) = [];
score_mdf_mask = score_matrix_num < 60 & score_matrix_num >= 0; score_matrix_num(score_mdf_mask) = score_mdf; score_matrix_num(score_matrix_num < 0) = 50;
GPA = round((score_matrix_num - 50) * course_cred' ./ (sum(course_cred) * 10), 3);
sheet1.Range(['F1:F' num2str(xls_n)]).Insert; sheet1.Range(['F1:F' num2str(xls_n)]).Insert; sheet1.Range('F5').Value = '绩点'; sheet1.Range('G5').Value = '排名';
sheet1.Range(['F6:F' num2str(6 + stu_num - 1)]).Value = GPA; sheet1.Range(['F6:G' num2str(6 + stu_num)]).HorizontalAlignment = -4108; sheet1.Range(['F' num2str(6 + stu_num)]).Value = round(mean(GPA), 3);
[~, r] = sort(GPA, 'descend'); [~, r] = sort(r); sheet1.Range(['G6:G' num2str(6 + stu_num - 1)]).Value = r;
score_matrix_mark_mask = score_matrix_mark < 60 & score_matrix_mark >=0; [n, p] = find(score_matrix_mark_mask == 1);
for i = 1 : sum(score_matrix_mark_mask(:)) sheet1.Range(mark_score_excel_coor(n(i) + 5, p(i)+ 7)).Interior.ColorIndex = 6; end
if ~exist('Output', 'dir') mkdir('Output') end WorkBook.SaveAs([path '/Output/' xls_file_name]);
end e.Quit; e.delete; toc disp('呼~处理完毕*^-^*') end
function excel_coor = mark_score_excel_coor(n, p)
excel_coor = [ex(p) num2str(n)];
end
function excel_coor_p = ex(p) if p > 26 s = ex(fix((p-1) / 26)); excel_coor_p = [s char(65 + mod(p-1, 26))]; else excel_coor_p = char(65 + p - 1); end end
|