
fn='\\Gibbs\shattuck\CLASS\PHY204\F2005EE\grades_204EE_F2005.xls';
ofn='mailit2005F.sh';

range='a3:bc20'; % data range including names and grades

% position of info
first=2;
last=1;
quiz=8;
test=9;
course=10;
final=50;
grade=11;

CreateTempFileHead='echo -e "';
CreateTempFileTail='\n\n~r~/.signature" > temp$$';
MailHead='mail ';
MailTail=' -I -c shattuck@ccny.cuny.edu -s "Grades for Physics 204EE" < temp$$'; 
Clean='rm -f temp$$';

%% doit yourself
Excel = actxserver('excel.application');

workbook = Excel.workbooks.Open(fn);

Select(Range(Excel,range));
DataRange=get(Excel,'Selection');
data=DataRange.value;

workbook.Close(false); % close workbook without saving any changes.

delete(Excel); % delete COM server

%[num txt data]=xlsread(fn,1,range);

[Ns Nf]=size(data);

%% Create Mail Script
fid=fopen(ofn,'w');
for ns=1:Ns
  %str=sprintf('Email for %s %s:',data{ns,first},data{ns,last});
  letter=sprintf('Dear %s %s,\n\nYour grades for Physics 204 EE are as follows:\n',data{ns,first},data{ns,last});
  letter=[letter sprintf('Quiz Avg: %5.1f\n',data{ns,quiz})];
  letter=[letter sprintf('Test Avg: %5.1f\n',data{ns,test})];
  letter=[letter sprintf('Final: %5.1f\n',data{ns,final})];
  letter=[letter sprintf('\nCourse Grade: %5.1f => %s\n',data{ns,course},data{ns,grade})];
  letter=[letter sprintf('\n-- Mark Shattuck')];
  fprintf(letter);
  fprintf('\n');
  email=input('email: ','s');
   
  if (~isempty(email))
    fprintf(1,'Adding: %s\n',email);
    fprintf(fid,'%s%s%s\n',CreateTempFileHead,strrep(letter,sprintf('\n'),'\n'),CreateTempFileTail);
    fprintf(fid,'%s%s%s\n',MailHead,email,MailTail);
    fprintf(fid,'%s\n',Clean);
  end
end
fclose(fid);