Ok. Ecco il codice:
procedure TForm3.Elabora1Click(Sender: TObject);
//var
begin
if verifica_ok = true then
begin
try
Ex := createoleobject('Excel.Application');
except
on E : Exception do
begin
MessageDlg('Errore nella creazione dell''istanza Microsoft Excel.', mtError, [mbOK], 0);
exit;
end;
end;
Ex.visible := vedi_ex;
// provo ad aprire excel
try
Ex.workbooks.open(L_vi.Caption);
except
on E : Exception do
begin
MessageDlg('Errore nell''apertura del file '+ L_vispi.caption , mtError, [mbOK], 0);
Exit;
end;
end;
end;
if cbox3.Checked = true then comp3;
ex.displayalerts := false;
ex.save;
ex.workbooks.close;
showmessage('Compilazione terminata');
end;
// compila il foglio3
procedure TForm3.comp3;
var
rigatesto : TextFile;
buffer : string;
filedacercare : string;
ctrrig : string;
xc, ri3, riga : integer;
importo : Extended;
imp : string;
xe : olevariant;
begin
Ex.workbooks.open(L_vi.Caption);
Ex.Workbooks[1].Worksheets['Foglio3'].select;
ri3 := 0;
riga := 10;
filedacercare := '';
filedacercare := (Trim(L_cartab.caption)) + '\' + (Trim(tab_3.text)+ '.TXT');
if FileExists(Trim(filedacercare)) = true then
begin
AssignFile(rigatesto, filedacercare);
Reset(rigatesto);
while not EOF(rigatesto) do begin
ri3:=ri3+1;
application.ProcessMessages;
Isp3pr.Text := inttostr(xc);
ReadLn(rigatesto, buffer);
If (ri3 >= rig3in) And (ri3 <= rig3fi) Then
begin
// finito
If (pos('Riepilogo', buffer) <> 0) Then
begin
s_3.Text := 'Compilato';
exit;
End;
// E' una riga con assegno
if (pos('test', buffer) <> 0) and (pos('test1', buffer) = 0) Then
begin
riga := riga + 1;
// data carico
If Length(Trim(copy(buffer, 81, 8))) <> 0 Then
begin
ex.Cells[riga, 1].Font.Size := 9;
ex.Cells[riga, 1].HorizontalAlignment := xlRight;
ex.Cells[riga, 1].NumberFormat := 'DD/MM/YY';
ex.Cells[riga, 1].Value := StrToDate(copy(buffer, 81, 8));
end;
end;
end;
end;
end;
CloseFile(rigatesto);
end;
end;
Questo e' un estratto del codice ma come dicevo il problema sta proprio nella riga
ex.Cells[riga, 1].NumberFormat := 'DD/MM/YY';
Grazie in anticipo.