delphi操作excel

delphi操作excel
delphi操作excel

DEPHI操作EXCEL的例子

var Form1: TForm1;

ExcelApp: Variant;

implementation

{$R

*.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

ExcelApp := CreateOleObject( …Excel.Application? );

end;

procedure TForm1.Button1Click(Sender: TObject);

begin//E xcelApp.WorkBooks.Open(…c:\1.xls? );

ExcelApp.WorkBooks.Open(ExtractFileDir(application.ExeName)+?\2.xls?);

ExcelApp.Visible := True;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

excelapp.workbooks.close;

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

ExcelApp.ActiveWorkBook.Sheets['Sheet2'].Select

end;

procedure TForm1.Button4Click(Sender: TObject);

begin

excelapp.activeworkbook.sheets[edit1.Text].select;

excelapp.activeworkbook.sheets[edit1.Text].range[edit2.Text].select;

edit3.Text :=excelapp.ActiveCell.value;

//

取公式excelapp.ActiveCell.FormulaR1C1

//取值excelapp.ActiveCell.value

end;

procedure TForm1.Button5Click(Sender: TObject);

begin

memo1.Clear;

excelapp.activeworkbook.sheets[edit4.Text].select;

excelapp.activeworkbook.sheets[edit4.Text].range[edit5.Text].select;

memo1.Lines.Add(…字体:?+https://www.360docs.net/doc/de16619568.html,);

if

not VarIsNull(excelapp.Selection.Font.size) then

memo1.Lines.Add(…字号:?+inttostr(excelapp.Selection.Font.size));

memo1.Lines.Add(…字形:?+excelapp.Selection.Font.FontStyle);

if

not VarIsNull(excelapp.Selection.Font.Underline) then

memo1.Lines.Add(…下划线:?+inttostr(excelapp.Selection.Font.Underline));

if

not VarIsNull(excelapp.Selection.Font.ColorIndex) then

memo1.Lines.Add(…字体颜色:?+inttostr(excelapp.Selection.Font.ColorIndex)); if

not VarIsNull(excelapp.Selection.Interior.ColorIndex) then

memo1.Lines.Add(…填充颜色:?+inttostr(excelapp.Selection.Interior.ColorIndex));

if

not VarIsNull(excelapp.Selection.HorizontalAlignment) then

memo1.Lines.Add(…文本水平对齐方式:?+inttostr(excelapp.Selection.HorizontalAlignment));

if

not VarIsNull(excelapp.Selection.VerticalAlignment) then

memo1.Lines.Add(…文本垂直对齐方式:?+inttostr(excelapp.Selection.VerticalAlignment));

if

not VarIsNull(excelapp.Selection.MergeCells) then

m emo1.Lines.Add(…合并单元格:?+inttostr(excelapp.Selection.MergeCells));

if

not VarIsNull(excelapp.Selection.WrapText) then

memo1.Lines.Add(…自动换行:?+inttostr(excelapp.Selection.WrapText));

// 1: Left, 2: Right, 3: Top, 4: bottom

// 5: \, 6: / (斜线)

// 7: Left, 8: Top, 9: bottom, 10: Right (不包括内部单元格)

// 11, 12 , 内部单元格线条(分别是竖线和横线,12我用了没效果)

if

not VarIsNull(excelapp.Selection.Borders[1].LineStyle) then

memo1.Lines.Add(…区域活动单元格左边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[1].LineStyle)+?:'+inttostr(exce lapp.Selection.Borders[ 1].Weight)+?:'+inttostr(excelapp.Selection.Borders[1].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[2].LineStyle) then

memo1.Lines.Add(…区域活动单元格右边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[2].LineStyle)+?:'+inttost r(excelapp.Selection.Borders[ 2].Weight)+?:'+inttostr(excelapp.Selection.Borders[2].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[3].LineStyle) then

memo1.Lines.Add(…区域活动单元格上边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[3].LineStyle)+?:'+i nttostr(excelapp.Selection.Borders[ 3].Weight)+?:'+inttostr(excelapp.Selection.Borders[3].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[4].LineStyle) then

memo1.Lines.Add(…区域活动单元格下边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[4].LineStyle)+?:'+inttostr(excelapp.Selection.Borders[ 4].Weight)+?:'+inttostr(excelapp.Selection.Borders[4].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[5].LineStyle) then

memo1.Lines.Add(…区域左右斜边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[5].LineStyle)+?:'+inttostr(excelapp.Selection.Borders[ 5].Weight)+?:'+inttostr(excelapp.Selection.Borders[5].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[6].LineStyle) then

memo1.Lines.Add(…区域右左斜边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[6].LineStyle)+?:'+inttostr(excelapp.Selection.Borders[ 6].Weight)+?:'+inttostr(excelapp.Selection.Borders[6].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[7].LineStyle) then

memo1.Lines.Add(…区域左边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[7].LineStyle)+?:'+inttostr(excelapp.Selection.Borders[ 7].Weight)+?:'+inttostr(excelapp.Selection.Borders[7].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[8].LineStyle) then

memo1.Lines.Add(…区域上边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[8].LineStyle)+?:'+inttostr(excelapp.Selection.Borders[ 8].Weight)+?:'+inttostr(excelapp.Selection.Borders[8].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[9].LineStyle) then

memo1.Lines.Add(…区域下边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[9].LineStyle)+?:'+inttostr(excelapp.Selection.Borders[ 9].Weight)+?:'+inttostr(excelapp.Selection.Borders[9].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[10].LineStyle) then

memo1.Lines.Add(…区域右边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[10].LineStyle)+?:'+inttostr(excelapp.Selection.Borders [10].Weight)+?:'+inttostr(excelapp.Selection.Borders[10].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[11].LineStyle) then

memo1.Lines.Add(…区域内部垂直边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[11].LineStyle)+?:'+inttostr(excelapp.Selection.Borders [11].Weight)+?:'+inttostr(excelapp.Selection.Borders[11].ColorIndex));

if

not VarIsNull(excelapp.Selection.Borders[12].LineStyle) then

memo1.Lines.Add(…区域内部水平边框(线性:大小:颜色):?+inttostr(excelapp.Selection.Borders[12].LineStyle)+?:'+inttostr(excelapp.Selection.Borders [12].Weight)+?:'+inttostr(excelapp.Selection.Borders[12].ColorIndex));

memo1.Lines.Add(…数字类型:?+excelapp.Selection.NumberFormatLocal);

memo1.Lines.Add(…行高:?+inttostr(excelapp.Selection.Ro wHeight));

memo1.Lines.Add(…列宽:?+inttostr(excelapp.Selection.ColumnWidth));

memo1.Lines.Add(…工作表名称:?+excelapp.activeworkbook.sheets[edit4.Text].name);

end;

procedure TForm1.Button6Click(Sender: TObject);

begin

memo2.Clear;

excelapp.activeworkbook.sheets[edit6.Text].select;

memo2.Lines.Add(…图表标题:?+excelapp.sheets[edit6.Text].ChartObjects[1].chart.ChartTitle.Characters.Text);

end;

procedure TForm1.Button7Click(Sender: TObject);

begin

ExcelApp.ActiveWorkbook.Sheets['Sheet3'].Select;

ExcelApp.Acti veWorkbook.PivotCaches.Add(1,?Sheet1!R1C2:R5C4′).CreatePivotTable(…[1.xls]S heet3!R2C1′,?数据透视表1′);

ExcelApp.ActiveWorkbook.ShowPivotTableFieldList :=

True;

ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).PivotFields(…姓名?).Orientation:=1; ExcelApp.Active Sheet.PivotTables(…数据透视表1′).PivotFields(…姓名?).Position:=1; ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).PivotFields(…语文?).Orientation:=2; ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).PivotFields(…语文?).Position:=1; ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).PivotFields(…数学?).Orientation:=2; ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).PivotFields(…数学?).Position:=1;

ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).DisplayImmediateItems

