Arsip: GImana Cara Save dan Print DBGRID

 
user image
more 12 years ago

ari_volker

alow,,,delphi mania,, mau nanya lagi,,,,boleh kan,, aku masih belom ngerti,, gimana cara SAve data Pada DBGRID ke xls,doc,txt,html,,dan lainnya Terus Bagaimana Cara Print data DBGRID tanpa memakai report,, Aku ga tau syntaxnya,,,, Mohon dibantu,,,
user image
more 12 years ago

MrLee

Baca buku Pemrograman database dengan delphi karangan HUSNI; penerbit graha ilmu; jika minat saya hanya bisa save ke excel dengan uses comobj; atau ke txt yg lain belum dipakai jadi ndak dipelajari dulu;
user image
more 12 years ago

MrLee

. . .
user image
more 12 years ago

ari_volker

gimana caranya,, boleh kasih tau,, sama cara print nya
user image
more 12 years ago

MrLee

1. cari di forum membaca excel; 2. pakai komonen excelexport; 3. Gunakan ComObj;

 //gunakan ComObj
// Membuat Data excel
var Sheet, Xls : Variant;
       xlw : variant;  //Jika digunakan
Xls := CreateOleObject('Excel.Application'); //siapkan Object Excel
//Buka File Excel
XLW := XLS.WorkBooks.Open(FileName := 'd:\Book1.XLS', Password := 'Lee', ReadOnly := True);
atau
XLS.WorkBooks.Open(FileName := 'd:\Book1.XLS', Password := 'Lee', ReadOnly := True);
  //judul atas sheet
XLS.Caption := 'Data Excel bla bla bla';
  // cara Menambah WorkBooks Baru;
XLS.WorkBooks.Add;  
  atau
XLS.WorkBooks[1].Sheets.Add;
  atau
XLS.WorkBooks[1].WorkSheets[1].Name := 'Nama Sheet Baru';
  atau
Sheet := XLS.WorkBooks[1].WorkSheets['Nama Sheet Baru'];
  atau
Sheet := XLS.WorkBooks[1].WorkSheets['Sheet1'];  //biasa saya pakai ini
bila sebelum perintah di bawa ini di jalankan dan terjadi error;
anda harus menutup / end task program excel secara manual, dgn ctrl alt del
Xls.visible := True; //Menampilkan Excel
//Menyimpan file Excel
sheet.SaveAs('NmFile');
XLW.SaveAs(FileName := 'D:\Book2.XLS', Paswoord := 'bla');
 //Menutup File Excel
if not VarIsEmpty(XLS) then  //Memerikasa apakah excel masih terbuka
begin
  XLS.DisplayAlerts := False; //Tidak Menampilkan Kotak pesan save file
  XLS.Quit; 
end;
//baca shell excel dan di simpan ke variable delphi
var data1 : integer; //bisa juga string
Data1 := Sheet.Cells[1,3].value;
//memberi nilai ke shell excelnya
Sheet.Cells[1,1] := 'Data Sel A1';
atau
Sheet.Cells[1,3].value := 'Data Sel C1';
Sheet.Cells[2,1] := 'Data Sel A2';
Sheet.Range['B3'] := 'Data Sel B3';
Sheet.Range['D3'] := '=+A1+34';
Sheet.Range['A1,H10'].Formula := 'rand()';  //mengisi banyak kolom
Sheet.cells[Brs,Klm].HorizontalAlignment := 1; 
    //1=general, 2=Left(indent), 3=center, 4=Right(indent)
      5=Fill, 6=Justify, 7=Center Across Selection
      8=Distributed(indent)
Sheet.Range['A1,H10'].Formula := 'rand()';
Sheet.range['B13'].verticalAlignment := 2;
  //1=Top, 2=Center, 3=Bottom, 4=Justify, 5=Distributed
Sheet.Range[Abj(KlmL+6)+Car(Brs)].copy;
Sheet.paste(sheet.Range[Abj(KlmL+7)+Car(Brs)]);
Sheet.Range['A2'].copy;        //Copy Dari Range A2 ke A4
Sheet.paste(sheet.Range['A4']);
Sheet.Cells[2,2].shrinktofit := True;
Sheet.cells[1,1].RowHeight := 30;
Sheet.cells[1,1].ColumnWidth := 20;
Sheet.columns[1].ColumnWidth := 20;
Sheet.Rows[7].RowHeight := 30;
//merubah Teks
Sheet.cells[brs,3].Font.Name := 'Times New Roman';
Sheet.cells[1,1].Font.Size := 52;
Sheet.cells[1,1].Font.Color := clBlue;
Sheet.cells[1,1].Font.Bold := true;
Sheet.cells[1,1].Font.italic := true;
Sheet.cells[1,1].Font.Underline := true;
Sheet.cells[1,1].Font.Underline := 1;
   //1=none, 2=single, 3=Double, 4=Singel Accounting, 5=Double Accounting
