Nah kawan, sekarang aku mau share dikit tenang delphi..
Kali ini aku mau buat aplikasi yang bisa memberitahukan kita IP seseorang, kan kalo udah tau IP seseorang kita bisa maen-maen dengan PC-nya.. hehehe
Langsung aja y.
uses
Winsock;
function IAddrToHostName(const IP: string): string;
var
i: Integer;
p: PHostEnt;
begin
Result := '';
i := inet_addr(PChar(IP));
if i <> u_long(INADDR_NONE) then
begin
p := GetHostByAddr(@i, SizeOf(Integer), PF_INET);
if p <> nil then Result := p^.h_name;
end
else
Result := 'Invalid IP address';
end;
Rabu, 18 Agustus 2010
Kamis, 05 Agustus 2010
Eksport Data Bag. II
Nah untuk bagian ke-2 ini saya akan menuliskan listing program uintuk meng-eksport data dari DBGrid ke Excel, jadi diharapkan aplikasi yang kawan buat hasil proses maupun output yang akan di cetak bisa di cetak kedalam excel..
Dan ini adalah listing nya..
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,comobj, StdCtrls, DB, DBTables, Grids, DBGrids;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Table1: TTable;
Excel: TButton;
procedure ExcelClick(Sender: TObject);
private
{ Private declarations }
XlApp, XlBook, XlSheet, XlSheets, Range,chat : Variant; // Excel 97
WApp, Word : Variant; // Word 97
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ExcelClick(Sender: TObject);
var i,x:integer;
Sfile:string;
begin
// buka excel
XlApp := CreateOleObject('Excel.Application');
// tambahkan workbook
XlBook := XlApp.WorkBooks.Add;
// tambahkan worksheet
XlSheet := XlBook.worksheets.add;
//cetak header field dari dbgrid
for i:=0 to dbgrid1.FieldCount-1 do
begin
XlSheet.cells[2,i+1].value:=dbgrid1.columns[i].Title.Caption;
end;
// transfer data ke excel
table1.First;
x:=1;
while not table1.Eof do
begin
for i:=0 to dbgrid1.FieldCount-1 do
begin
XlSheet.cells[2+x,i+1].value:=dbgrid1.Fields[i].Text;
end;
table1.Next;
inc(x);
end;
//menampilkan aplikasi //XlApp.visible:=true;
//script dibawah ini untuk dialog disimpan atau ditampilkan
if MessageDlg('Apakah hasil export ditampilkan..?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
MessageDlg('Hasil Ditampilkan', mtInformation,
[mbOk], 0);
XlApp.visible:=true;
end
else
//simpan ke file
begin
Sfile:= InputBox('Nama File', 'hasil export', 'c:\hasil.xls');
XlApp.ActiveWorkbook.SaveAs(sfile);
XlApp.visible:=true;
end
end;
end.
Simpel kan....?? Selamat mencoba..
Dan ini adalah listing nya..
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,comobj, StdCtrls, DB, DBTables, Grids, DBGrids;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Table1: TTable;
Excel: TButton;
procedure ExcelClick(Sender: TObject);
private
{ Private declarations }
XlApp, XlBook, XlSheet, XlSheets, Range,chat : Variant; // Excel 97
WApp, Word : Variant; // Word 97
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ExcelClick(Sender: TObject);
var i,x:integer;
Sfile:string;
begin
// buka excel
XlApp := CreateOleObject('Excel.Application');
// tambahkan workbook
XlBook := XlApp.WorkBooks.Add;
// tambahkan worksheet
XlSheet := XlBook.worksheets.add;
//cetak header field dari dbgrid
for i:=0 to dbgrid1.FieldCount-1 do
begin
XlSheet.cells[2,i+1].value:=dbgrid1.columns[i].Title.Caption;
end;
// transfer data ke excel
table1.First;
x:=1;
while not table1.Eof do
begin
for i:=0 to dbgrid1.FieldCount-1 do
begin
XlSheet.cells[2+x,i+1].value:=dbgrid1.Fields[i].Text;
end;
table1.Next;
inc(x);
end;
//menampilkan aplikasi //XlApp.visible:=true;
//script dibawah ini untuk dialog disimpan atau ditampilkan
if MessageDlg('Apakah hasil export ditampilkan..?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
MessageDlg('Hasil Ditampilkan', mtInformation,
[mbOk], 0);
XlApp.visible:=true;
end
else
//simpan ke file
begin
Sfile:= InputBox('Nama File', 'hasil export', 'c:\hasil.xls');
XlApp.ActiveWorkbook.SaveAs(sfile);
XlApp.visible:=true;
end
end;
end.
Simpel kan....?? Selamat mencoba..
Eksport Data Bag. I
Ok kawan,,untuk materi sekarang saya akan mencoba menjabarkan listing program untuk meng-eksport data dari komponen listview ke dalam excel..
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,ComObj;
procedure TForm1.Button2Click(Sender: TObject);
var
xlapp, xlbook,XlSheet: OLEVariant;
baris,kolom,x,y:integer;
begin
xlapp := CreateOLEObject('Excel.Application');
xlbook := xlapp.Workbooks.Add;
XlSheet := XlBook.worksheets.add;
xlapp.Visible := True;
baris:=ListView1.Items.Count;
kolom:=3; // jumlah kolom listview
{Cetak judul kolom}
for x:=1 to 3 do
XlSheet.Cells[1,x].value:= ListView1.Columns[x-1].Caption;
for y:=0 to baris-1 do
for x:=1 to kolom do
begin
begin
if x=1 then
{cetak kolom pertama}
XlSheet.Cells[y+2,x].value := ListView1.Items.Item[y].Caption
else
{cetak kolom kedua dan seterusnya}
XlSheet.Cells[y+2,x].value := ListView1.Items.Item[y].SubItems[x-2];
end;
end;
end;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,ComObj;
procedure TForm1.Button2Click(Sender: TObject);
var
xlapp, xlbook,XlSheet: OLEVariant;
baris,kolom,x,y:integer;
begin
xlapp := CreateOLEObject('Excel.Application');
xlbook := xlapp.Workbooks.Add;
XlSheet := XlBook.worksheets.add;
xlapp.Visible := True;
baris:=ListView1.Items.Count;
kolom:=3; // jumlah kolom listview
{Cetak judul kolom}
for x:=1 to 3 do
XlSheet.Cells[1,x].value:= ListView1.Columns[x-1].Caption;
for y:=0 to baris-1 do
for x:=1 to kolom do
begin
begin
if x=1 then
{cetak kolom pertama}
XlSheet.Cells[y+2,x].value := ListView1.Items.Item[y].Caption
else
{cetak kolom kedua dan seterusnya}
XlSheet.Cells[y+2,x].value := ListView1.Items.Item[y].SubItems[x-2];
end;
end;
end;
Langganan:
Postingan (Atom)