:=True;

ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).AddDataField(ExcelApp.ActiveSheet.PivotTables(…数据透视表1′).PivotFields(…语文?),

…求和项:语文?,-4157);

//说明,对于宏录制的代码中的,xlRowField ,xlColumnField ,xlSum

没有相应的说明,

//可以EXCEL的宏中调试时,跟踪出相关的值如xlSum=-4157,其它的根据要求,自己跟踪

//以下是录制的宏命令,以供参考

{

Sub Macro1()

Macro1 Macro

宏由MS User 录制,时间: 2006-5-19

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=

_

“Sheet1!R1C2:R5C4″).CreatePivotTable TableDestination:=”", TableName:= _

“数据透视表1″,

DefaultVersion:=xlPivotTableVersion10

ActiveSheet.PivotTableWizard

TableDestination:=ActiveSheet.Cells(3, 1)

ActiveSheet.Cells(3, 1).Select

With

ActiveSheet.PivotTables(“数据透视表1″).PivotFields(“姓名”)

.Orientation =

xlRowField

.Position = 1

End With

With

ActiveSheet.Piv otTables(“数据透视表1″).PivotFields(“语文”)

.Orientation =

xlColumnField

.Position = 1

End With

With

ActiveSheet.PivotTables(“数据透视表1″).PivotFields(“数学”)