//Sheet.range['B13'].Font.StrikeThrough := true;
//Sheet.range['B13'].Font.SuperScript := true;
Sheet.range['B13'].Font.SubScript := true;

Sheet.cells[1,1].Wraptext := true;
Sheet.cells[1,1].Orientation := 10; // (derajat kemiringan) -10 kebawah
Sheet.range['a12'].shrinktofit := True;

Sheet.range['a12','c12'].Wraptext := true;
Sheet.range['a12','c12'].mergeCells := true;
atau
Sheet.range['a12','c12'].HorizontalAlignment := 7;
Sheet.Range['I1'].EntireColumn.HorizontalAlignment := 3;
Sheet.range['a12','c12'].HorizontalAlignment := 3;
Sheet.columns[chr(64+nBrsAwl)].Font.Name := 'Letter Gothic';
Sheet.range['A1','H1'].EntireColumn.Font.Size := 9;
Sheet.range['C3'].font.size := 24;
Sheet.range['C3', 'G5'].font.size := 24;
dll
//background
Sheet.cells[1,1].Interior.color := $00FF00; //BackGround Color
Sheet.range['B13'].interior.pattern := 1; //pattern dari 1 s/d 18
1 = Solid;
2 = 50% Gray;
3 = 75% Gray;
4 = 25% Gray;
5 = Horizontal Stripe
6 = Vertical Stripe
7 = Reverse Diagonal Stripe
8 = Diagonal Stripe
9 = Diagonal CrossHatch
10 = Thick Diagonal CrossHatch
11 = Thin Horizontal Stripe
12 = Thin Vertical Stripe
13 = Thin Reverse Diagonal Stripe
14 = Thin Diagonal Stripe
15 = Thin Horizontal CrossHatch
16 = Thin Diagonal CrossHatch
17 = 12,5% Gray;
18 = 6,25% Gray;
Sheet.range['B13'].interior.patterncolor := $00FFFF;
Sheet.cells[1,1].Borders[$00000009].LineStyle := 1;
Sheet.cells[1,1].Borders[$00000009].Weight := $FFFFEFD6;
Sheet.cells[1,1].Borders[$00000009].Color := $00FF00;
Sheet.cells[1,1].Borders[Garis_Dlm_Vertikal].LineStyle := 7;
                        Weight               excell
  xlHairline = $00000001; = 1     2
  xlMedium = $FFFFEFD6;= 3     12
  xlThick     = $00000004; = 4     13
  xlThin      = $00000002; = 2      7

   LineStyle      excel     Border (Garis)
1 ________ => 7       $00000005 Diagonal_Down
2 -------- => 6       $00000006 Diagonal_Up
3 ........ => 3       $00000007 Garis_Kiri
4 -.-.-.-. => 5       $00000008 Garis_Atas
5 -..-..-. => 4       $00000009 Garis_Bawah
6 -~~-~~-~ => 9       $0000000A Garis_Kanan
7 ________ => 7       $0000000B Garis_Dlm_Vertikal
8 ~~~~~~~~ => 6       $0000000C Garis_Dlm_Horizontal  //Dahulukan dari line yg lain
9 Double Line => 14

Sheet.cells[brs,klm].Orientation := 12; //sudut minus ke bawah
Sheet.cells[brs,klm].EntireColumn.Autofit;
Sheet.cells[brs,klm].EntireRow.Autofit;
Sheet.rows[Brs].EntireColumn.Autofit;
Sheet.range['C'+Car(Brs),Abj(Klm)+Car(Brs)].EntireColumn.ColumnWidth := 10.57;
                                                  atau   RowHeight
