Kod: Tümünü seç
procedure TForm3.BitBtn9Click(Sender: TObject);
var ExcelApp, WBook, Sheet: OleVariant;
Row, Col, I: Integer; // satır ve sütün için değişken
begin
If Edit1.Text='' Then
Begin
Application.MessageBox('Boş Kayıt Excel gönderilemez !!! ','Uyarı Mesajı',MB_ICONERROR);
End
Else
Begin
if ERehber.IsEmpty then Exit;
try
ExcelApp := CreateOleObject('Excel.Application');
WBook := ExcelApp.WorkBooks.Add;
Sheet := WBook.WorkSheets[1];
Sheet.Range['A1','I1'].Merge;
Sheet.Range['A1','I1'].Font.Bold:=True;
Sheet.Range['A1','I8'].Font.Color:=clRed;
Sheet.Cells[1,1].Value:='Emanet Stok Çıkış Fişi';
Sheet.Cells[1,1].HorizontalAlignment := -4108;
Sheet.Cells[1,1].Font.Size := 20;
Sheet.Cells[2,1].Value:='Fiş No';
Sheet.Cells[3,1].Value:='Cari Kod';
Sheet.Cells[4,1].Value:='Cari İsim';
Sheet.Cells[5,1].Value:='Cari Adres';
Sheet.Cells[6,1].Value:='Vergi Dairesi';
Sheet.Cells[7,1].Value:='Vergi No';
Sheet.Cells[8,1].Value:='Stok Kodu';
Sheet.Cells[8,2].Value:='Stok İsmi';
Sheet.Cells[8,3].Value:='Miktar';
Sheet.Cells[8,4].Value:='Ölçü Birimi';
Sheet.Cells[8,5].Value:='Tip';
Sheet.Cells[8,6].Value:='Çıkış Tarihi';
Sheet.Cells[8,7].Value:='Barkod';
Sheet.Cells[8,8].Value:='Stok Satır Açıklama';
Sheet.Cells[8,9].Value:='Kalan Stok';
Sheet.Range['A2','I8'].Font.Bold:=True;
Sheet.Range['A2','I8'].Font.Color:=clRed;
CASABIT.close;
CASABIT.sql.clear;
CASABIT.sql.add('SELECT * FROM TBLCASABIT where CARI_KOD='+#39+''+DBEdit1.text+''+#39+'');
CASABIT.open;
Sheet.Cells[2,2].Value:='''' + Edit1.Text;
Sheet.Cells[3,2].Value:='''' + DBEdit1.Text;
Sheet.Cells[4,2].Value:='''' + DBEdit2.Text;
Sheet.Cells[5,2].Value:='''' + CaSabit.Fields[14].asstring;
Sheet.Cells[6,2].Value:='''' + CaSabit.Fields[16].asstring;
Sheet.Cells[7,2].Value:='''' + CasaBit.Fields[17].asstring;
except
ShowMessage('Excel başlatılamıyor.'); Exit;
end;
try
with ERehber do
begin
Row := 9; // başlangıç 9. satır
First;
While not Eof do
begin
Col := 0;
for i := 0 to DBGrid1.FieldCount - 1 do
if i <> 2 then
begin
Inc(Col);
Sheet.Cells[Row, Col].Value := DBGrid1.Fields[i].Value;
if Col >= 2 then
// Sheet.Cells[Row,Col].NumberFormat := '0_ ;-0';
Sheet.Cells[Row,Col].NumberFormat := '#';
if (Col = 6) then
Sheet.Cells[Row, Col].NumberFormat := 'gg.aa.yyyy';
end;
// Sheet.Cells[Row, Col + 1].Value := Edit5.Text;
Next;
Inc(Row);
end;
end;
finally
Sheet.Columns['A:I'].EntireColumn.AutoFit;
ExcelApp.Visible := True;
ExcelApp.ActiveSheet.PageSetup.Zoom := 85;
ExcelApp := Null; WBook := Null; Sheet := Null;
end;
end;
end;
Kod: Tümünü seç
Filitre.close;
Filitre.sql.clear;
Filitre.sql.add('SELECT ESTOK_KODU,ESTOK_ADI,');
Filitre.sql.add('SUM(CASE WHEN EGCTIP='+#39+'G'+#39+' then ESTHAR_GCMIK else 0 end) [SGTOP],');
Filitre.sql.add('SUM(CASE WHEN EGCTIP='+#39+'C'+#39+' then ESTHAR_GCMIK else 0 end) [SCTOP],');
Filitre.sql.add('SUM((CASE WHEN EGCTIP='+#39+'G'+#39+' then ESTHAR_GCMIK else 0 end)-(CASE WHEN EGCTIP='+#39+'C'+#39+' then ESTHAR_GCMIK else 0 end)) [SKTOP]');
Filitre.sql.add('FROM TBLEMANET where ECARI_KOD='+#39+''+DBEdit1.text+''+#39+'');
Filitre.sql.add('and ESTOK_KODU='+#39+''+DBEdit6.text+''+#39+'');
Filitre.sql.add('GROUP BY ESTOK_KODU,ESTOK_ADI');
Filitre.open;