学完这个你就成为excel高手了!(Delphi对Excel的所有操作)逐个试试!
Delphi对Excel的所有操作 
Delphi对Excel的所有操作一) 使用动态创建的方法 
Delphi对Excel的所有操作
Delphi对Excel的所有操作首先创建 Excel 对象,使用ComObj: 
Delphi对Excel的所有操作
var ExcelApp: Variant; 
Delphi对Excel的所有操作ExcelApp :
= CreateOleObject( 'Excel.Application' ); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
1) 显示当前窗口: 
Delphi对Excel的所有操作ExcelApp.Visible :
= True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
2) 更改 Excel 标题栏: 
Delphi对Excel的所有操作ExcelApp.Caption :
= '应用程序调用 Microsoft Excel'
Delphi对Excel的所有操作
Delphi对Excel的所有操作
3) 添加新工作簿: 
Delphi对Excel的所有操作ExcelApp.WorkBooks.Add; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
4) 打开已存在的工作簿: 
Delphi对Excel的所有操作ExcelApp.WorkBooks.Open( 
'C:\Excel\Demo.xls' ); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
5) 设置第2个工作表为活动工作表: 
Delphi对Excel的所有操作ExcelApp.WorkSheets[
2].Activate; 
Delphi对Excel的所有操作或 
Delphi对Excel的所有操作ExcelApp.WorksSheets[ 
'Sheet2' ].Activate; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
6) 给单元格赋值: 
Delphi对Excel的所有操作ExcelApp.Cells[
1,4].Value := '第一行第四列'
Delphi对Excel的所有操作
Delphi对Excel的所有操作
7) 设置指定列的宽度(单位:字符个数),以第一列为例: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Columns[
1].ColumnsWidth := 5
Delphi对Excel的所有操作
Delphi对Excel的所有操作
8) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Rows[
2].RowHeight := 1/0.035// 1厘米 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
9) 在第8行之前插入分页符: 
Delphi对Excel的所有操作ExcelApp.WorkSheets[
1].Rows.PageBreak := 1
Delphi对Excel的所有操作
Delphi对Excel的所有操作
10) 在第8列之前删除分页符: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Columns[
4].PageBreak := 0
Delphi对Excel的所有操作
Delphi对Excel的所有操作
11) 指定边框线宽度: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Range[ 
'B3:D4' ].Borders[2].Weight := 3
Delphi对Excel的所有操作
1-左 2-右 3-顶 4-底 5-斜( \ ) 6-斜( / ) 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
12) 清除第一行第四列单元格公式: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Cells[
1,4].ClearContents; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
13) 设置第一行字体属性: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Rows[
1].Font.Name := '隶书'
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Rows[
1].Font.Color := clBlue; 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Rows[
1].Font.Bold := True; 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Rows[
1].Font.UnderLine := True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
14) 进行页面设置: 
Delphi对Excel的所有操作
Delphi对Excel的所有操作a.页眉: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.CenterHeader :
= '报表演示'
Delphi对Excel的所有操作b.页脚: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.CenterFooter :
= '第&P页'
Delphi对Excel的所有操作c.页眉到顶端边距2cm: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.HeaderMargin :
= 2/0.035
Delphi对Excel的所有操作d.页脚到底端边距3cm: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.HeaderMargin :
= 3/0.035
Delphi对Excel的所有操作e.顶边距2cm: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.TopMargin :
= 2/0.035
Delphi对Excel的所有操作f.底边距2cm: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.BottomMargin :
= 2/0.035
Delphi对Excel的所有操作g.左边距2cm: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.LeftMargin :
= 2/0.035
Delphi对Excel的所有操作h.右边距2cm: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.RightMargin :
= 2/0.035
Delphi对Excel的所有操作i.页面水平居中: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.CenterHorizontally :
= 2/0.035
Delphi对Excel的所有操作j.页面垂直居中: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.CenterVertically :
= 2/0.035
Delphi对Excel的所有操作k.打印单元格网线: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PageSetup.PrintGridLines :
= True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
15) 拷贝操作: 
Delphi对Excel的所有操作
Delphi对Excel的所有操作a.拷贝整个工作表: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Used.Range.Copy; 
Delphi对Excel的所有操作b.拷贝指定区域: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Range[ 
'A1:E2' ].Copy; 
Delphi对Excel的所有操作c.从A1位置开始粘贴: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Range.[ 
'A1' ].PasteSpecial; 
Delphi对Excel的所有操作d.从文件尾部开始粘贴: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.Range.PasteSpecial; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
16) 插入一行或一列: 
Delphi对Excel的所有操作a. ExcelApp.ActiveSheet.Rows[
2].Insert; 
Delphi对Excel的所有操作b. ExcelApp.ActiveSheet.Columns[
1].Insert; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
17) 删除一行或一列: 
Delphi对Excel的所有操作a. ExcelApp.ActiveSheet.Rows[
2].Delete; 
Delphi对Excel的所有操作b. ExcelApp.ActiveSheet.Columns[
1].Delete; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
18) 打印预览工作表: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
19) 打印输出工作表: 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PrintOut; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
20) 工作表保存: 
Delphi对Excel的所有操作
if not ExcelApp.ActiveWorkBook.Saved then 
Delphi对Excel的所有操作ExcelApp.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
21) 工作表另存为: 
Delphi对Excel的所有操作ExcelApp.SaveAs( 
'C:\Excel\Demo1.xls' ); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
22) 放弃存盘: 
Delphi对Excel的所有操作ExcelApp.ActiveWorkBook.Saved :
= True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
23) 关闭工作簿: 
Delphi对Excel的所有操作ExcelApp.WorkBooks.Close; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
24) 退出 Excel: 
Delphi对Excel的所有操作ExcelApp.Quit; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作(二) 使用Delphi 控件方法 
Delphi对Excel的所有操作在Form中分别放入ExcelApplication, ExcelWorkbook和ExcelWorksheet。 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
1) 打开Excel 
Delphi对Excel的所有操作ExcelApplication1.Connect; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
2) 显示当前窗口: 
Delphi对Excel的所有操作ExcelApplication1.Visible[
0]:=True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
3) 更改 Excel 标题栏: 
Delphi对Excel的所有操作ExcelApplication1.Caption :
= '应用程序调用 Microsoft Excel'
Delphi对Excel的所有操作
Delphi对Excel的所有操作
4) 添加新工作簿: 
Delphi对Excel的所有操作ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,
0)); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
5) 添加新工作表: 
Delphi对Excel的所有操作
var Temp_Worksheet: _WorkSheet; 
Delphi对Excel的所有操作
begin 
Delphi对Excel的所有操作Temp_Worksheet:
=ExcelWorkbook1. 
Delphi对Excel的所有操作WorkSheets.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,
0) as _WorkSheet; 
Delphi对Excel的所有操作ExcelWorkSheet1.ConnectTo(Temp_WorkSheet); 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
6) 打开已存在的工作簿: 
Delphi对Excel的所有操作ExcelApplication1.Workbooks.Open (c:\a.xls 
Delphi对Excel的所有操作EmptyParam,EmptyParam,EmptyParam,EmptyParam, 
Delphi对Excel的所有操作EmptyParam,EmptyParam,EmptyParam,EmptyParam, 
Delphi对Excel的所有操作EmptyParam,EmptyParam,EmptyParam,EmptyParam,
0
Delphi对Excel的所有操作
Delphi对Excel的所有操作
7) 设置第2个工作表为活动工作表: 
Delphi对Excel的所有操作ExcelApplication1.WorkSheets[
2].Activate; 或 
Delphi对Excel的所有操作ExcelApplication1.WorksSheets[ 
'Sheet2' ].Activate; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
8) 给单元格赋值: 
Delphi对Excel的所有操作ExcelApplication1.Cells[
1,4].Value := '第一行第四列'
Delphi对Excel的所有操作
Delphi对Excel的所有操作
9) 设置指定列的宽度(单位:字符个数),以第一列为例: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Columns[
1].ColumnsWidth := 5
Delphi对Excel的所有操作
Delphi对Excel的所有操作
10) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Rows[
2].RowHeight := 1/0.035// 1厘米 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
11) 在第8行之前插入分页符: 
Delphi对Excel的所有操作ExcelApplication1.WorkSheets[
1].Rows.PageBreak := 1
Delphi对Excel的所有操作
Delphi对Excel的所有操作
12) 在第8列之前删除分页符: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Columns[
4].PageBreak := 0
Delphi对Excel的所有操作
Delphi对Excel的所有操作
13) 指定边框线宽度: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Range[ 
'B3:D4' ].Borders[2].Weight := 3
Delphi对Excel的所有操作
1-左 2-右 3-顶 4-底 5-斜( \ ) 6-斜( / ) 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
14) 清除第一行第四列单元格公式: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Cells[
1,4].ClearContents; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
15) 设置第一行字体属性: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Rows[
1].Font.Name := '隶书'
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Rows[
1].Font.Color := clBlue; 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Rows[
1].Font.Bold := True; 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.Rows[
1].Font.UnderLine := True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
16) 进行页面设置: 
Delphi对Excel的所有操作a.页眉: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.CenterHeader :
= '报表演示'
Delphi对Excel的所有操作b.页脚: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.CenterFooter :
= '第&P页'
Delphi对Excel的所有操作c.页眉到顶端边距2cm: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.HeaderMargin :
= 2/0.035
Delphi对Excel的所有操作d.页脚到底端边距3cm: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.HeaderMargin :
= 3/0.035
Delphi对Excel的所有操作e.顶边距2cm: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.TopMargin :
= 2/0.035
Delphi对Excel的所有操作f.底边距2cm: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.BottomMargin :
= 2/0.035
Delphi对Excel的所有操作g.左边距2cm: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.LeftMargin :
= 2/0.035
Delphi对Excel的所有操作h.右边距2cm: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.RightMargin :
= 2/0.035
Delphi对Excel的所有操作i.页面水平居中: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.CenterHorizontally :
= 2/0.035
Delphi对Excel的所有操作j.页面垂直居中: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.CenterVertically :
= 2/0.035
Delphi对Excel的所有操作k.打印单元格网线: 
Delphi对Excel的所有操作ExcelApplication1.ActiveSheet.PageSetup.PrintGridLines :
= True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
17) 拷贝操作: 
Delphi对Excel的所有操作
Delphi对Excel的所有操作a.拷贝整个工作表: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveSheet.Used.Range.Copy; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作b.拷贝指定区域: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveSheet.Range[ 
'A1:E2' ].Copy; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作c.从A1位置开始粘贴: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveSheet.Range.[ 
'A1' ].PasteSpecial; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作d.从文件尾部开始粘贴: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveSheet.Range.PasteSpecial; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
18) 插入一行或一列: 
Delphi对Excel的所有操作a. ExcelApplication1.ActiveSheet.Rows[
2].Insert; 
Delphi对Excel的所有操作b. ExcelApplication1.ActiveSheet.Columns[
1].Insert; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
19) 删除一行或一列: 
Delphi对Excel的所有操作a. ExcelApplication1.ActiveSheet.Rows[
2].Delete; 
Delphi对Excel的所有操作b. ExcelApplication1.ActiveSheet.Columns[
1].Delete; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
20) 打印预览工作表: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
21) 打印输出工作表: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveSheet.PrintOut; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
22) 工作表保存: 
Delphi对Excel的所有操作 
if not ExcelApplication1.ActiveWorkBook.Saved then 
Delphi对Excel的所有操作    ExcelApplication1.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
23) 工作表另存为: 
Delphi对Excel的所有操作 ExcelApplication1.SaveAs( 
'C:\Excel\Demo1.xls' ); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
24) 放弃存盘: 
Delphi对Excel的所有操作 ExcelApplication1.ActiveWorkBook.Saved :
= True; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
25) 关闭工作簿: 
Delphi对Excel的所有操作 ExcelApplication1.WorkBooks.Close; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
26) 退出 Excel: 
Delphi对Excel的所有操作 ExcelApplication1.Quit; 
Delphi对Excel的所有操作 ExcelApplication1.Disconnect; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作(三) 使用Delphi 控制Excle二维图 
Delphi对Excel的所有操作在Form中分别放入ExcelApplication, ExcelWorkbook和ExcelWorksheet 
Delphi对Excel的所有操作
var asheet1,achart, range:variant; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
1)选择当第一个工作薄第一个工作表 
Delphi对Excel的所有操作asheet1:
=ExcelApplication1.Workbooks[1].Worksheets[1]; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
2)增加一个二维图 
Delphi对Excel的所有操作achart:
=asheet1.chartobjects.add(100,100,200,200); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
3)选择二维图的形态 
Delphi对Excel的所有操作achart.chart.charttype:
=4
Delphi对Excel的所有操作
Delphi对Excel的所有操作
4)给二维图赋值 
Delphi对Excel的所有操作series:
=achart.chart.seriescollection; 
Delphi对Excel的所有操作range:
=sheet1!r2c3:r3c9; 
Delphi对Excel的所有操作series.add(range,true); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
5)加上二维图的标题 
Delphi对Excel的所有操作achart.Chart.HasTitle:
=True; 
Delphi对Excel的所有操作achart.Chart.ChartTitle.Characters.Text:
=’ Excle二维图’ 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作学完这个你就成为excel高手了!^&^ 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作下面,以Delphi为例,说明这种调用方法。 
Delphi对Excel的所有操作Unit excel; 
Delphi对Excel的所有操作Interface 
Delphi对Excel的所有操作Uses 
Delphi对Excel的所有操作Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,ComObj, 
Delphi对Excel的所有操作
{ ComObj是操作OLE对象的函数集} 
Delphi对Excel的所有操作Type 
Delphi对Excel的所有操作TForm1
=class(TForm) 
Delphi对Excel的所有操作Button1:TButton; 
Delphi对Excel的所有操作Procedure Button1Click(Sender:Tobject); 
Delphi对Excel的所有操作Private 
Delphi对Excel的所有操作
{ Private declaration} 
Delphi对Excel的所有操作Public 
Delphi对Excel的所有操作
{ Public declaration } 
Delphi对Excel的所有操作
end
Delphi对Excel的所有操作
var 
Delphi对Excel的所有操作Form1:Tform1; 
Delphi对Excel的所有操作Implementation 
Delphi对Excel的所有操作
{$R *.DFM} 
Delphi对Excel的所有操作
procedure TForm1.Button1Click(sender:Tobject); 
Delphi对Excel的所有操作
var 
Delphi对Excel的所有操作eclApp,WordBook:Variant; 
{声明为OLE Automation对象} 
Delphi对Excel的所有操作xlsFileName:string; 
Delphi对Excel的所有操作
begin 
Delphi对Excel的所有操作xlsFileName:
=’ex.xls’; 
Delphi对Excel的所有操作try 
Delphi对Excel的所有操作
{创建OLE对象:Excel Application与WordBook} 
Delphi对Excel的所有操作eclApp:
=CreateOleObject(‘Excel.Application’); 
Delphi对Excel的所有操作WorkBook:
=CreateOleObject(Excel.Sheet’); 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作Application.MessageBox(‘你的机器没有安装Microsoft Excel’, 
Delphi对Excel的所有操作’使用Microsoft Excel’,MB_OK
+MB_ICONWarning); 
Delphi对Excel的所有操作Exit; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作ShowMessage(‘下面演示:新建一个XLS文件,并写入数据,并关闭它。’); 
Delphi对Excel的所有操作WorkBook:
=eclApp.workbooks.Add; 
Delphi对Excel的所有操作EclApp.Cells(
1,1):=’字符型’; 
Delphi对Excel的所有操作EclApp.Cells(
2,1):=’Excel文件’; 
Delphi对Excel的所有操作EclApp.Cells(
1,2):=’Money’; 
Delphi对Excel的所有操作EclApp.Cells(
2,2):=10.01
Delphi对Excel的所有操作EclApp.Cells(
1,3):=’日期型’; 
Delphi对Excel的所有操作EclApp.Cells(
2,3):=Date; 
Delphi对Excel的所有操作WorkBook.SaveAS(xlsFileName); 
Delphi对Excel的所有操作WorkBook.close; 
Delphi对Excel的所有操作ShowMessage(‘下面演示:打开刚创建的XLS文件,并修改其中的内容,然后,由用户决定是否保存。’); 
Delphi对Excel的所有操作Workbook:
=eclApp.WorkBooks.Open(xlsFileName); 
Delphi对Excel的所有操作EclApp.Cells(
1,4):=’Excel文件类型’; 
Delphi对Excel的所有操作If MessageDlg(xlsFileName
+’已经被修改,是否保存?’, 
Delphi对Excel的所有操作mtConfirmation,[mbYes,mbNo],
0)=mrYes then 
Delphi对Excel的所有操作WorkBook.Save 
Delphi对Excel的所有操作Else 
Delphi对Excel的所有操作WorkBook.Saved:
=True; {放弃保存} 
Delphi对Excel的所有操作Workbook.Close; 
Delphi对Excel的所有操作EclApp.Quit; 
//退出Excel Application 
Delphi对Excel的所有操作
{释放Variant变量} 
Delphi对Excel的所有操作eclApp:
=Unassigned; 
Delphi对Excel的所有操作except 
Delphi对Excel的所有操作showMessage(‘不能正确操作Excel文件。可能是该文件已被其他程序打开,或系统错误。’); 
Delphi对Excel的所有操作WorkBook.close; 
Delphi对Excel的所有操作EclApp.Quit; 
Delphi对Excel的所有操作
{释放Variant变量} 
Delphi对Excel的所有操作eclApp:
=Unassigned; 
Delphi对Excel的所有操作
end
Delphi对Excel的所有操作
end
Delphi对Excel的所有操作
end 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作
-------------------------------------------- 
Delphi对Excel的所有操作
Delphi对Excel的所有操作一个操作Excel的单元     
Delphi对Excel的所有操作这里给出一个Excel的操作单元,函概了部分常用Excel操作,不是我写的,是从Experts
-Exchange 
Delphi对Excel的所有操作看到后收藏起来的,给大家参考。 
Delphi对Excel的所有操作
// 该文件操作单元封装了大部分的Excel操作 
Delphi对Excel的所有操作
// use to manipulate Excel xls File 
Delphi对Excel的所有操作
// Dragon P.C. <2000.05.10> 
Delphi对Excel的所有操作unit ExcelUnit; 
Delphi对Excel的所有操作interface 
Delphi对Excel的所有操作uses 
Delphi对Excel的所有操作Dialogs, Messages, SysUtils, Grids, Cmp_Sec, ComObj, Ads_Misc; 
Delphi对Excel的所有操作
{!~Add a blank WorkSheet} 
Delphi对Excel的所有操作Function ExcelAddWorkSheet(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Close Excel} 
Delphi对Excel的所有操作Function ExcelClose(Excel : Variant; SaveAll: Boolean): Boolean; 
Delphi对Excel的所有操作
{!~Returns the Column String Value from its integer equilavent.} 
Delphi对Excel的所有操作Function ExcelColIntToStr(ColNum: Integer): ShortString; 
Delphi对Excel的所有操作
{!~Returns the Column Integer Value from its Alpha equilavent.} 
Delphi对Excel的所有操作Function ExcelColStrToInt(ColStr: ShortString): Integer; 
Delphi对Excel的所有操作
{!~Close All Workbooks. All workbooks can be saved or not.} 
Delphi对Excel的所有操作Function ExcelCloseWorkBooks(Excel : Variant; SaveAll: Boolean): Boolean; 
Delphi对Excel的所有操作
{!~Copies a range of Excel Cells to a Delphi StringGrid. If successful 
Delphi对Excel的所有操作True is returned, False otherwise. If SizeStringGridToFit is True 
Delphi对Excel的所有操作then the StringGrid is resized to be exactly the correct dimensions to 
Delphi对Excel的所有操作receive the input Excel cells, otherwise the StringGrid is not resized. 
Delphi对Excel的所有操作If ClearStringGridFirst is true then any cells outside the input range 
Delphi对Excel的所有操作are cleared, otherwise existing values are retained. Please not that the 
Delphi对Excel的所有操作Excel cell coordinates are "1" based and the Delphi StringGrid coordinates 
Delphi对Excel的所有操作are zero based.
} 
Delphi对Excel的所有操作Function ExcelCopyToStringGrid( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作ExcelFirstRow : Integer; 
Delphi对Excel的所有操作ExcelFirstCol : Integer; 
Delphi对Excel的所有操作ExcelLastRow : Integer; 
Delphi对Excel的所有操作ExcelLastCol : Integer; 
Delphi对Excel的所有操作StringGrid : TStringGrid; 
Delphi对Excel的所有操作StringGridFirstRow : Integer; 
Delphi对Excel的所有操作StringGridFirstCol : Integer; 
Delphi对Excel的所有操作
{Make the StringGrid the same size as the input range} 
Delphi对Excel的所有操作SizeStringGridToFit : Boolean; 
Delphi对Excel的所有操作
{cells outside input range in StringGrid are cleared} 
Delphi对Excel的所有操作ClearStringGridFirst : Boolean 
Delphi对Excel的所有操作): Boolean; 
Delphi对Excel的所有操作
{!~Delete a WorkSheet by Name} 
Delphi对Excel的所有操作Function ExcelDeleteWorkSheet( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作SheetName : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Moves the cursor to the last row and column} 
Delphi对Excel的所有操作Function ExcelEnd(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Finds A value and moves the cursor there. 
Delphi对Excel的所有操作If the value is not found then the cursor does not move. 
Delphi对Excel的所有操作If nothing is found then false is returned, True otherwise.
} 
Delphi对Excel的所有操作Function ExcelFind( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FindString : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Finds A value in a range and moves the cursor there. 
Delphi对Excel的所有操作If the value is not found then the cursor does not move. 
Delphi对Excel的所有操作If nothing is found then false is returned, True otherwise.
} 
Delphi对Excel的所有操作Function ExcelFindInRange( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FindString : ShortString; 
Delphi对Excel的所有操作TopRow : Integer; 
Delphi对Excel的所有操作LeftCol : Integer; 
Delphi对Excel的所有操作LastRow : Integer; 
Delphi对Excel的所有操作LastCol : Integer): Boolean; 
Delphi对Excel的所有操作
{!~Finds A value in a range and moves the cursor there. If the value is 
Delphi对Excel的所有操作not found then the cursor does not move. If nothing is found then 
Delphi对Excel的所有操作false is returned, True otherwise. The search directions can be defined. 
Delphi对Excel的所有操作If you want row searches to go from left to right then SearchRight should 
Delphi对Excel的所有操作be set to true, False otherwise. If you want column searches to go from 
Delphi对Excel的所有操作top to bottom then SearchDown should be set to true, false otherwise. 
Delphi对Excel的所有操作If RowsFirst is set to true then all the columns in a complete row will be 
Delphi对Excel的所有操作searched.
} 
Delphi对Excel的所有操作Function ExcelFindValue( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FindString : ShortString; 
Delphi对Excel的所有操作TopRow : Integer; 
Delphi对Excel的所有操作LeftCol : Integer; 
Delphi对Excel的所有操作LastRow : Integer; 
Delphi对Excel的所有操作LastCol : Integer; 
Delphi对Excel的所有操作SearchRight : Boolean; 
Delphi对Excel的所有操作SearchDown : Boolean; 
Delphi对Excel的所有操作RowsFirst : Boolean 
Delphi对Excel的所有操作): Boolean; 
Delphi对Excel的所有操作
{!~Returns The First Col} 
Delphi对Excel的所有操作Function ExcelFirstCol(Excel : Variant): Integer; 
Delphi对Excel的所有操作
{!~Returns The First Row} 
Delphi对Excel的所有操作Function ExcelFirstRow(Excel : Variant): Integer; 
Delphi对Excel的所有操作
{!~Returns the name of the currently active worksheet 
Delphi对Excel的所有操作as a shortstring
} 
Delphi对Excel的所有操作Function ExcelGetActiveSheetName(Excel : Variant): ShortString; 
Delphi对Excel的所有操作
{!~Gets the formula in a cell.} 
Delphi对Excel的所有操作Function ExcelGetCellFormula( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作RowNum, ColNum: Integer): ShortString; 
Delphi对Excel的所有操作
{!~Returns the contents of a cell as a shortstring} 
Delphi对Excel的所有操作Function ExcelGetCellValue(Excel : Variant; RowNum, ColNum: Integer): ShortString; 
Delphi对Excel的所有操作
{!~Returns the the current column} 
Delphi对Excel的所有操作Function ExcelGetCol(Excel : Variant): Integer; 
Delphi对Excel的所有操作
{!~Returns the the current row} 
Delphi对Excel的所有操作Function ExcelGetRow(Excel : Variant): Integer; 
Delphi对Excel的所有操作
{!~Moves the cursor to the last column} 
Delphi对Excel的所有操作Function ExcelGoToLastCol(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Moves the cursor to the last row} 
Delphi对Excel的所有操作Function ExcelGoToLastRow(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Moves the cursor to the Leftmost Column} 
Delphi对Excel的所有操作Function ExcelGoToLeftmostCol(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Moves the cursor to the Top row} 
Delphi对Excel的所有操作Function ExcelGoToTopRow(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Moves the cursor to Home position, i.e., A1} 
Delphi对Excel的所有操作Function ExcelHome(Excel : Variant): Boolean; 
Delphi对Excel的所有操作
{!~Returns The Last Column} 
Delphi对Excel的所有操作Function ExcelLastCol(Excel : Variant): Integer; 
Delphi对Excel的所有操作
{!~Returns The Last Row} 
Delphi对Excel的所有操作Function ExcelLastRow(Excel : Variant): Integer; 
Delphi对Excel的所有操作
{!~Open the file you want to work within Excel. If you want to 
Delphi对Excel的所有操作take advantage of optional parameters then you should use 
Delphi对Excel的所有操作ExcelOpenFileComplex
} 
Delphi对Excel的所有操作Function ExcelOpenFile(Excel : Variant; FileName : String): Boolean; 
Delphi对Excel的所有操作
{!~Open the file you want to work within Excel. If you want to 
Delphi对Excel的所有操作take advantage of optional parameters then you should use 
Delphi对Excel的所有操作ExcelOpenFileComplex
} 
Delphi对Excel的所有操作Function ExcelOpenFileComplex( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FileName : String; 
Delphi对Excel的所有操作UpdateLinks : Integer; 
Delphi对Excel的所有操作ReadOnly : Boolean; 
Delphi对Excel的所有操作Format : Integer; 
Delphi对Excel的所有操作Password : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Saves the range on the currently active sheet 
Delphi对Excel的所有操作to to values only.
} 
Delphi对Excel的所有操作Function ExcelPasteValuesOnly( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作ExcelFirstRow : Integer; 
Delphi对Excel的所有操作ExcelFirstCol : Integer; 
Delphi对Excel的所有操作ExcelLastRow : Integer; 
Delphi对Excel的所有操作ExcelLastCol : Integer): Boolean; 
Delphi对Excel的所有操作
{!~Renames a worksheet.} 
Delphi对Excel的所有操作Function ExcelRenameSheet( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作OldName : ShortString; 
Delphi对Excel的所有操作NewName : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Saves the range on the currently active sheet 
Delphi对Excel的所有操作to a DBase 4 table.
} 
Delphi对Excel的所有操作Function ExcelSaveAsDBase4( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作ExcelFirstRow : Integer; 
Delphi对Excel的所有操作ExcelFirstCol : Integer; 
Delphi对Excel的所有操作ExcelLastRow : Integer; 
Delphi对Excel的所有操作ExcelLastCol : Integer; 
Delphi对Excel的所有操作OutFilePath : ShortString; 
Delphi对Excel的所有操作OutFileName : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Saves the range on the currently active sheet 
Delphi对Excel的所有操作to a text file.
} 
Delphi对Excel的所有操作Function ExcelSaveAsText( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作ExcelFirstRow : Integer; 
Delphi对Excel的所有操作ExcelFirstCol : Integer; 
Delphi对Excel的所有操作ExcelLastRow : Integer; 
Delphi对Excel的所有操作ExcelLastCol : Integer; 
Delphi对Excel的所有操作OutFilePath : ShortString; 
Delphi对Excel的所有操作OutFileName : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Selects a range on the currently active sheet. From the 
Delphi对Excel的所有操作current cursor position a block is selected down and to the right. 
Delphi对Excel的所有操作The block proceeds down until an empty row is encountered. The 
Delphi对Excel的所有操作block proceeds right until an empty column is encountered.
} 
Delphi对Excel的所有操作Function ExcelSelectBlock( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FirstRow : Integer; 
Delphi对Excel的所有操作FirstCol : Integer): Boolean; 
Delphi对Excel的所有操作
{!~Selects a range on the currently active sheet. From the 
Delphi对Excel的所有操作current cursor position a block is selected that contains 
Delphi对Excel的所有操作the currently active cell. The block proceeds in each 
Delphi对Excel的所有操作direction until an empty row or column is encountered.
} 
Delphi对Excel的所有操作Function ExcelSelectBlockWhole(Excel: Variant): Boolean; 
Delphi对Excel的所有操作
{!~Selects a cell on the currently active sheet} 
Delphi对Excel的所有操作Function ExcelSelectCell(Excel : Variant; RowNum, ColNum: Integer): Boolean; 
Delphi对Excel的所有操作
{!~Selects a range on the currently active sheet} 
Delphi对Excel的所有操作Function ExcelSelectRange( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FirstRow : Integer; 
Delphi对Excel的所有操作FirstCol : Integer; 
Delphi对Excel的所有操作LastRow : Integer; 
Delphi对Excel的所有操作LastCol : Integer): Boolean; 
Delphi对Excel的所有操作
{!~Selects an Excel Sheet By Name} 
Delphi对Excel的所有操作Function ExcelSelectSheetByName(Excel : Variant; SheetName: String): Boolean; 
Delphi对Excel的所有操作
{!~Sets the formula in a cell. Remember to include the equals sign "=". 
Delphi对Excel的所有操作If the function fails False is returned, True otherwise.
} 
Delphi对Excel的所有操作Function ExcelSetCellFormula( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作FormulaString : ShortString; 
Delphi对Excel的所有操作RowNum, ColNum: Integer): Boolean; 
Delphi对Excel的所有操作
{!~Sets the contents of a cell as a shortstring} 
Delphi对Excel的所有操作Function ExcelSetCellValue( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作RowNum, ColNum: Integer; 
Delphi对Excel的所有操作Value : ShortString): Boolean; 
Delphi对Excel的所有操作
{!~Sets a Column Width on the currently active sheet} 
Delphi对Excel的所有操作Function ExcelSetColumnWidth( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作ColNum : Integer; 
Delphi对Excel的所有操作ColumnWidth: Integer): Boolean; 
Delphi对Excel的所有操作
{!~Set Excel Visibility} 
Delphi对Excel的所有操作Function ExcelSetVisible( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作IsVisible: Boolean): Boolean; 
Delphi对Excel的所有操作
{!~Saves the range on the currently active sheet 
Delphi对Excel的所有操作to values only.
} 
Delphi对Excel的所有操作Function ExcelValuesOnly( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作ExcelFirstRow : Integer; 
Delphi对Excel的所有操作ExcelFirstCol : Integer; 
Delphi对Excel的所有操作ExcelLastRow : Integer; 
Delphi对Excel的所有操作ExcelLastCol : Integer): Boolean; 
Delphi对Excel的所有操作
{!~Returns the Excel Version as a ShortString.} 
Delphi对Excel的所有操作Function ExcelVersion(Excel: Variant): ShortString; 
Delphi对Excel的所有操作Function IsBlockColSide( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作RowNum: Integer; 
Delphi对Excel的所有操作ColNum: Integer): Boolean; Forward; 
Delphi对Excel的所有操作unction IsBlockRowSide( 
Delphi对Excel的所有操作Excel : Variant; 
Delphi对Excel的所有操作RowNum: Integer; 
Delphi对Excel的所有操作ColNum: Integer): Boolean; Forward; 
Delphi对Excel的所有操作  
Delphi对Excel的所有操作implementation 
Delphi对Excel的所有操作  
Delphi对Excel的所有操作
Delphi对Excel的所有操作
type 
Delphi对Excel的所有操作
//Declare the constants used by Excel 
Delphi对Excel的所有操作SourceType 
= (xlConsolidation, xlDatabase, xlExternal, xlPivotTable); 
Delphi对Excel的所有操作Orientation 
= (xlHidden, xlRowField, xlColumnField, xlPageField, xlDataField); 
Delphi对Excel的所有操作RangeEnd 
= (NoValue, xlToLeft, xlToRight, xlUp, xlDown); 
Delphi对Excel的所有操作ExcelPasteType 
= (xlAllExceptBorders,xlNotes,xlFormats,xlValues,xlFormulas,xlAll); 
Delphi对Excel的所有操作
{CAUTION!!! THESE OUTPUTS ARE ALL GARBLED! YOU SELECT xlDBF3 AND EXCEL 
Delphi对Excel的所有操作OUTPUTS A xlCSV.
} 
Delphi对Excel的所有操作FileFormat 
= (xlAddIn, xlCSV, xlCSVMac, xlCSVMSDOS, xlCSVWindows, xlDBF2, 
Delphi对Excel的所有操作xlDBF3, xlDBF4, xlDIF, xlExcel2, xlExcel3, xlExcel4, 
Delphi对Excel的所有操作xlExcel4Workbook, xlIntlAddIn, xlIntlMacro, xlNormal, 
Delphi对Excel的所有操作xlSYLK, xlTemplate, xlText, xlTextMac, xlTextMSDOS, 
Delphi对Excel的所有操作xlTextWindows, xlTextPrinter, xlWK1, xlWK3, xlWKS, 
Delphi对Excel的所有操作xlWQ1, xlWK3FM3, xlWK1FMT, xlWK1ALL); 
Delphi对Excel的所有操作
{Add a blank WorkSheet} 
Delphi对Excel的所有操作Function ExcelAddWorkSheet(Excel : Variant): Boolean; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= True; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作Excel.Worksheets.Add; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作MessageDlg(
'Unable to add a new worksheet', mtError, [mbOK], 0); 
Delphi对Excel的所有操作Result :
= False; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Sets Excel Visibility} 
Delphi对Excel的所有操作Function ExcelSetVisible(Excel : Variant;IsVisible: Boolean): Boolean; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= True; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作Excel.Visible :
= IsVisible; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作MessageDlg(
'Unable to Excel Visibility', mtError, [mbOK], 0); 
Delphi对Excel的所有操作Result :
= False; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Close Excel} 
Delphi对Excel的所有操作Function ExcelClose(Excel : Variant; SaveAll: Boolean): Boolean; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= True; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作ExcelCloseWorkBooks(Excel, SaveAll); 
Delphi对Excel的所有操作Excel.Quit; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作MessageDlg(
'Unable to Close Excel', mtError, [mbOK], 0); 
Delphi对Excel的所有操作Result :
= False; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Close All Workbooks. All workbooks can be saved or not.} 
Delphi对Excel的所有操作Function ExcelCloseWorkBooks(Excel : Variant; SaveAll: Boolean): Boolean; 
Delphi对Excel的所有操作
var 
Delphi对Excel的所有操作loop: byte; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= True; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作For loop :
= 1 to Excel.Workbooks.Count Do 
Delphi对Excel的所有操作Excel.Workbooks[
1].Close[SaveAll]; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作Result :
= False; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Selects an Excel Sheet By Name} 
Delphi对Excel的所有操作Function ExcelSelectSheetByName(Excel : Variant; SheetName: String): Boolean; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= True; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作Excel.Sheets[SheetName].Select; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作Result :
= False; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Selects a cell on the currently active sheet} 
Delphi对Excel的所有操作Function ExcelSelectCell(Excel : Variant; RowNum, ColNum: Integer): Boolean; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= True; 
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作Excel.ActiveSheet.Cells[RowNum, ColNum].Select; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作Result :
= False; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Returns the contents of a cell as a shortstring} 
Delphi对Excel的所有操作Function ExcelGetCellValue(Excel : Variant; RowNum, ColNum: Integer): ShortString; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= ''
Delphi对Excel的所有操作Try 
Delphi对Excel的所有操作Result :
= Excel.Cells[RowNum, ColNum].Value; 
Delphi对Excel的所有操作Except 
Delphi对Excel的所有操作Result :
= ''
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作End; 
Delphi对Excel的所有操作
{Returns the the current row} 
Delphi对Excel的所有操作Function ExcelGetRow(Excel : Variant): Integer; 
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作Result :
= 1
Delphi对Excel的所有操作
Delphi对Excel的所有操作 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作(一) 使用动态创建的方法 
Delphi对Excel的所有操作首先创建 Excel 对象,使用ComObj: 
Delphi对Excel的所有操作  
var ExcelApp: Variant; 
Delphi对Excel的所有操作  ExcelApp :
= CreateOleObject( 'Excel.Application' ); 
Delphi对Excel的所有操作
1) 显示当前窗口: 
Delphi对Excel的所有操作  ExcelApp.Visible :
= True; 
Delphi对Excel的所有操作
2) 更改 Excel 标题栏: 
Delphi对Excel的所有操作  ExcelApp.Caption :
= '应用程序调用 Microsoft Excel'
Delphi对Excel的所有操作
3) 添加新工作簿: 
Delphi对Excel的所有操作  ExcelApp.WorkBooks.Add; 
Delphi对Excel的所有操作
4) 打开已存在的工作簿: 
Delphi对Excel的所有操作  ExcelApp.WorkBooks.Open( 
'C:\Excel\Demo.xls' ); 
Delphi对Excel的所有操作
5) 设置第2个工作表为活动工作表: 
Delphi对Excel的所有操作  ExcelApp.WorkSheets[
2].Activate;  或 
Delphi对Excel的所有操作  ExcelApp.WorksSheets[ 
'Sheet2' ].Activate; 
Delphi对Excel的所有操作
6) 给单元格赋值: 
Delphi对Excel的所有操作  ExcelApp.Cells[
1,4].Value := '第一行第四列'
Delphi对Excel的所有操作
7) 设置指定列的宽度(单位:字符个数),以第一列为例: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Columns[
1].ColumnsWidth := 5
Delphi对Excel的所有操作
8) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Rows[
2].RowHeight := 1/0.035// 1厘米 
Delphi对Excel的所有操作
9) 在第8行之前插入分页符: 
Delphi对Excel的所有操作  ExcelApp.WorkSheets[
1].Rows[8].PageBreak := 1
Delphi对Excel的所有操作
10) 在第8列之前删除分页符: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Columns[
4].PageBreak := 0
Delphi对Excel的所有操作
11) 指定边框线宽度: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Range[ 
'B3:D4' ].Borders[2].Weight := 3
Delphi对Excel的所有操作  
1-左    2-右   3-顶    4-底   5-斜( \ )     6-斜( / ) 
Delphi对Excel的所有操作
12) 清除第一行第四列单元格公式: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Cells[
1,4].ClearContents; 
Delphi对Excel的所有操作
13) 设置第一行字体属性: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Rows[
1].Font.Name := '隶书'
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Rows[
1].Font.Color  := clBlue; 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Rows[
1].Font.Bold   := True; 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Rows[
1].Font.UnderLine := True; 
Delphi对Excel的所有操作
14) 进行页面设置: 
Delphi对Excel的所有操作a.页眉: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.CenterHeader :
= '报表演示'
Delphi对Excel的所有操作b.页脚: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.CenterFooter :
= '第&P页'
Delphi对Excel的所有操作c.页眉到顶端边距2cm: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.HeaderMargin :
= 2/0.035
Delphi对Excel的所有操作d.页脚到底端边距3cm: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.HeaderMargin :
= 3/0.035
Delphi对Excel的所有操作e.顶边距2cm: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.TopMargin :
= 2/0.035
Delphi对Excel的所有操作f.底边距2cm: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.BottomMargin :
= 2/0.035
Delphi对Excel的所有操作g.左边距2cm: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.LeftMargin :
= 2/0.035
Delphi对Excel的所有操作h.右边距2cm: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.RightMargin :
= 2/0.035
Delphi对Excel的所有操作i.页面水平居中: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.CenterHorizontally :
= 2/0.035
Delphi对Excel的所有操作j.页面垂直居中: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.CenterVertically :
= 2/0.035
Delphi对Excel的所有操作k.打印单元格网线: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PageSetup.PrintGridLines :
= True; 
Delphi对Excel的所有操作
15) 拷贝操作: 
Delphi对Excel的所有操作a.拷贝整个工作表: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Used.Range.Copy; 
Delphi对Excel的所有操作b.拷贝指定区域: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Range[ 
'A1:E2' ].Copy; 
Delphi对Excel的所有操作c.从A1位置开始粘贴: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Range.[ 
'A1' ].PasteSpecial; 
Delphi对Excel的所有操作d.从文件尾部开始粘贴: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.Range.PasteSpecial; 
Delphi对Excel的所有操作
16) 插入一行或一列: 
Delphi对Excel的所有操作a. ExcelApp.ActiveSheet.Rows[
2].Insert; 
Delphi对Excel的所有操作b. ExcelApp.ActiveSheet.Columns[
1].Insert; 
Delphi对Excel的所有操作
17) 删除一行或一列: 
Delphi对Excel的所有操作a. ExcelApp.ActiveSheet.Rows[
2].Delete; 
Delphi对Excel的所有操作b. ExcelApp.ActiveSheet.Columns[
1].Delete; 
Delphi对Excel的所有操作
18) 打印预览工作表: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
19) 打印输出工作表: 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PrintOut; 
Delphi对Excel的所有操作
20) 工作表保存: 
Delphi对Excel的所有操作  
if not ExcelApp.ActiveWorkBook.Saved then 
Delphi对Excel的所有操作  ExcelApp.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
21) 工作表另存为: 
Delphi对Excel的所有操作  ExcelApp.SaveAs( 
'C:\Excel\Demo1.xls' ); 
Delphi对Excel的所有操作
22) 放弃存盘: 
Delphi对Excel的所有操作  ExcelApp.ActiveWorkBook.Saved :
= True; 
Delphi对Excel的所有操作
23) 关闭工作簿: 
Delphi对Excel的所有操作  ExcelApp.WorkBooks.Close; 
Delphi对Excel的所有操作
24) 退出 Excel: 
Delphi对Excel的所有操作  ExcelApp.Quit; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作(二) 使用Delphi 控件方法 
Delphi对Excel的所有操作  在Form中分别放入ExcelApplication, ExcelWorkbook和ExcelWorksheet。 
Delphi对Excel的所有操作
1)  打开Excel 
Delphi对Excel的所有操作  ExcelApplication1.Connect; 
Delphi对Excel的所有操作
2) 显示当前窗口: 
Delphi对Excel的所有操作  ExcelApplication1.Visible[
0]:=True; 
Delphi对Excel的所有操作
3) 更改 Excel 标题栏: 
Delphi对Excel的所有操作  ExcelApplication1.Caption :
= '应用程序调用 Microsoft Excel'
Delphi对Excel的所有操作
4) 添加新工作簿: 
Delphi对Excel的所有操作  ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,
0)); 
Delphi对Excel的所有操作
5) 添加新工作表: 
Delphi对Excel的所有操作  
var Temp_Worksheet: _WorkSheet; 
Delphi对Excel的所有操作  
begin 
Delphi对Excel的所有操作    Temp_Worksheet:
=ExcelWorkbook1.WorkSheets.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,0) as _WorkSheet; 
Delphi对Excel的所有操作    ExcelWorkSheet1.ConnectTo(Temp_WorkSheet); 
Delphi对Excel的所有操作  End; 
Delphi对Excel的所有操作
6) 打开已存在的工作簿: 
Delphi对Excel的所有操作  ExcelApplication1.Workbooks.Open (c:\a.xls 
Delphi对Excel的所有操作  EmptyParam,EmptyParam,EmptyParam,EmptyParam, 
Delphi对Excel的所有操作  EmptyParam,EmptyParam,EmptyParam,EmptyParam, 
Delphi对Excel的所有操作  EmptyParam,EmptyParam,EmptyParam,EmptyParam,
0
Delphi对Excel的所有操作
7) 设置第2个工作表为活动工作表: 
Delphi对Excel的所有操作  ExcelApplication1.WorkSheets[
2].Activate;  或 
Delphi对Excel的所有操作  ExcelApplication1.WorksSheets[ 
'Sheet2' ].Activate; 
Delphi对Excel的所有操作
8) 给单元格赋值: 
Delphi对Excel的所有操作  ExcelApplication1.Cells[
1,4].Value := '第一行第四列'
Delphi对Excel的所有操作
9) 设置指定列的宽度(单位:字符个数),以第一列为例: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Columns[
1].ColumnsWidth := 5
Delphi对Excel的所有操作
10) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Rows[
2].RowHeight := 1/0.035// 1厘米 
Delphi对Excel的所有操作
11) 在第8行之前插入分页符: 
Delphi对Excel的所有操作  ExcelApplication1.WorkSheets[
1].Rows[8].PageBreak := 1
Delphi对Excel的所有操作
12) 在第8列之前删除分页符: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Columns[
4].PageBreak := 0
Delphi对Excel的所有操作
13) 指定边框线宽度: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Range[ 
'B3:D4' ].Borders[2].Weight := 3
Delphi对Excel的所有操作  
1-左    2-右   3-顶    4-底   5-斜( \ )     6-斜( / ) 
Delphi对Excel的所有操作
14) 清除第一行第四列单元格公式: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Cells[
1,4].ClearContents; 
Delphi对Excel的所有操作
15) 设置第一行字体属性: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Rows[
1].Font.Name := '隶书'
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Rows[
1].Font.Color  := clBlue; 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Rows[
1].Font.Bold   := True; 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Rows[
1].Font.UnderLine := True; 
Delphi对Excel的所有操作
16) 进行页面设置: 
Delphi对Excel的所有操作a.页眉: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.CenterHeader :
= '报表演示'
Delphi对Excel的所有操作b.页脚: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.CenterFooter :
= '第&P页'
Delphi对Excel的所有操作c.页眉到顶端边距2cm: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.HeaderMargin :
= 2/0.035
Delphi对Excel的所有操作d.页脚到底端边距3cm: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.HeaderMargin :
= 3/0.035
Delphi对Excel的所有操作e.顶边距2cm: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.TopMargin :
= 2/0.035
Delphi对Excel的所有操作f.底边距2cm: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.BottomMargin :
= 2/0.035
Delphi对Excel的所有操作g.左边距2cm: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.LeftMargin :
= 2/0.035
Delphi对Excel的所有操作h.右边距2cm: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.RightMargin :
= 2/0.035
Delphi对Excel的所有操作i.页面水平居中: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.CenterHorizontally :
= 2/0.035
Delphi对Excel的所有操作j.页面垂直居中: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.CenterVertically :
= 2/0.035
Delphi对Excel的所有操作k.打印单元格网线: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PageSetup.PrintGridLines :
= True; 
Delphi对Excel的所有操作
17) 拷贝操作: 
Delphi对Excel的所有操作a.拷贝整个工作表: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Used.Range.Copy; 
Delphi对Excel的所有操作b.拷贝指定区域: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Range[ 
'A1:E2' ].Copy; 
Delphi对Excel的所有操作c.从A1位置开始粘贴: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Range.[ 
'A1' ].PasteSpecial; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作d.从文件尾部开始粘贴: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.Range.PasteSpecial; 
Delphi对Excel的所有操作
18) 插入一行或一列: 
Delphi对Excel的所有操作a. ExcelApplication1.ActiveSheet.Rows[
2].Insert; 
Delphi对Excel的所有操作b. ExcelApplication1.ActiveSheet.Columns[
1].Insert; 
Delphi对Excel的所有操作
19) 删除一行或一列: 
Delphi对Excel的所有操作a. ExcelApplication1.ActiveSheet.Rows[
2].Delete; 
Delphi对Excel的所有操作b. ExcelApplication1.ActiveSheet.Columns[
1].Delete; 
Delphi对Excel的所有操作
20) 打印预览工作表: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
21) 打印输出工作表: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveSheet.PrintOut; 
Delphi对Excel的所有操作
22) 工作表保存: 
Delphi对Excel的所有操作  
if not ExcelApplication1.ActiveWorkBook.Saved then 
Delphi对Excel的所有操作    ExcelApplication1.ActiveSheet.PrintPreview; 
Delphi对Excel的所有操作
23) 工作表另存为: 
Delphi对Excel的所有操作  ExcelApplication1.SaveAs( 
'C:\Excel\Demo1.xls' ); 
Delphi对Excel的所有操作
24) 放弃存盘: 
Delphi对Excel的所有操作  ExcelApplication1.ActiveWorkBook.Saved :
= True; 
Delphi对Excel的所有操作
25) 关闭工作簿: 
Delphi对Excel的所有操作  ExcelApplication1.WorkBooks.Close; 
Delphi对Excel的所有操作
26) 退出 Excel: 
Delphi对Excel的所有操作  ExcelApplication1.Quit; 
Delphi对Excel的所有操作  ExcelApplication1.Disconnect; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作(三) 使用Delphi 控制Excle二维图 
Delphi对Excel的所有操作  在Form中分别放入ExcelApplication, ExcelWorkbook和ExcelWorksheet 
Delphi对Excel的所有操作  
var asheet1,achart, range:variant; 
Delphi对Excel的所有操作
1)选择当第一个工作薄第一个工作表 
Delphi对Excel的所有操作  asheet1:
=ExcelApplication1.Workbooks[1].Worksheets[1]; 
Delphi对Excel的所有操作
2)增加一个二维图 
Delphi对Excel的所有操作  achart:
=asheet1.chartobjects.add(100,100,200,200); 
Delphi对Excel的所有操作
3)选择二维图的形态 
Delphi对Excel的所有操作  achart.chart.charttype:
=4
Delphi对Excel的所有操作
4)给二维图赋值 
Delphi对Excel的所有操作  series:
=achart.chart.seriescollection; 
Delphi对Excel的所有操作  range:
=sheet1!r2c3:r3c9; 
Delphi对Excel的所有操作  series.add(range,true); 
Delphi对Excel的所有操作
5)加上二维图的标题 
Delphi对Excel的所有操作  achart.Chart.HasTitle:
=True; 
Delphi对Excel的所有操作  achart.Chart.ChartTitle.Characters.Text:
=’ Excle二维图’           
Delphi对Excel的所有操作
6)改变二维图的标题字体大小 
Delphi对Excel的所有操作  achart.Chart.ChartTitle.Font.size:
=6
Delphi对Excel的所有操作
7)给二维图加下标说明 
Delphi对Excel的所有操作  achart.Chart.Axes(xlCategory, xlPrimary).HasTitle :
= True; 
Delphi对Excel的所有操作  achart.Chart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text :
= '下标说明'
Delphi对Excel的所有操作
8)给二维图加左标说明 
Delphi对Excel的所有操作  achart.Chart.Axes(xlValue, xlPrimary).HasTitle :
= True; 
Delphi对Excel的所有操作  achart.Chart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text :
= '左标说明'
Delphi对Excel的所有操作
9)给二维图加右标说明 
Delphi对Excel的所有操作  achart.Chart.Axes(xlValue, xlSecondary).HasTitle :
= True; 
Delphi对Excel的所有操作  achart.Chart.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text :
= '右标说明'
Delphi对Excel的所有操作
10)改变二维图的显示区大小 
Delphi对Excel的所有操作  achart.Chart.PlotArea.Left :
= 5
Delphi对Excel的所有操作  achart.Chart.PlotArea.Width :
= 223
Delphi对Excel的所有操作  achart.Chart.PlotArea.Height :
= 108
Delphi对Excel的所有操作
11)给二维图坐标轴加上说明 
Delphi对Excel的所有操作  achart.chart.seriescollection[
1].NAME:='坐标轴说明'
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作 提供在DELPHI中用程序实现EXCEL单元格合并的源码
Delphi对Excel的所有操作Begin 
Delphi对Excel的所有操作 CapStr:
=trim(exApp.Cells[Row,1].value); 
Delphi对Excel的所有操作 Col1:
=2
Delphi对Excel的所有操作 Col2:
=FldCount; 
Delphi对Excel的所有操作 For Col1:
=2 to Col2 Do 
Delphi对Excel的所有操作 
begin 
Delphi对Excel的所有操作   NewCapStr:
=trim(exApp.Cells[Row,Col1].value); 
Delphi对Excel的所有操作   
if (NewCapStr=CapStr) then 
Delphi对Excel的所有操作   Begin 
Delphi对Excel的所有操作     Cell1:
=exApp.Cells.Item[Row,Col1-1]; 
Delphi对Excel的所有操作     Cell2:
=exApp.Cells.Item[Row,Col1]; 
Delphi对Excel的所有操作     exApp.Cells[Row,Col1].value:
=''
Delphi对Excel的所有操作     exApp.Range[Cell1,Cell2].Merge(True); 
Delphi对Excel的所有操作   
end 
Delphi对Excel的所有操作   
else 
Delphi对Excel的所有操作   
begin 
Delphi对Excel的所有操作     CapStr:
=NewCapStr; 
Delphi对Excel的所有操作   
end
Delphi对Excel的所有操作 
end
Delphi对Excel的所有操作
end; 
Delphi对Excel的所有操作
Delphi对Excel的所有操作 数据库图片插入到excel中uses:clipbrd 
Delphi对Excel的所有操作
var 
Delphi对Excel的所有操作MyFormat:Word; 
Delphi对Excel的所有操作AData:THandle;      
//临时句柄变量。 
Delphi对Excel的所有操作APalette:HPALETTE;  
//临时变量。 
Delphi对Excel的所有操作Stream1:TMemoryStream;
//TBlobStream 
Delphi对Excel的所有操作xx:tbitmap; 
Delphi对Excel的所有操作         Stream1:
= TMemoryStream.Create; 
Delphi对Excel的所有操作         TBlobField(query.FieldByName(
'存储图片的字段')).SaveToStream(Stream1); 
Delphi对Excel的所有操作         Stream1.Position :
=0
Delphi对Excel的所有操作         xx:
=tbitmap.Create ; 
Delphi对Excel的所有操作         xx.LoadFromStream(Stream1); 
Delphi对Excel的所有操作         xx.SaveToClipboardFormat(MyFormat,AData,APalette); 
Delphi对Excel的所有操作         ClipBoard.SetAsHandle(MyFormat, AData); 
Delphi对Excel的所有操作         myworksheet1.Range[
'g3','h7'].select;//myworksheet1是当前活动的sheet页 
Delphi对Excel的所有操作         myworksheet1.Paste;   
Delphi对Excel的所有操作
Delphi对Excel的所有操作
Delphi对Excel的所有操作 
Delphi对Excel的所有操作 
Delphi对Excel的所有操作程序中写的一个例子,导出库存到Excel中。 
Delphi对Excel的所有操作可参看有关Excel操作部分 
Delphi对Excel的所有操作
Delphi对Excel的所有操作
procedure TfrmExcel.StoreToExcel; 
Delphi对Excel的所有操作
var 
Delphi对Excel的所有操作 data: TADODataSet; 
Delphi对Excel的所有操作 ExcelApp, Ra:Variant; 
Delphi对Excel的所有操作 row: Integer; 
Delphi对Excel的所有操作
begin 
Delphi对Excel的所有操作 
if not InitExcel(ExcelApp) then 
Delphi对Excel的所有操作   exit; 
Delphi对Excel的所有操作 data :
= TADODataSet.Create(nil); 
Delphi对Excel的所有操作 data.Connection :
= ADOConn; 
Delphi对Excel的所有操作 try 
Delphi对Excel的所有操作   data.CommandText :
= 'select * from ProInfo'
Delphi对Excel的所有操作   data.Open; 
Delphi对Excel的所有操作   
with TADODataSet.Create(nildo 
Delphi对Excel的所有操作   
begin 
Delphi对Excel的所有操作     Connection :
= ADOConn; 
Delphi对Excel的所有操作     CommandText :
= 'select ProNO, sum(ProNum) as sNum from AreaProInfo group by ProNO'
Delphi对Excel的所有操作     Open; 
Delphi对Excel的所有操作     row :
= 1
Delphi对Excel的所有操作     ExcelApp.Rows[row].RowHeight :
= 30
Delphi对Excel的所有操作     Ra :
= ExcelApp.Range[ExcelApp.Cells[row, 1], ExcelApp.Cells[row, 7]]; 
Delphi对Excel的所有操作     Ra.font.size :
= 18
Delphi对Excel的所有操作     Ra.font.Bold :
= true; 
Delphi对Excel的所有操作     Ra.MergeCells :
= true; 
Delphi对Excel的所有操作     Ra.HorizontalAlignment :
= xlcenter; 
Delphi对Excel的所有操作     Ra.VerticalAlignment :
= xlcenter; 
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
1] := '部件库存情况表'
Delphi对Excel的所有操作     inc(row); 
Delphi对Excel的所有操作     Ra :
= ExcelApp.Range[ExcelApp.Cells[row, 1], ExcelApp.Cells[row, 7]]; 
Delphi对Excel的所有操作     Ra.font.size :
= 10
Delphi对Excel的所有操作     Ra.HorizontalAlignment :
= xlRight; 
Delphi对Excel的所有操作     Ra.VerticalAlignment :
= xlcenter; 
Delphi对Excel的所有操作     Ra.MergeCells :
= true; 
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
1] := FormatDateTime('yyyy-mm-dd', Now); 
Delphi对Excel的所有操作
Delphi对Excel的所有操作     inc(row); 
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
1] := '部件编号'
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
2] := '部件名称'
Delphi对Excel的所有操作     ExcelApp.Columns[
2].ColumnWidth := 15
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
3] := '单位'
Delphi对Excel的所有操作     ExcelApp.Columns[
3].ColumnWidth := 4
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
4] := '型号规格'
Delphi对Excel的所有操作     ExcelApp.Columns[
4].ColumnWidth := 20
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
5] := '部件单价'
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
6] := '库存数量'
Delphi对Excel的所有操作     ExcelApp.Cells[row, 
7] := '库存金额'
Delphi对Excel的所有操作     
while not Eof do 
Delphi对Excel的所有操作     
begin 
Delphi对Excel的所有操作       
if data.Locate('ProNO', FieldByName('ProNO').AsString, []) then 
Delphi对Excel的所有操作       
begin 
Delphi对Excel的所有操作         inc(row); 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
1] := FieldByName('ProNO').AsString; 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
2] := data.FieldByName('ProName').AsString; 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
3] := data.FieldByName('ProUnit').AsString; 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
4] := data.FieldByName('ProKind').AsString; 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
5] := data.FieldByName('ProMoney').AsString; 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
6] := FieldByName('sNum').Value; 
Delphi对Excel的所有操作         ExcelApp.Cells[row, 
7] := '=E' + IntToStr(row) + '*F' + IntToStr(row); 
Delphi对Excel的所有操作       
end
Delphi对Excel的所有操作       Next; 
Delphi对Excel的所有操作
{        if RecNO = 10 then 
Delphi对Excel的所有操作         Break;
} 
Delphi对Excel的所有操作       ProgressBar.Position :
= RecNO * 100 div RecordCount; 
Delphi对Excel的所有操作       Show; 
Delphi对Excel的所有操作     
end
Delphi对Excel的所有操作     ExcelApp.Cells[row 
+ 12] := '合计'
Delphi对Excel的所有操作     ExcelApp.Cells[row 
+ 17] := '=SUM(G2:G' + IntToStr(Row); 
Delphi对Excel的所有操作     Free; 
Delphi对Excel的所有操作   
end
Delphi对Excel的所有操作 finally 
Delphi对Excel的所有操作   data.Free; 
Delphi对Excel的所有操作   ExcelApp.ScreenUpdating :
= true; 
Delphi对Excel的所有操作 
end
Delphi对Excel的所有操作
end
Delphi对Excel的所有操作
Delphi对Excel的所有操作
function TfrmExcel.InitExcel(var excel: Variant): Boolean; 
Delphi对Excel的所有操作
begin 
Delphi对Excel的所有操作 try 
Delphi对Excel的所有操作   excel :
= CreateOleObject('Excel.Application'); 
Delphi对Excel的所有操作 except 
Delphi对Excel的所有操作   result :
= false; 
Delphi对Excel的所有操作   showMsg(
'调用Excel出错!'); 
Delphi对Excel的所有操作   exit; 
Delphi对Excel的所有操作 
end
Delphi对Excel的所有操作
Delphi对Excel的所有操作 excel.WorkBooks.Add; 
Delphi对Excel的所有操作 excel.WorkSheets[
1].Activate; 
Delphi对Excel的所有操作 excel.Visible :
= true; 
Delphi对Excel的所有操作 excel.ScreenUpdating :
= false; 
Delphi对Excel的所有操作 excel.Rows.RowHeight :
= 18
Delphi对Excel的所有操作 excel.ActiveSheet.PageSetup.PrintGridLines :
= false; 
Delphi对Excel的所有操作 result :
= true; 
Delphi对Excel的所有操作
end;

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-12-22
  • 2022-01-10
  • 2022-12-23
猜你喜欢
  • 2022-02-15
  • 2021-07-27
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案