Sheet.cells[brs,klm].Insert(n,EmptyParam)  //Utk XP
atau
Sheet.cells[brs,klm].EntireRow.Insert(n,EmptyParam);
Sheet.cells[brs,klm].EntireRow.Insert(n);
Sheet.cells[brs,klm].Insert(n);
Sheet.cells[brs,klm].Insert(n,m);
nilai n (Insert)
1 Tambah & geser ke Kanan
2 Tambah & geser ke bawah
3 Tambah 1 row geser ke bawah
4 Tambah 1 column geser ke kanan
nilai m (insert)
0 tambah samakan format cell dng sel atas / kiri
1 tambah samakan format cell dng sel bawah / kanan
Sheet.cells[brs,klm].clear; //Reset to General
Sheet.cells[brs,klm].clearContent;
Sheet.cells[brs,klm].delete; //Hapus Sel Ybs
Sheet.cells[brs,klm].EntireColumn.Delete;  //Hapus Kolom di klm tsb
Sheet.cells[brs,klm].EntireRow.Delete;  //Hapus Kolom di Brs tsb
Sheet.cells[brs,klm] := '=D6+1';  /Nilai Rumus Range tsb
Sheet.cells[brs,klm].NumberFormat := 'General';
Sheet.cells[brs,klm].NumberFormat := '@';  //format Text
Sheet.cells[brs,klm].NumberFormat := 'dddd, dd/mm/yyyy'  //format Tanggal
Sheet.Range['D'+IntToStr(brs)] := FormatDateTime('mm/dd/yyyy',DmHrdJM.TblAbsensi.FieldByName('TglLemb').AsDateTime);
Sheet.cells[brs,klm].NumberFormat := '#'+ThousandSeparator+'##0'+DecimalSeparator+'0';  /Format Currency
Sheet.Columns[3].NumberFormat := '#'+ThousandSeparator+'###';
Sheet.Columns[3].NumberFormat :=  '#'+ThousandSeparator+'##0'+DecimalSeparator+'00_);Red';
Sheet.Range['D'+Car(Brs)] := '=sum(D'+Car(BrsA)+':D'+Car(Brs-1)+')';
Sheet.range['C'+Car(Brs),Abj(Klm)+Car(Brs)].EntireColumn.NumberFormat := '#'+ThousandSeparator+'##0'+DecimalSeparator+
       '00_);[Red]#'+ThousandSeparator+'##0'+DecimalSeparator+'00';
    #,###;[Red]#,###
    #,###_);[Red]#,###
    #,##0_);[Red]#,###
    #,##0;[Red]#,##0
Number Format
General    = General
Number     = 0.00 atau#,##0.00
            #,##0.00;[Red]#,##0.00-> Warna Merah Jika Minus
            #,##0.0_);(#,##0.00)-> Dlm Kurung Jika Minus
            #,##0.0_);href="#,##0.00" target="_blank" >Red -> Dlm Kurung Jika Minus & warna Merah
Currency   = $#,##0.00
             $#,##0.00;[Red]$#,##0.00
             $#,##0.0_);Red