.Orientation =

xlColumnField

.Position = 1

End With

Ra nge(“D8″).Select

ActiveSheet.PivotTables(“数据透视表1″).AddDataField ActiveSheet.PivotTables(“数据透视表1″ _

).PivotFields(“语文”), “求和项:语文”,

xlSum

Range(“C13″).Select

End

Sub

}

end;

怎么在delphi中读取Excel数据(各种详细操作)

怎么在delphi中读取Excel数据(各种详细操作)转 ( 一) 使用动态创建的方法 首先创建Excel 对象,使用ComObj : Var ExcelApp : Variant ; ExcelApp := CreateOleObject ( '' Excel.Application '' ) ; 1 ) 显示当前窗口: ExcelApp.Visible := True ; 2 ) 更改Excel 标题栏: ExcelApp.Caption := '' 应用程序调用Microsoft Excel '' ; 3 ) 添加新工作簿: ExcelApp.WorkBooks.Add ; 4 ) 打开已存在的工作簿: ExcelApp.WorkBooks.Open ( '' C : \Excel\Demo.xls '' ) ; 5 ) 设置第2个工作表为活动工作表: ExcelApp.WorkSheets [ 2 ] .Activate ; 或 ExcelApp.WorksSheets [ '' Sheet2 '' ] .Activate ; 6 ) 给单元格赋值: ExcelApp.Cells [ 1 , 4 ] .Value := '' 第一行第四列'' ; 7 ) 设置指定列的宽度(单位:字符个数),以第一列为例: ExcelApp.ActiveSheet.Columns [ 1 ] .ColumnsWidth := 5 ; 8 ) 设置指定行的高度(单位:磅)(1磅=0.035 厘米),以第二行为例:ExcelApp.ActiveSheet.Rows [ 2 ] .RowHeight := 1 / 0.035 ; // 1厘米 9 ) 在第8行之前插入分页符: ExcelApp.WorkSheets [ 1 ] .Rows [ 8 ] .PageBreak := 1 ; 10 ) 在第8列之前删除分页符: ExcelApp.ActiveSheet.Columns [ 4 ] .PageBreak := 0 ;

Delphi控制Excel的重要属性和方法

