Kategori: Com & ActiveX
(I) Gunakan metode pembuatan dinamis
Pertama -tama buat objek Excel, menggunakan comobj:
var excelapp: varian;
Excelapp: = createoleObject ('excel.application');
1) Tampilkan jendela saat ini:
Excelapp.visible: = true;
2) Ubah bilah judul Excel:
Excelapp.Caption: = 'Aplikasi memanggil Microsoft Excel';
3) Tambahkan buku kerja baru:
Excelapp.workbooks.add;
4) Buka buku kerja yang ada:
Excelapp.workbooks.open ('c: /excel/demo.xls');
5) Atur lembar kerja kedua sebagai lembar kerja aktif:
Excelapp.worksheets [2] .aktivasi;
atau
Excelapp.worksheets ['sheet2'] .aktivasi;
6) Tetapkan nilai ke sel:
Excelapp.cells [1,4] .value: = 'baris pertama, kolom keempat';
7) Atur lebar kolom yang ditentukan (unit: jumlah karakter), mengambil kolom pertama sebagai contoh:
Excelapp.activesheet.columns [1] .columnswidth: = 5;
8) Atur ketinggian baris yang ditentukan (unit: pound) (1 pound = 0,035 cm), dan gunakan contoh perilaku kedua:
Excelapp.activesheet.rows [2] .rowHeight: = 1/0.035;
9) Masukkan Halaman Istirahat sebelum baris 8:
Excelapp.worksheets [1] .rows [8] .pagebreak: = 1;
10) Hapus Halaman Istirahat Sebelum Kolom 8:
Excelapp.activesheet.columns [4] .pagebreak: = 0;
11) Tentukan lebar garis perbatasan:
Excelapp.activesheet.range ['b3: d4'] .Borders [2] .Weight: = 3;
1-LEFT 2-RIGHT 3-TOP 4-Bottom 5-Slant ( /) 6-Slant ( /)
12) Bersihkan rumus sel dari baris pertama dan kolom keempat:
Excelapp.activesheet.cells [1,4] .clearcontents;
13) Atur properti font dari baris pertama:
Excelapp.activesheet.rows [1] .font.name: = 'lishu';
Excelapp.activesheet.rows [1] .font.color: = clblue;
Excelapp.activesheet.rows [1] .font.bold: = true;
Excelapp.activesheet.rows [1] .font.underline: = true;
14) membuat pengaturan halaman:
a.
Excelapp.activesheet.pagesetup.centerHeader: = 'Laporan Demo';
b.
Excelapp.activesheet.pagesetup.centerfooter: = 'page & p';
c.
Excelapp.activesheet.pagesetup.headermargin: = 2/0,035;
d.
Excelapp.activesheet.pagesetup.headermargin: = 3/0,035;
e. Margin teratas 2cm:
Excelapp.activesheet.pagesetup.topmargin: = 2/0,035;
f.
Excelapp.activesheet.pagesetup.bottommargin: = 2/0,035;
G. Margin Left 2cm:
Excelapp.activesheet.pagesetup.leftmargin: = 2/0,035;
h. margin kanan 2cm:
Excelapp.activesheet.pagesetup.rightmargin: = 2/0,035;
i.
Excelapp.activesheet.pagesetup.centerhorizontally: = 2/0,035;
J.
Excelapp.activesheet.pagesetup.centervertically: = 2/0,035;
K KABEL CELLAN CELL:
Excelapp.activesheet.pagesetup.printgridlines: = true;
15) Operasi Salin:
a.
Excelapp.activesheet.used.range.copy;
b.
Excelapp.activesheet.range ['a1: e2'] .copy;
c. Mulai menempel dari posisi A1:
Excelapp.activesheet.range. ['A1'] .paspecial;
d.
Excelapp.activesheet.range.pastespecial;
16) Masukkan baris atau kolom:
a.
b. Excelapp.activesheet.columns [1].
17) Hapus baris atau kolom:
a.
b.
18) Cetak Lembar Kerja Pratinjau:
Excelapp.activesheet.printpreview;
19) Lembar Kerja Cetak:
Excelapp.activesheet.printout;
20) Penghematan Lembar Kerja:
Jika tidak excelapp.activeWorkBook.saved maka
Excelapp.activesheet.printpreview;
21) Simpan lembar kerja sebagai:
Excelapp.saveas ('c: /excel/demo1.xls');
22) Menyerah Menyimpan:
Excelapp.activeWorkBook.Saved: = true;
23) Tutup buku kerja:
Excelapp.workbooks.close;
24) Keluar dari Excel:
Excelapp.quit;
(Ii) Gunakan metode kontrol delphi
Masukkan ExcelApplication, Excelworkbook, dan Excelworksheet dalam bentuk masing -masing.
1) Buka Excel
Excelapplication1.connect;
2) Tampilkan jendela saat ini:
Excelapplication1.visible [0]: = true;
3) Ubah bilah judul Excel:
Excelapplication1.caption: = 'Aplikasi memanggil Microsoft Excel';
4) Tambahkan buku kerja baru:
Excelworkbook1.connectto (excelapplication1.workbooks.add (emptyparam, 0));
5) Tambahkan lembar kerja baru:
var temp_worksheet: _worksheet;
Mulai
Temp_worksheet: = excelworkbook1.
Worksheets.add (emptyparam, emptyparam, emptyparam, emptyparam, 0) sebagai _worksheet;
Excelworksheet1.connectto (temp_worksheet);
Akhir;
6) Buka buku kerja yang ada:
Excelapplication1.workbooks.open (c: /a.xls
Emptyparam, emptyparam, emptyparam, emptyparam, emptyparam,
Emptyparam, emptyparam, emptyparam, emptyparam, emptyparam,
Emptyparam, emptyparam, emptyparam, emptyparam, 0)
7) Atur lembar kerja kedua sebagai lembar kerja aktif:
Excelapplication1.worksheets [2] .aktivasi;
Excelapplication1.worksheets ['sheet2'] .aktivasi;
8) Tetapkan nilai ke sel:
Excelapplication1.cells [1,4] .value: = 'baris pertama, kolom keempat';
9) Atur lebar kolom yang ditentukan (unit: jumlah karakter), mengambil kolom pertama sebagai contoh:
Excelapplication1.activesheet.columns [1] .columnswidth: = 5;
10) Atur ketinggian baris yang ditentukan (unit: pound) (1 pound = 0,035 cm), dan gunakan contoh perilaku kedua:
Excelapplikasi1.activesheet.rows [2] .rowHeight: = 1/0,035;
11) Masukkan Halaman Istirahat sebelum baris 8:
Excelapplication1.worksheets [1] .rows [8] .pagebreak: = 1;
12) Hapus Halaman Istirahat Sebelum Kolom 8:
Excelapplication1.activesheet.columns [4] .pagebreak: = 0;
13) Tentukan lebar garis perbatasan:
Excelapplication1.activesheet.range ['b3: d4'] .Borders [2] .Weight: = 3;
1-LEFT 2-RIGHT 3-TOP 4-Bottom 5-Slant ( /) 6-Slant ( /)
14) Bersihkan rumus sel dari baris pertama dan kolom keempat:
Excelapplication1.activesheet.cells [1,4] .clearcontents;
15) Atur properti font dari baris pertama:
Excelapplication1.activesheet.rows [1] .font.name: = 'lishu';
Excelapplication1.activesheet.rows [1] .font.color: = clblue;
Excelapplication1.activesheet.rows [1] .font.bold: = true;
Excelapplication1.activesheet.rows [1] .font.underline: = true;
16) membuat pengaturan halaman:
a.
Excelapplication1.activesheet.pagesetup.centerHeader: = 'Laporan Demo';
b.
Excelapplication1.activesheet.pagesetup.centerfooter: = 'page & p';
c.
Excelapplication1.activesheet.pagesetup.headermargin: = 2/0,035;
d.
Excelapplication1.activesheet.pagesetup.headermargin: = 3/0,035;
e. Margin teratas 2cm:
Excelapplication1.activesheet.pagesetup.topmargin: = 2/0,035;
f.
Excelapplication1.activesheet.pagesetup.bottommargin: = 2/0,035;
G. Margin Left 2cm:
Excelapplication1.activesheet.pagesetup.leftmargin: = 2/0,035;
h. margin kanan 2cm:
Excelapplication1.activesheet.pagesetup.rightmargin: = 2/0,035;
i.
Excelapplication1.activesheet.pagesetup.centerhorizontally: = 2/0,035;
J.
Excelapplication1.activesheet.pagesetup.centervertically: = 2/0,035;
K KABEL CELLAN CELL:
Excelapplication1.activesheet.pagesetup.printgridlines: = true;
17) Operasi Salin:
a.
Excelapplication1.activesheet.used.range.copy;
b.
Excelapplication1.activesheet.range ['a1: e2'] .copy;
c. Mulai menempel dari posisi A1:
Excelapplication1.activesheet.range. ['A1'] .paspececial;
d.
Excelapplication1.activesheet.range.paspecial;
18) Masukkan baris atau kolom:
a.
b. Excelapplication1.activesheet.columns [1]. Insert;
19) Hapus baris atau kolom:
a.
b. Excelapplication1.activesheet.columns [1] .delete;
20) Cetak Lembar Kerja Pratinjau:
Excelapplication1.activesheet.printpreview;
21) Lembar Kerja Cetak:
Excelapplication1.activesheet.printout;
22) Penghematan Lembar Kerja:
Jika tidak excelapplication1.activeWorkBook.saved maka
Excelapplication1.activesheet.printpreview;
23) Simpan lembar kerja sebagai:
Excelapplication1.saveas ('c: /excel/demo1.xls');
24) Menyerah Menyimpan:
Excelapplication1.activeWorkBook.saved: = true;
25) Tutup buku kerja:
Excelapplication1.workbooks.close;
26) Keluar dari Excel:
Excelapplication1.quit;
Excelapplication1.disconnect;
(Iii) Gunakan Delphi untuk mengontrol diagram 2D Excel
Masukkan ExcelApplication, Excelworkbook, dan Excelworksheet dalam bentuk masing -masing
var shell1, acart, rentang: varian;
1) Pilih lembar kerja pertama saat buku kerja pertama
shell1: = excelapplication1.workbooks [1] .worksheets [1];
2) Tambahkan grafik dua dimensi
achart: = sheet1.chartObjects.add (100.100.200.200);
3) Pilih bentuk grafik dua dimensi
achart.chart.chartType: = 4;
4) Tetapkan nilai ke grafik dua dimensi
Seri: = acart.chart.SeriesCollection;
rentang: = sheet1! r2c3: r3c9;
Series.Add (range, true);
5) Tambahkan judul grafik dua dimensi
achart.chart.hastitle: = true;
achart.chart.charttitle.characters.text: = 'excle 2d diagram'
6) Ubah ukuran font judul dari grafik dua dimensi
achart.chart.charttitle.font.size: = 6;
7) Tambahkan deskripsi ke sosok dua dimensi
achart.chart.axes (xlcategory, xlprimary) .hastitle: = true;
achart.chart.axes (xlcategory, xlprimary) .axistitle.characters.text: = 'deskripsi subscript';
8) Tambahkan tanda kiri ke sosok dua dimensi
achart.chart.axes (xlvalue, xlprimary) .hastitle: = true;
achart.chart.axes (xlvalue, xlprimary) .axistitle.characters.text: = 'Deskripsi tanda kiri';
9) Tambahkan tanda kanan ke sosok dua dimensi
achart.chart.axes (xlvalue, xlsecondary) .hastitle: = true;
achart.chart.axes (xlvalue, xlsecondary) .axistitle.characters.text: = 'Deskripsi tanda kanan';
10) Ubah ukuran area tampilan dari grafik dua dimensi
achart.chart.plotarea.left: = 5;
achart.chart.plotarea.width: = 223;
achart.chart.plotarea.height: = 108;
11) Tambahkan instruksi ke sumbu koordinat dari grafik dua dimensi
achart.chart.SeriesCollection [1] .name: = 'Axis Description';