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
|
procedure TFormCreatEnvoiFi.Button1Click(Sender: TObject);
var
aMSG:String;
FichIni:TIniFile;
x:Integer;
ListDest:TStrings;
aRange:AnsiString;
begin
// Ouvrir Classeur ModèleFi.xls
FichIni := TIniFile.Create('c:\fi\FINI.ini');
ASheetName:=FichIni.ReadString('Parametres', 'CHEMIN','');
Fichini.free;
aFileName:=aSheetName+'\modeleFi.XLS';
try
vMSExcel:=GetActiveOleObject('Excel.Application');
except
vMSExcel:=CreateOleObject('Excel.Application');
end;
vXLWorkbooks:=vMSExcel.workBooks;
vXLWorkBook:=vXLWorkBooks.open(aFilename);
//
FichIni := TIniFile.Create('c:\fi\FINI.ini');
ListDest:=TStringList.Create;
FichIni.ReadSectionValues('MonMail',ListDest);
// remplir cellule ds EXCEL avec Destinataire
vWorksheet:=vXLWorkBook.WorkSheets['FeuilleFi'];
for x:=0 to ListDest.Count-1 do
begin
aRange:='K'+IntToStr(x+1);
vCell:=vWorksheet.range[aRange];
vCell.value:=Copy(ListDest[x],3,Length(ListDest[x])-1);
end;
FichIni.Free;
ListDest.free;
vXLWorkBook.save;
TraiterFi; // procedure pour remplir un certain nombre de cellule
//
aFileName:='\FI '+DateTimeToStr(now);
aFileName:=ReplaceStr(aFilename,':','_');
aFileName:=ReplaceStr(aFilename,'/','_');
aFileName:=aFileName+'.xls';
AfileName:=aSheetName+AfileName;
vXLWorkBook.saveAs(aFileName);
vXLWorkBook.Close(false,AfileName);
vXLWorkBook:=unassigned;
vWorksheet:=unassigned;
vMSExcel.Quit;
vMSEXCEL:=unassigned;
//
end; |