Delphi控制Excel2000 类别:COM&ActiveX (一)使用动态创建的方法 首先创建Excel对象,使用ComObj: var ExcelApp:Variant; ExcelApp:=CreateOleObject('Excel.Application'); 1)显示当前窗口: ExcelApp.Visible:=True; 2)更改Excel标题栏: ExcelApp.Caption:='应用程序调用Microsoft Excel'; 3)添加新工作簿: ExcelApp.WorkBooks.Add; 4)打开已存在的工作簿: ExcelApp.WorkBooks.Open('C:\Excel\Demo.xls'); 5)设置第2个工作表为活动工作表: ExcelApp.WorkSheets[2].Activate; 或 ExcelApp.WorksSheets['Sheet2'].Activate; 6)给单元格赋值: ExcelApp.Cells[1,4].Value:='第一行第四列'; 7)设置指定列的宽度(单位:字符个数),以第一列为例: ExcelApp.ActiveSheet.Columns[1].ColumnsWidth:=5; 8)设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例: ExcelApp.ActiveSheet.Rows[2].RowHeight:=1/0.035;//1厘米 9)在第8行之前插入分页符: ExcelApp.WorkSheets[1].Rows[8].PageBreak:=1; 10)在第8列之前删除分页符: ExcelApp.ActiveSheet.Columns[4].PageBreak:=0; 11)指定边框线宽度: ExcelApp.ActiveSheet.Range['B3:D4'].Borders[2].Weight:=3; 1-左2-右3-顶4-底5-斜(\)6-斜(/) 12)清除第一行第四列单元格公式: ExcelApp.ActiveSheet.Cells[1,4].ClearContents; WrapText:=True可能是自动换行 13)设置第一行字体属性: ExcelApp.ActiveSheet.Rows[1]https://www.360docs.net/doc/de16619568.html,:='隶书'; ExcelApp.ActiveSheet.Rows[1].Font.Color:=clBlue; ExcelApp.ActiveSheet.Rows[1].Font.Bold:=True; ExcelApp.ActiveSheet.Rows[1].Font.UnderLine:=True; 14)进行页面设置: a.页眉: ExcelApp.ActiveSheet.PageSetup.CenterHeader:='报表演示'; b.页脚:

Delphi操作EXCEL函数整理

一、使用单元: Use :EXCEL 2000, ComObj 二、定义 var ExcelApp,Sheet,Range: Variant; 注释: ExcelApp 为定义的Excel 对象 Sheet 为定义的工作表(Sheet)对象 Range 为定义的工作表范围 三、关于Excel 对象创建初始化以及工作表、工作表范围的初始化 1. 创建excel对象: ExcelApp := CreateOleObject( 'Excel.Application' ); 2. 显示当前窗口: ExcelApp.Visible := True; 3. 更改Excel 标题栏: ExcelApp.Caption := '应用程序调用Microsoft Excel'; 4. 添加新工作簿: ExcelApp.WorkBooks.Add; 5 打开已存在的工作簿: ExcelApp.WorkBooks.Open(FilePath); 6.设置工作簿默认工作表张数 ExcelApp.SheetsInNewWorkbook := 1; 7.设置工作表名称 ExcelApp.Workbooks[WorkbookNum].WorkSheets[WorkSheetNum].Name := PName; 8.工作表初始化 Sheet:= ExcelApp.Workbooks[WorkbookNum].WorkSheets[WorkSheetNum]; 9.工作表范围初始化 Range := Sheet.Range['A1:DL1'] ; 10.设置第2个工作表为活动工作表: ExcelApp.WorkSheets[2].Activate; 或 ExcelApp.WorksSheets[ 'Sheet2' ].Activate; 三、单元格赋值设置数值类型 1. 给单元格赋值: ExcelApp.Cells[row, column].Value := '第一行第四列'; 或 Sheet.Cells[row, column] := ‘第一行第四列’; 2 清除第一行第四列单元格公式:

【Delphi】汇出Excel时,Excel单元格格式设置(附Delphi操作Excel方法)

【Delphi】汇出Excel时,Excel单元格格式设置(附Delphi操作Excel方法) 一个例子: excelworksheet1.Cells.Item[row,3]. numberformatlocal:='$#,##0.00;[红色]-$#,##0.00'; excelworksheet1.Cells.Item[row,3].Formula:='=SUM(R[-'+inttostr(row-rowflag+1)+']C:R[-1]C)'; excelworksheet1.Cells.Item[row,3].Borders[3].LineStyle :=xlContinuous; excelworksheet1.Cells.Item[row,3].Borders[4].LineStyle :=xlDouble; excelworksheet1.Cells.Item[row,4].Borders[3].LineStyle :=xlContinuous; excelworksheet1.Cells.Item[row,4].Borders[4].LineStyle :=xlDouble; excelworksheet1.Cells.Item[row,4].Formula:='=R[-1]C'; 注:不知道公式及格式,均可通过录制宏找出对应公式及格式。 效果如下图: 资料来自网络 单元格设置 1.设置单元格线框 Excel.ActiveSheet.Range[B10:C13].Borders[N].LineStyle := xlNone Excel.ActiveSheet.Range[B10:C13].Borders[N].Weight := xlThin

