



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C+ Builder中使用OLE控制Excel2000,必须掌握Excel2000的自动化对象及Microsoft Word Visual Basic帮助文件中的关于Excel的对象、方法和属性。对象是一个Excel元素,属性是对象的一个特性或操作的一个方面,方法是对象可以进行的动作。首先定义以下几个变量:Variant ExcelApp,Workbook1,Sheet1,Range1;1、Excel中常用的对象是:Application,Workbooks,Worksheets等。 创建应用对象Variant ExcelApp;ExcelApp = Variant:CreateObject (Excel.Application);或者ExcelApp = CreateOleObject (Excel.Application); 创建工作簿对象Variant WorkBook1;WorkBook1 = ExcelApp.OlePropertyGet(ActiveWorkBook); 创建工作表对象Variant Sheet1;Sheet1 = WorkBook1.OlePropertyGet(ActiveSheet); 创建区域对象 Variant Range;Range = Sheet1.OlePropertyGet(Range,A1:A10); 或者使用Excel.Exec(PropertyGet(Range)A1:C1).Exec(Procedure(Select);2、常用的属性操作: 使Excel程序不可见ExcelApp.OlePropertySet(Visible, (Variant)false); 新建EXCEL文件 新建系统模板的工作簿ExcelApp.OlePropertyGet(workbooks).OleFunction(Add) /默认工作簿ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, 1) /单工作表ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, 2) /图表 ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, 3) /宏表ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, 4) /国际通用宏表ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, 5) /与默认的相同ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, 6) /工作簿且只有一个表或者使用ExcelApp的Exec方法Excel.Exec(PropertyGet(Workbooks).Exec(Procedure(Add); 新建自己创建的模板的工作簿ExcelApp.OlePropertyGet(workbooks).OleFunction(Add, C:Tempresult.xlt); 打开工作簿ExcelApp.OlePropertyGet(workbooks).OleFunction(open, 路径名.xls) 保存工作簿WorkBook1.OleFunction(Save); /保存工作簿WorkBook1.OleFunction(SaveAs, 文件名);/工作簿保存为,路径注意用 退出EXCELExcelApp.OleFunction(Quit);ExcelApp = Unassigned;或者ExcelApp.Exec(Procedure(Quit); 操作工作表 选择选择工作表中第一个工作表Workbook1.OlePropertyGet(Sheets, 1).OleProcedure(Select);Sheet1 = Workbook1.OlePropertyGet(ActiveSheet); 重命名工作表Sheet1.OlePropertyGet(Name, Sheet的新名字); 当前工作簿中的工作表总数 int nSheetCount=Workbook1.OlePropertyGet(Sheets).OlePropertyGet(Count); 操作行和列 获取当前工作表中有多少行和多少列:Sheet1.OlePropertyGet(UsedRange).OlePropertyGet(Columns).OlePropertyGet(Count); /列数Sheet1.OlePropertyGet(UsedRange).OlePropertyGet(Rows).OlePropertyGet(Count); /行数 设置列宽ExcelApp.OlePropertyGet(Columns, 1).OlePropertySet(ColumnWidth, 22);或者Range = ExcelApp.OlePropertyGet(Cells, 1, 3);Range.OlePropertySet(ColumnWidth, 22); 设置行高ExcelApp.OlePropertyGet(Rows, 2).OlePropertySet(RowHeight, 25);或者Range = ExcelApp.OlePropertyGet(Cells, 2, 1); Range.OlePropertySet(RowHeight, 25); 在工作表最前面插入一行Sheet1.OlePropertyGet(Rows, 1).OleProcedure(Insert); 删除一行ExcelApp.OlePropertyGet(Rows, 2).OleProcedure(Delete); /将第2行删除 操作单元格 设置单元格字体Sheet1.OlePropertyGet(Cells, 1, 1).OlePropertyGet(Font).OlePropertySet(Name, 隶书); /字体Sheet1.OlePropertyGet(Cells, 2, 3).OlePropertyGet(Font).OlePropertySet(size, 28); /大小 设置所选区域字体Range.OlePropertyGet(Cells).OlePropertyGet(Font).OlePropertySet(Size, 28);Range.OlePropertyGet(Cells).OlePropertyGet(Font).OlePropertySet(Color, RGB(0, 0, 255);其中参数的设置:Font Name : 隶书 /字体名称Size : 12 /字体大小Color : RGB(*,*,*) /颜色Underline : true/false /下划线Italic: true/false /斜体 设置单元格格式为小数百分比Sheet1.OlePropertyGet(Cells, 1, 1).OlePropertySet(NumberFormatLocal, 0.00%); 设定单元格的垂直对齐方式Range = ExcelApp.OlePropertyGet(Cells, 3, 4); / 1=靠上 2=居中 3=靠下对齐 4=两端对齐 5=分散对齐Range.OlePropertySet(VerticalAlignment, 2); 设定单元格的文本为自动换行Range = ExcelApp.OlePropertyGet(Cells, 3, 4);Range.OlePropertySet(WrapText, true); 单元格的合并 Range = Sheet1.OlePropertyGet(Range, A1:A2); /A1和A2单元格合并String strRange = A + IntToStr(j) + : + C + IntToStr(j); /比如:A1:C5Range1=Sheet1.OlePropertyGet(Range, strRange.c_str(); /可以用变量控制单元格合并Range1.OleFunction(Merge, false); 读写单元格 指定单元格赋值String strValue = abcdefg;Sheet1.OlePropertyGet(Cells, 3, 6).OlePropertySet(Value, strValue.c_str();Sheet1.OlePropertyGet(Cells, j, 1).OlePropertySet(Value, 总记录: + String(j-6);或者使用Excel.Exec(PropertyGet(Cells)13).Exec(PropertySet(Value)15); 所选区域单元格赋值Range.OlePropertyGet(Cells).OlePropertySet(Value, 10); 所选区域行赋值Range.OlePropertyGet(Rows,1).OlePropertySet(Value, 1234); 工作表列赋值Sheet1.OlePropertyGet(Columns,1).OlePropertySet(Value, 1234); 读取取值语句:String strValue = Sheet1.OlePropertyGet(Cells, 3, 5).OlePropertyGet(Value); 窗口属性 显示属性ExcelApp.OlePropertySet(Windowstate, 3);
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年电热锅炉行业前景分析及投资机遇研究报告
- 2025年民用雷达行业投资趋势与盈利模式研究报告
- 2025年视频会议系统行业投资趋势与盈利模式研究报告
- 2025年食品产业园区行业投资趋势与盈利模式研究报告
- 2025年尾矿综合利用行业当前竞争格局与未来发展趋势分析报告
- 2025年智慧停车行业规模分析及投资前景研究报告
- 2025年训练健身器材行业需求分析及创新策略研究报告
- 2025年房地产估价行业前景分析及投资机遇研究报告
- 挖机手聘用合同
- 劳动仲裁签协议书劳动关系仲裁书(13篇)
- 多媒体教室使用的课件
- 2025年军队专业技能岗位文职人员招聘考试(工程机械驾驶员)历年参考题库含答案详解(5卷)
- 2025年下半年广西现代物流集团社会招聘校园招聘笔试参考题库附带答案详解(10套)
- 2025年粉笔辅警考试题库
- 水声传感器技术研究与应用
- 2025年小学教研室教学计划
- 2025年上海市建筑工程施工合同模板
- 手术室护理业务学习
- 贩卖人口罪与强迫劳动罪
- 新员工入职职业道德培训
- 宽带宣传活动方案
评论
0/150
提交评论