Accounting = _($#,##0.00_);_($(#,##0.00);_($"-"??_);_(@_)
Date       = d/m/yyyy
Time       = h:mm:ss;@
Percentage = 0.00%
Fraction   = 

??/?? atau# ?/?

as halves =

?/2

as Quarters =

?/4

as tenths =

?/10

as hundredths =

??/100

Scientific = 0.00E+00 Text = @ Special = [<=9999999]###-####;(###)###-#

-> u/ Phone Number

Custom = 00000 Sheet.columns[2].group(1); Sheet.rows[2].group(1); Sheet.Cells[3,3].group(1); //2 group kolom Sheet.Cells[2,3] := xls.Workbooks.count; Sheet.rows['2'].font.size := 24; Sheet.columns['C'].font.size := 20; sheet.pagesetup.printgridlines:=false; sheet.pagesetup.centerHeader:='AAAAA'; sheet.pagesetup.RightHeader:='&[Page]/&[Pages]'; sheet.pagesetup.centerFooter:='AAAAA'; sheet.outline.summaryRow := true; sheet.outline.summarycolumn := false; regional setting measurement system delphi = Metric = US //ukur sendiri 14.173 = 0.5 = 0,196850393700787 28.346 = 1 = 0,393700787401575 42.519 = 1.5 = 0,590551181102362 56.692 = 2 = 0,78740157480315 sheet.pagesetup.HeaderMargin := 0 ; sheet.pagesetup.LeftMargin := 14 ; sheet.pagesetup.RightMargin := 14; sheet.pagesetup.TopMargin := 14; sheet.pagesetup.BottomMargin := 14; sheet.pagesetup.HeaderMargin := 14; sheet.pagesetup.FooterMargin := 14; sheet.pagesetup.orientation :=2; //1 portait sheet.pagesetup.Papersize := 1; //nomor pilihan ada di bawah papersize //semua printer sama, tapi hanya ada format yg tidak terpakai seperti // 39 = US Std Fanfold 14 7/8 x 11 in tdk di kenal di printer kecil 1 = Letter 215.9 x 279.4 mm (8 1/2 x 11 in) 3 = Tabloid 11 x 17 in 5 = Legal 215.9 x 355.6 mm (8 1/2 x 14 in) 6 = Statement 5 1/2 x 8 1/2 in 8 = A3 297 x 420 mm 9 = A4 210.0 x 297.0 mm 11 = A5 148.0 x 210.0 mm 12 = B4 (JIS) 257 x 364 mm 13 = B5 (JIS) 182.0 x 257.0 mm 14 = Folio 8 1/2 x 13 in 16 = 10 x 14 in 19 = Env#93/7 x 8 7/8 in 20 =#10Env. 241.3 x 104.6 mm 27 = DL Env. 220.0 x 110.0 mm 31 = Env C6 114 x 162 34 = Env B5 176 x 250 mm 36 = Env 110 x 203 mm 37 = Env Monarch 3 7/8 x 7 1/2 in 39 = US Std Fanfold 14 7/8 x 11 in 40 = German Std Fanfold 8 1/2 x 12 in 41 = German legal fanfold 8 1/2 x 13 in (Folio) 66 = A2 420 x 594 mm 258 = A3 Rotated 420 x 297 mm 258 = Letter Tansverse 11 x 8.5 in 259 = A4 Rotated 297 x 210 mm 259 = A2 420 x 594 mm 260 = Letter fanfold 8 1/2 x 11 in 260 = A3 Transverse 420 x 297 mm 261 = A4 Fanfold 210 x 11 2/3 in 261 = A4 Transverse 297 x 210 mm 262 = 14 7/8 x 11.59 262 = Fanfold 11 x 8 1/2 in 263 = Fanfold 210 x 305 mm 263 = Fanfold 8.5 x 12 in 264 = Fanfold 358 x 305 mm 264 = 8 x 6 inc 265 = 6 3/4 Env 6 1/2 x 3 5/8 in 265 = Fanfold 210 mm x 12 in 266 = Env#109 1/2 x 4 1/8 in 266 = Fanfold 358mm x 12 in 267 = Fanfold 8.5 x 13 in 267 = Env. DL 220.0 x 110.0 mm 268 = Env. C5 229 x 162 mm 268 = Fanfold 15 x 12 in 269 = Card 148 x 105 mm 284 = Canon 101.6 x 152.4 mm sheet.printpreview; sheet.print;
manual banget khan, tapi bisa membuat berbagai format tampilan sesuai yang di inginkan dan tidak tergantung ama yg lain; sewaktu sedang di proses ke excel, excelnya jangan di utak atik, pasti pengisian data nya stop dan error pada delphi. pelajari dan coba dulu; semua perintah diatas sudah saya pakai di excel 2000 s/d 2007; itulah semua yg saya tahu untuk option lain saya sedang cari tahu dan tanya di forum ini belum ada yang berih tahu seperti option persentase mencetak/preview dll nya post ke saya jika udah dapat ya!! buat yang lain jika tahu perintah yg lain tolong post donk!; biar bagi-bagi lah gitu;
user image
more 12 years ago

delphinewbie

pake TmxExport kayanya lebih mudah... Features: Exports Tables, Queries, ClientDataSets and all TDataSet descendants Exports Grids ( TDBGrid, TStringGrid etc... ) Exports TStrings and its descendants You can easily create your own export components with TmxCustomExport class It supports: HTML, XLS, DOC, TXT, TAB, DIF, RTF, SLK, CSV and the clipboard Its code 100% Native, so you do not need to have installed Office, OCX or other tools As it does not use OLE it is very fast even for big amount of data Exports to file even if the application is not installed on your computer Any export formats can be disabled Full source code available * And so many more possibilities... freeware unduh di http://www.maxcomponents.net/
user image
more 12 years ago

ari_volker

Thankz berat nih,, Aku lagi ke TKP langsung nyedot,,
user image
more 12 years ago

maulaku

@delphinewbie: pake TmxExport kayanya lebih mudah...
xixix aku coba download tapi filenya ada yang kurang, aku coba pakai delphi 7 mxNativeExcel_d7 kok ngga ada..
more ...
  • Pages:
  • 1
Share to
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com