【免费下载】Delphi汇出Excel时Excel单元格格式设置附Delphi操作Excel方法

【Delphi】汇出Excel 时,Excel 单元格格式设置(附Delphi 操作Excel 方法)一个例子:excelworksheet1.Cells.Item[row,3]. numberformatlocal:='$#,##0.00;[红色]-$#,##0.00'; excelworksheet1.Cells.Item[row,3].Formula:='=SUM(R[-'+inttostr(row-rowflag+1)+']C:R[-1]C)'; excelworksheet1.Cells.Item[row,3].Borders[3].LineStyle :=xlContinuous;excelworksheet1.Cells.Item[row,3].Borders[4].LineStyle :=xlDouble;excelworksheet1.Cells.Item[row,4].Borders[3].LineStyle :=xlContinuous;excelworksheet1.Cells.Item[row,4].Borders[4].LineStyle :=xlDouble;excelworksheet1.Cells.Item[row,4].Formula:='=R[-1]C';注:不知道公式及格式,均可通过录制宏找出对应公式及格式。 效果如下图: 资料来自网络单元格设置1.设置单元格线框Excel.ActiveSheet.Range[B10:C13].Borders[N].LineStyle := xlNone Excel.ActiveSheet.Range[B10:C13].Borders[N].Weight := xlThin 、管路敷设技术通过管线敷设技术,不仅可以解决吊顶层配置不规范问题,而且可保障各类管路习题到位。在管路敷设过程中,要加强看护关于管路高中资料试卷连接管口处理高中资料试卷弯扁度固定盒位置保护层防腐跨接地线弯曲半径标高等,要求技术交底。管线敷设技术中包含线槽、管架等多项方式,为解决高中语文电气课件中管壁薄、接口不严等问题,合理利用管线敷设技术。线缆敷设原则:在分线盒处,当不同电压回路交叉时,应采用金属隔板进行隔开处理;同一线槽内,强电回路须同时切断习题电源,线缆敷设完毕,要进行检查和检测处理。、电气课件中调试对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料试卷相互作用与相互关系,根据生产工艺高中资料试卷要求,对电气设备进行空载与带负荷下高中资料试卷调控试验;对设备进行调整使其在正常工况下与过度工作下都可以正常工作;对于继电保护进行整核对定值,审核与校对图纸,编写复杂设备与装置高中资料试卷调试方案,编写重要设备高中资料试卷试验方案以及系统启动方案;对整套启动过程中高中资料试卷电气设备进行调试工作并且进行过关运行高中资料试卷技术指导。对于调试过程中高中资料试卷技术问题,作为调试人员,需要在事前掌握图纸资料、设备制造厂家出具高中资料试卷试验报告与相关技术资料,并且了解现场设备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。、电气设备调试高中资料试卷技术电力保护装置调试技术,电力保护高中资料试卷配置技术是指机组在进行继电保护高中资料试卷总体配置时,需要在最大限度内来确保机组高中资料试卷安全,并且尽可能地缩小故障高中资料试卷破坏范围,或者对某些异常高中资料试卷工况进行自动处理,尤其要避免错误高中资料试卷保护装置动作,并且拒绝动作,来避免不必要高中资料试卷突然停机。因此,电力高中资料试卷保护装置调试技术,要求电力保护装置做到准确灵活。对于差动保护装置高中资料试卷调试技术是指发电机一变压器组在发生内部故障时,需要进行外部电源高中资料试卷切除从而采用高中资料试卷主要保护装置。

德尔菲法(Delphi)Excel上机指导

