文件名称:excel control by delphi
文件大小:219KB
文件格式:ZIP
更新时间:2009-03-15 02:52:39
另类其它 控件 源码 资源
//About my self excel control ..... study data // for your information... unit toxls5butt; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Excel2000, OleServer; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; CheckBox1: TCheckBox; Button5: TButton; SaveDialog1: TSaveDialog; OpenDialog1: TOpenDialog; // ExcelWorksheet1: TExcelWorksheet; // ExcelOLEObject1: TExcelOLEObject; // ExcelWorkbook1: TExcelWorkbook; // ExcelApplication1: TExcelApplication; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private v:variant; sheet:variant; { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation { *.dfm} uses comobj; procedure TForm1.Button1Click(Sender: TObject); begin try V:=createoleobject(‘excel.application‘); v.visible:=checkbox1.Checked; v.workbooks.add; v.workbooks[1].worksheets[1].name:=‘good‘; sheet:=v.workbooks[1].worksheets[1]; sheet.cells[3,1]:=‘31‘; sheet.cells[2,1]:=‘21‘; sheet.cells[1.5]:=‘15‘; sheet.cells[2,2]:=‘22‘; v.workbooks[1].worksheets[2].name:=‘love‘; sheet:=v.workbooks[1].worksheets[2]; sheet.cells[3,4]:=‘34hello‘; // sheet:=v.workbooks[1].worksheets[‘helloaaa‘]; except showmessage(‘excel init load error, not excel or other error!‘); v.displayalerts:=false; v.quit; exit; end; application.Restore; application.BringToFront; end; procedure TForm1.Button2Click(Sender: TObject); begin if opendialog1.Execute then begin try V:=createoleobject(‘excel.application‘); v.visible:=checkbox1.Checked; v.workbooks.open(opendialog1.FileName); except showmessage(‘excel init error, not excel or other error, try again‘); v.displayalerts:=false; v.quit; exit; end; application.Restore; application.BringToFront; end; end; procedure TForm1.Button3Click(Sender: TObject); begin try if not varisempty(v) then begin v.DisplayAlert:=true; v.workbooks[1].close(true,‘c:untitled.xls‘); v.workbooks[1].close(true,‘*.xls‘); v.quit; end; finally close; end; end; procedure TForm1.Button4Click(Sender: TObject); begin if opendialog1.Execute then begin try v:=createoleObject(‘excel.application‘); v.visible:=checkbox1.Checked; v.workbooks.open(opendialog1.FileName); sheet:=v.workbooks[1].worksheet[1]; sheet.pagesetup.printtitlerows:=‘$1:$3‘; //page head sheet.pagesetup.printtitlecolumns:=‘‘; sheet.pagesetup.leftfooter:=‘Noted: PageHead‘+‘sum total&N page ‘+‘--No.&Page‘; //pagehead sheet.pagesetup.leftmargin:=30; //偞离?擒 Sheet.PageSetup.RightMargin := 30; Sheet.PageSetup.TopMargin := 30; Sheet.PageSetup.BottomMargin := 50; Sheet.PageSetup.PrintQuality := 300; //賤昴僅(跦?荂桶復隅) Sheet.PageSetup.CenterHorizontally := True;//岆瘁阨懈笢 Sheet.PageSetup.CenterVertically := True; //岆瘁晶眻懈笢 Sheet.PageSetup.Orientation := 2; //砃蹈荂 Sheet.PageSetup.Draft := False; //準翌詨耀宒 Sheet.PageSetup.FirstPageNumber := xlAutomatic; Sheet.PageSetup.BlackAndWhite := false; //窪啞詨 Sheet.PageSetup.Zoom := 100; //窺溫 sheet.PrintPreView; //蹈荂蕼罜 except Showmessage(‘initiale error ㄛnot Excelㄛor other error ˙try again!‘); v.DisplayAlerts := false; v.Quit; // finally exit; end; end; end; end.
【文件预览】:
button5save.exe