




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
DEPHI操作EXCEL的例子var Form1: TForm1; ExcelApp: Variant;implementation$R*.dfmprocedure TForm1.FormCreate(Sender: TObject);beginExcelApp := CreateOleObject( Excel.Application );end;procedure TForm1.Button1Click(Sender: TObject);begin/ExcelApp.WorkBooks.Open(c:1.xls );ExcelApp.WorkBooks.Open(ExtractFileDir(application.ExeName)+2.xls);ExcelApp.Visible := True;end;procedure TForm1.Button2Click(Sender: TObject);beginexcelapp.workbooks.close;end;procedure TForm1.Button3Click(Sender: TObject);beginExcelApp.ActiveWorkBook.SheetsSheet2.Selectend;procedure TForm1.Button4Click(Sender: TObject);beginexcelapp.activeworkbook.sheetsedit1.Text.select;excelapp.activeworkbook.sheetsedit1.Text.rangeedit2.Text.select;edit3.Text :=excelapp.ActiveCell.value;/取公式 excelapp.ActiveCell.FormulaR1C1/取值 excelapp.ActiveCell.valueend;procedure TForm1.Button5Click(Sender: TObject);beginmemo1.Clear;excelapp.activeworkbook.sheetsedit4.Text.select;excelapp.activeworkbook.sheetsedit4.Text.rangeedit5.Text.select;memo1.Lines.Add(字体:+excelapp.Selection.F);ifnot VarIsNull(excelapp.Selection.Font.size) thenmemo1.Lines.Add(字号:+inttostr(excelapp.Selection.Font.size);memo1.Lines.Add(字形:+excelapp.Selection.Font.FontStyle);ifnot VarIsNull(excelapp.Selection.Font.Underline) thenmemo1.Lines.Add(下划线:+inttostr(excelapp.Selection.Font.Underline);ifnot VarIsNull(excelapp.Selection.Font.ColorIndex) thenmemo1.Lines.Add(字体颜色:+inttostr(excelapp.Selection.Font.ColorIndex);ifnot VarIsNull(excelapp.Selection.Interior.ColorIndex) thenmemo1.Lines.Add(填充颜色:+inttostr(excelapp.Selection.Interior.ColorIndex);ifnot VarIsNull(excelapp.Selection.HorizontalAlignment) thenmemo1.Lines.Add(文本水平对齐方式:+inttostr(excelapp.Selection.HorizontalAlignment);ifnot VarIsNull(excelapp.Selection.VerticalAlignment) thenmemo1.Lines.Add(文本垂直对齐方式:+inttostr(excelapp.Selection.VerticalAlignment);ifnot VarIsNull(excelapp.Selection.MergeCells) thenmemo1.Lines.Add(合并单元格:+inttostr(excelapp.Selection.MergeCells);ifnot VarIsNull(excelapp.Selection.WrapText) thenmemo1.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我用了没效果)ifnot VarIsNull(excelapp.Selection.Borders1.LineStyle) thenmemo1.Lines.Add(区域活动单元格左边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders1.LineStyle)+:+inttostr(excelapp.Selection.Borders1.Weight)+:+inttostr(excelapp.Selection.Borders1.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders2.LineStyle) thenmemo1.Lines.Add(区域活动单元格右边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders2.LineStyle)+:+inttostr(excelapp.Selection.Borders2.Weight)+:+inttostr(excelapp.Selection.Borders2.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders3.LineStyle) thenmemo1.Lines.Add(区域活动单元格上边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders3.LineStyle)+:+inttostr(excelapp.Selection.Borders3.Weight)+:+inttostr(excelapp.Selection.Borders3.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders4.LineStyle) thenmemo1.Lines.Add(区域活动单元格下边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders4.LineStyle)+:+inttostr(excelapp.Selection.Borders4.Weight)+:+inttostr(excelapp.Selection.Borders4.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders5.LineStyle) thenmemo1.Lines.Add(区域左右斜边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders5.LineStyle)+:+inttostr(excelapp.Selection.Borders5.Weight)+:+inttostr(excelapp.Selection.Borders5.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders6.LineStyle) thenmemo1.Lines.Add(区域右左斜边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders6.LineStyle)+:+inttostr(excelapp.Selection.Borders6.Weight)+:+inttostr(excelapp.Selection.Borders6.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders7.LineStyle) thenmemo1.Lines.Add(区域左边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders7.LineStyle)+:+inttostr(excelapp.Selection.Borders7.Weight)+:+inttostr(excelapp.Selection.Borders7.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders8.LineStyle) thenmemo1.Lines.Add(区域上边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders8.LineStyle)+:+inttostr(excelapp.Selection.Borders8.Weight)+:+inttostr(excelapp.Selection.Borders8.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders9.LineStyle) thenmemo1.Lines.Add(区域下边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders9.LineStyle)+:+inttostr(excelapp.Selection.Borders9.Weight)+:+inttostr(excelapp.Selection.Borders9.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders10.LineStyle) thenmemo1.Lines.Add(区域右边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders10.LineStyle)+:+inttostr(excelapp.Selection.Borders10.Weight)+:+inttostr(excelapp.Selection.Borders10.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders11.LineStyle) thenmemo1.Lines.Add(区域内部垂直边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders11.LineStyle)+:+inttostr(excelapp.Selection.Borders11.Weight)+:+inttostr(excelapp.Selection.Borders11.ColorIndex);ifnot VarIsNull(excelapp.Selection.Borders12.LineStyle) thenmemo1.Lines.Add(区域内部水平边框(线性:大小:颜色):+inttostr(excelapp.Selection.Borders12.LineStyle)+:+inttostr(excelapp.Selection.Borders12.Weight)+:+inttostr(excelapp.Selection.Borders12.ColorIndex);memo1.Lines.Add(数字类型:+excelapp.Selection.NumberFormatLocal);memo1.Lines.Add(行高:+inttostr(excelapp.Selection.RowHeight);memo1.Lines.Add(列宽:+inttostr(excelapp.Selection.ColumnWidth);memo1.Lines.Add(工作表名称:+excelapp.activeworkbook.sheetsedit4.T);end;procedure TForm1.Button6Click(Sender: TObject);beginmemo2.Clear;excelapp.activeworkbook.sheetsedit6.Text.select;memo2.Lines.Add(图表标题:+excelapp.sheetsedit6.Text.ChartObjects1.chart.ChartTitle.Characters.Text);end;procedure TForm1.Button7Click(Sender: TObject);begin ExcelApp.ActiveWorkbook.SheetsSheet3.Select;ExcelApp.ActiveWorkbook.PivotCaches.Add(1,Sheet1!R1C2:R5C4).CreatePivotTable(1.xlsSheet3!R2C1,数据透视表1); ExcelApp.ActiveWorkbook.ShowPivotTableFieldList :=True;ExcelApp.ActiveSheet.PivotTables(数据透视表1).PivotFields(姓名).Orientation:=1;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).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.PivotCac
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农业废弃物资源化利用项目经济效益评估报告(2025年)
- 安全教育广州办培训课件
- 常用化石燃料相关参数值
- 蓝网科技面试题库及答案
- 安全教育培训通信报道课件
- 矿产品面试题库及答案
- 2025年房地产市场库存去化压力下的社群营销策略报告
- 2025年新能源绿色金融政策对风电产业影响评估
- 安全教育培训记录模板课件
- 高铁新线开通对城市交通拥堵缓解研究报告
- 2024 体育生规章制度
- 事业单位行政单位物业管理服务方案(技术标)
- 单位食堂制止浪费方案
- 2024年电工(高级技师)职业鉴定理论考试题库-上(单选题)
- 《财务管理学(第10版)》课件 第1、2章 总论、财务管理的价值观念
- GB/T 43934-2024煤矿土地复垦与生态修复技术规范
- 高流量湿化仪的使用技术操作及评分标准
- 中华全国总工会办公厅印发《加快工会数字化建设工作方案》
- 透析液质量控制方案
- 2024年危险化学品生产单位主要负责人考试题及答案
- QC七大手法及品质8D方法
评论
0/150
提交评论