1.1 德尔菲法实验 1.1.1 理论知识准备 德尔菲(Delphi )是在专家个人判断法的基础上发展起来的一种新型直观的预测方法。目前,德尔菲法已经运用在规划和决策中,并具有较高的声望,是一种重要的规划决策工具。 德尔菲法与专家会议法相比有三个特点,即匿名性、反馈性和预测结果的统计特性。匿名性就是采用匿名函询的方式征求意见,以就消除对专家判断的客观性有影响的一些不良因素。反馈性就是要进行几轮专家意见征询,并把上一轮的结果反馈到下一轮的预测中去,以便专家们可以参考有价值的意见从而提出更好的意见。预测结果的统计特性是指德尔菲法采用统计方法对专家意见进行处理,从而得到定量的表达,使得专家意见逐渐趋于一致。 德尔菲法预测步骤如下: (1) 确定预测主题,归纳预测事件 预测主题就是所要研究和解决的问题。一个主题包括若干个事件。事件是用来说明主题的重要指标。确定预测主题和归纳预测事件是德尔菲法的关键一步。 (2) 选择专家 德尔菲法要求专家对预测主题相当了解,对预测问题的研究非常深入,所选择专家来源广泛,一般是本企业、本部门的专家和有业务联系、关系密切的外部专家以及在社会上有影响的知名人士。专家人数恰当,通常视预测主题规模而定。专家人数太少,缺乏代表性,太多又难于组织。一般情况下,专家小组人数以10~50人为宜。对重大问题的预测,专家小组的人数可扩大到l00人左右。 (3) 预测过程 经典德尔菲法的预测过程一般分为四轮。第一轮确定预测事件,要求各个专家根据所要预测的主题提出预测事件,并用准确的术语列出“预测事件一览表”。第二轮初次预测,将“预测事件一览表”发给各个专家,要求他们对各个事件做出评价,提出相应的预测,并附上理由。有必要还可以提出需要的补充资料,使预测更加准确。第三轮修改预测,专家根据预测领导小组所反馈的第二轮预测结果和补充资料,再一次进行预测,并像第二轮预测一样附上理由。第四轮最后预测,专家再次根据反馈结果做出最后的预测,并根据领导小组的要求,做出或不做出新的论证。 在实际运用中,预测的轮数依照实际情况而定,如果大多数专家不再修改自己的意见,这表明专家们的意见基本趋于一致,这种情况下才能结束预测。 (4) 确定预测值,做出预测结论 最后对专家应答结果进行量化分析和处理,这是德尔菲法最重要的阶段,常采用中位数法,即上、下四分点之间的距离越小,说明专家们的意见越集中,用中位数代表的预测结果的可信程度越高。 首先,把专家们的意见(即对某个问题的不同方案所给出的得分)按从小到大的顺序排列。若有n 个专家,n 个(包括重复的)答数排列如下:n x x x ≤?≤≤21,若中位数及上、下四分点分别用下上中,,x x x 表示,则 ???=++=++k n x x k n x x k k k 2,2/)(12,11=中

delphi控制excel大全(完全版)

下面是我写的通用文档微机管理系统的打印部分原代码,包括合并execl单元格,加入分页符号,设置行高,列宽,设置execl页头,设置每页记录数,画单元格边框,调用execl模板等等 procedure TfrmMain.Button3Click(Sender:TObject);//动态打印excel报表 var tiaojian:string;//tiaojian为一个sql查询语句,全宗号,目录号,起始日期为一数据库字段begin tiaojian:='; if Edit7.Text<>'then begin tiaojian:=tiaojian+'(全宗号='+EDit7.Text+')and'; end; if Edit8.Text<>'then begin tiaojian:=tiaojian+'(目录号='+Edit8.Text+')and'; end; if Edit9.Text<>'then begin tiaojian:=tiaojian+'(起始日期>='+Edit9.Text+')and'; end else tiaojian:=tiaojian+'(起始日期>=0)and'; if Edit10.Text<>'then begin tiaojian:=tiaojian+'(起始日期<='+Edit10.Text+')and'; end; tiaojian:=copy(tiaojian,1,length(tiaojian)-3);//tiaojian为一个sql查询语句Printanjuan(tiaojian);//调用打印过程 ShellExecute(Handle,'Open',PChar(GetCurpath+'temp.xls'),nil,nil,sw_shownormal);//调用excel查看生成的文件 ProgressBar1.Position:=0;//ProgressBar1为一个进程条控件 end; procedure TfrmMain.Printanjuan(tiaojiao:string); var nowhangi,i,jilushu,LCID:integer;//nowhangi当前execl的所在行,jilushu当前的记录

DELPHI操作EXCEL

(一) 使用动态创建的方法 首先创建Excel 对象,使用ComObj: var ExcelApp: Variant; ExcelApp := CreateOleObject( 'Excel.Application ' ); 1) 显示当前窗口: ExcelApp.Visible := True; 2) 更改Excel 标题栏: ExcelApp.Caption := '应用程序调用Microsoft Excel '; 3) 添加新工作簿: ExcelApp.WorkBooks.Add; 4) 打开已存在的工作簿: ExcelApp.WorkBooks.Open( 'C:\Excel\Demo.xls ' ); 5) 设置第2个工作表为活动工作表: ExcelApp.WorkSheets[2].Activate; 或 ExcelApp.WorksSheets[ 'Sheet2 ' ].Activate; 6) 给单元格赋值: ExcelApp.Cells[1,4].Value := '第一行第四列'; 7) 设置指定列的宽度(单位:字符个数),以第一列为例:ExcelApp.ActiveSheet.Columns[1].ColumnWidth := 5; 8) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例:ExcelApp.ActiveSheet.Rows[2].RowHeight := 1/0.035; // 1厘米 9) 在第8行之前插入分页符: ExcelApp.WorkSheets[1].Rows[8].PageBreak := 1; 10) 在第8列之前删除分页符: ExcelApp.ActiveSheet.Columns[4].PageBreak := 0; 11) 指定边框线宽度: ExcelApp.ActiveSheet.Range[ 'B3:D4 ' ].Borders[2].Weight := 3; 1-左2-右3-顶4-底5-斜( \ ) 6-斜( / ) 12) 清除第一行第四列单元格公式: ExcelApp.ActiveSheet.Cells[1,4].ClearContents;

