with aqy do begin
{ Excel 中增加工作表,改名。 }
if gcName = '' then begin
Close;
sql.Text := 'SELECT FullName from ClassData WHERE gcid in (SELECT DISTINCT gcid FROM SessionData WHERE TermName = ' + '''' + TermName + '''' + ') ORDER BY FullName';
Open;
k:= 0;
First;
While not Eof do begin
if k > 0 then
WorkBook.sheets[1].copy(WorkBook.sheets[1]);
tmp:= Fields[0].AsString ;
WorkBook.sheets[1].Name:= tmp;
Next;
Inc(k);
end;
end else
WorkBook.sheets[1].Name:= gcName;
{ 算平均分 }
if gcName <> '' then begin
Close;
sql.Text:= 'SELECT FullName, SubID, AVG(SubScore) as avg01, Count(*) as count01 FROM StudentAnswer ' +
'INNER JOIN ' +
'(SELECT SessionID, FullName FROM SessionData INNER JOIN ClassData ' +
'ON SessionData.gcid = ClassData.gcID WHERE (TermName = ' + '''' + TermName + '''' + ') and (FullName = ' + '''' + gcName + '''' + ')) AA ' +
'ON StudentAnswer.SessionID = AA.SessionID ' +
'GROUP BY FullName, SubID ORDER BY FullName, SubID' ;
Open;
end else
begin
Close;
sql.Clear;
sql.Add('SELECT FullName, SubID, AVG(SubScore) as avg01, Count(*) as count01 FROM StudentAnswer ');
sql.Add('INNER JOIN ');
sql.Add('(SELECT SessionID, FullName FROM SessionData INNER JOIN ClassData ');
sql.Add('ON SessionData.gcid = ClassData.gcID WHERE (TermName = ' + '''' + TermName + '''' + ')) AA ');
sql.Add('ON StudentAnswer.SessionID = AA.SessionID ');
sql.Add('GROUP BY FullName, SubID ORDER BY FullName, SubID');
Open;
end;
{ 写入excel报表 }
str:= '';
First;
while not Eof do begin
tmp:= FieldByName('FullName').AsString;
if tmp <> str then begin
WorkBook.Sheets[tmp].Activate;
WorkBook.ActiveSheet.Cells[2, 3].value:= tmp;
WorkBook.ActiveSheet.Cells[2, 8].value:= FieldByName('count01').AsInteger;
end;
str:= tmp;
SubID:= FieldByName('SubID').AsInteger;
f:= RoundTo(FieldByName('avg01').AsFloat, -2);
WorkBook.ActiveSheet.Cells[22, SubID + 3].value:= FloatToStr(f);
Next;
end;
{ 算百分比 }
if gcName <> '' then begin
Close;
sql.Text := 'SELECT FullName, SubID, ' +
'SUM(field01) as sum01, SUM(field02) as sum02, SUM(field03) as sum03, SUM(field04) as sum04, ' +
'SUM(field05) as sum05, SUM(field06) as sum06, SUM(field07) as sum07, SUM(field08) as sum08, ' +
'SUM(field09) as sum09, SUM(field10) as sum10, SUM(field11) as sum11, SUM(field12) as sum12, ' +
'SUM(field13) as sum13, SUM(field14) as sum14, SUM(field15) as sum15, SUM(field16) as sum16, ' +
'SUM(field17) as sum17, SUM(field18) as sum18 ' +
'FROM studentanswer INNER JOIN ' +
'(SELECT SessionID, FullName FROM SessionData ' +
'INNER JOIN ClassData ON SessionData.gcid = ClassData.gcID WHERE (TermName = ' + '''' + TermName + '''' + ') and (FullName = ' + '''' + gcName + '''' + ')) AA ' +
'ON StudentAnswer.SessionID = AA.SessionID ' +
'GROUP BY FullName, SubID ORDER BY FullName, SubID';
Open;
end else
begin
Close;
sql.Text := 'SELECT FullName, SubID, ' +
'SUM(field01) as sum01, SUM(field02) as sum02, SUM(field03) as sum03, SUM(field04) as sum04, ' +
'SUM(field05) as sum05, SUM(field06) as sum06, SUM(field07) as sum07, SUM(field08) as sum08, ' +
'SUM(field09) as sum09, SUM(field10) as sum10, SUM(field11) as sum11, SUM(field12) as sum12, ' +
'SUM(field13) as sum13, SUM(field14) as sum14, SUM(field15) as sum15, SUM(field16) as sum16, ' +
'SUM(field17) as sum17, SUM(field18) as sum18 ' +
'FROM studentanswer INNER JOIN ' +
'(SELECT SessionID, FullName FROM SessionData ' +
'INNER JOIN ClassData ON SessionData.gcid = ClassData.gcID WHERE (TermName = ' + '''' + TermName + '''' + ')) AA ' +
'ON StudentAnswer.SessionID = AA.SessionID ' +
'GROUP BY FullName, SubID ORDER BY FullName, SubID';
Open;
end;
{ 写入excel报表 }
str:= '';
RecNum:= 0;
First;
while not Eof do begin
tmp:= FieldByName('FullName').AsString;
if tmp <> str then begin
WorkBook.Sheets[tmp].Activate;
RecNum:= WorkBook.ActiveSheet.Cells[2, 8].value;
end;
str:= tmp;
SubID:= FieldByName('SubID').AsInteger;
for i:= 1 to STAT_COUNT do begin
m:= Abs(Fields[i + 1].AsInteger);
WorkBook.ActiveSheet.Cells[i + 3, SubID + 3].value:= FloatToStr(RoundTo(100* m / RecNum, -2)) + '%';
end;
Next;
end;