DELPHI控制EXCEL2000操作全集

Delphi控制Excel2000操作全集 十分值得收藏的咚咚,对认为有用的人很有用,呵呵 ----------------------------------------- Delphi控制Excel2000 希望这分数据,为论坛中的各位会员关于EXCEL操作的问题提供一些帮助。同时也希望各位能将自己整理的、或已有的资料共享出来。 这样可以减少大家的「重复劳动」吗? 技术在于交流,经验在于积累!!!! 一.使用动态创建的方法 首先创建Excel对象,使用ComObj: var ExcelApp:Variant; ExcelApp:=CreateOleObject('Excel.Application'); 1)显示当前窗口: ExcelApp.Visible:=True; 2)更改Excel标题栏: ExcelApp.Caption:='应用程序调用Microsoft Excel'; 3)添加新工作簿: ExcelApp.WorkBooks.Add; 4)打开已存在的工作簿: ExcelApp.WorkBooks.Open('C:\Excel\Demo.xls'); 5)设置第2个工作表为活动工作表: ExcelApp.WorkSheets[2].Activate; 或 ExcelApp.WorksSheets['Sheet2'].Activate; 6)给单元格赋值: ExcelApp.Cells[1,4].Value:='第一行第四列'; 7)设置指定列的宽度(单位:字符个数),以第一列为例: ExcelApp.ActiveSheet.Columns[1].ColumnsWidth:=5; 8)设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例:ExcelApp.ActiveSheet.Rows[2].RowHeight:=1/0.035;//1厘米

Delphi操作Excel大全

1.往Excel中插入图片 用MsExcelWorkSheet.Pictures.Insert(ExtractFilePath(ParamStr(0))+'temp.jpg'); 可以放图片 var ExcelApp,MyWorkBook,MsExcelWorkSheet,Temple1:Variant; begin try ExcelApp:=CreateOleObject('Excel.Application'); MyWorkBook:=CreateOleobject('Excel.Sheet'); MyWorkBook:=ExcelApp.WorkBooks.open(ExtractFilePath(ParamStr(0))+'testItemB ook.xls'); MsExcelWorkSheet:=MyWorkBook.WorkSheets['3']; if not ADOQueryItemBook.IsEmpty then begin Tblobfield(ADOQueryItemBook.FieldByName('pic')).SaveToFile(ExtractFilePat h(ParamStr(0))+'temp.jpg'); MsExcelWorkSheet.Pictures.Insert(ExtractFilePath(ParamStr(0))+'temp.jpg'); end; 提供一些Excel的操作方法,希望有点用处吧。 一) 使用动态创建的方法 首先创建 Excel 对象,使用ComObj: var ExcelApp: Variant; ExcelApp := CreateOleObject( 'Excel.Application' ); 1) 显示当前窗口: ExcelApp.Visible := True; 2) 更改 Excel 标题栏: ExcelApp.Caption := '应用程序调用 Microsoft Excel'; 3) 添加新工作簿: ExcelApp.WorkBooks.Add; 4) 打开已存在的工作簿: ExcelApp.WorkBooks.Open( 'C:\Excel\Demo.xls' ); 5) 设置第2个工作表为活动工作表: ExcelApp.WorkSheets[2].Activate; 或 ExcelApp.WorksSheets[ 'Sheet2' ].Activate; 6) 给单元格赋值:

delphi操作excel

DEPHI操作EXCEL的例子 var Form1: TForm1; ExcelApp: Variant; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin ExcelApp := CreateOleObject( …Excel.Application? ); end; procedure TForm1.Button1Click(Sender: TObject); begin//E xcelApp.WorkBooks.Open(…c:\1.xls? ); ExcelApp.WorkBooks.Open(ExtractFileDir(application.ExeName)+?\2.xls?); ExcelApp.Visible := True; end; procedure TForm1.Button2Click(Sender: TObject); begin excelapp.workbooks.close; end; procedure TForm1.Button3Click(Sender: TObject); begin ExcelApp.ActiveWorkBook.Sheets['Sheet2'].Select end;

procedure TForm1.Button4Click(Sender: TObject); begin excelapp.activeworkbook.sheets[edit1.Text].select; excelapp.activeworkbook.sheets[edit1.Text].range[edit2.Text].select; edit3.Text :=excelapp.ActiveCell.value; // 取公式excelapp.ActiveCell.FormulaR1C1 //取值excelapp.ActiveCell.value end; procedure TForm1.Button5Click(Sender: TObject); begin memo1.Clear; excelapp.activeworkbook.sheets[edit4.Text].select; excelapp.activeworkbook.sheets[edit4.Text].range[edit5.Text].select; memo1.Lines.Add(…字体:?+https://www.360docs.net/doc/de16619568.html,); if not VarIsNull(excelapp.Selection.Font.size) then memo1.Lines.Add(…字号:?+inttostr(excelapp.Selection.Font.size)); memo1.Lines.Add(…字形:?+excelapp.Selection.Font.FontStyle); if not VarIsNull(excelapp.Selection.Font.Underline) then memo1.Lines.Add(…下划线:?+inttostr(excelapp.Selection.Font.Underline)); if not VarIsNull(excelapp.Selection.Font.ColorIndex) then memo1.Lines.Add(…字体颜色:?+inttostr(excelapp.Selection.Font.ColorIndex)); if

delphi中打开excel文件的实现

uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ComObj; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; Excel1: Variant; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin begin excel1 := CreateOleObject('Excel.Application'); excel1.WorkBooks.Open('D:\55\aa.xls'); excel1.WorkSheets['sheet1'].Activate; excel1.Cells[1, 4].value:=56+23;//表示单元格 excel1.ActiveSheet.Columns[4].Insert;//插入列 excel1.Cells.Columns.AutoFit;//自动列大小 excel1.visible := true;//是excel可见。 excel1.WorkSheets[2].Activate; excel1.cells[2,2].value:=44; end; end;

相关主题
相关文档
最新文档