全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
将 Excel 表内的数据导入到 GridString 控件内 procedure TForm1 ButnNewClick Sender TObject var i j integer ColCount RowCount integer 标识数与行数 msExcel msExcelWorkbook msExcelWorkSheet variant Strtemp str1 str2 string IsDigital boolean begin 判定是否在测试 否则不可以导入数据 if IsTesting then begin Application MessageBox 正在测试中 不可以导入数据 提示 mb ok exit end opendialog1 InitialDir ExtractFileDir paramstr 0 文件的打存放初始路径 OpenDialog1 Filter Microsoft Excel 文件 xls xls 把导入文件名按下面的规律自动增加 注意在 A B 填入对话框的文件名编辑框 00111A XLS 00111B XLS 00112A XLS 00112B XLS 00113A XLS 00113B XLS Strtemp Form1 Caption 当已经导入了文件时 其格式为 后台测试软件 V1 8 0 xsl i pos Strtemp 2 if i 3 then begin delete Strtemp 1 i 删除 后台测试软件 V1 8 0 字样 i pos A Strtemp if i 0 then begin OpenDialog1 FileName OpenDialog1 InitialDir Trim copy Strtemp 1 i 1 B Trim copy Strtemp i 1 4 end else begin i pos B Strtemp 此处要防止非数字转换产生的问题 if i 1 then begin str1 Trim copy Strtemp 1 i 1 IsDigital True 默认 str1 是一个数字 for j 1 to length str1 do if str1 j in 0 1 2 3 4 5 6 7 8 9 then continue else begin IsDigital False break end end if end for if IsDigital then begin str1 inttostr strtoint str1 1 str2 Trim copy Strtemp i 1 4 strtemp for j 1 to i 1 do Strtemp strtemp 0 str1 Formatfloat strtemp strtoint str1 OpenDialog1 FileName OpenDialog1 InitialDir str1 A str2 end end if end end end 创建 Excel 对象 msExcel CreateOleObject Excel Application msExcel displayAlerts false 禁止运行宏时显示警告和提示信息 msExcel ScreenUpdating false 屏幕更新 提高速度 try try if OpenDialog1 Execute then begin msExcelWorkbook msExcel Workbooks Open OpenDialog1 FileName null null null null null null null null null null null null null 0 msExcelWorkSheet msExcelWorkbook Worksheets 1 Form1 Caption 后台测试软件 V2 0 0 ExtractFileName OpenDialog1 FileName 取得 EXCELL 表中有多少行 i 1 while trim msExcelWorkSheet cells item i 1 do i i 1 RowCount i 1 预先设定行数 取得 EXCELL 表中的列数 i 1 while trim msExcelWorkSheet cells item 1 i do i i 1 ColCount i 1 预先设定列数 Rzstringgrid1 ColCount ColCount 2 Rzstringgrid1 RowCount RowCount 2 将内容先清除 For i 0 to ColCount 1 do For j 0 to RowCount 1 do Rzstringgrid1 Cells i j 给 StrinGrid 的表头加上列的标识 1 2 3 For i 2 to ColCount 1 do Rzstringgrid1 Cells i 0 第 inttostr i 1 列 Rzstringgrid1 Cells 列 行 初始为 0 列 0 行 ExcelWorksheet1 Cells Item 行 列 初始为 1 行 1 列 给 StringGrid 的右表头加上行标识 For i 2 to Rowcount 1 do Rzstringgrid1 Cells 0 i 第 inttostr i 1 行 Rzstringgrid1 Cells 1 0 测试频率 Rzstringgrid1 Cells 0 1 测试电平 Rzstringgrid1 Cells 0 0 A B T 标识 Screen Cursor crHourGlass for i 1 to RowCount do 行 for j 1 to ColCount do 列 begin if trim msExcelWorkSheet cells item i 1 then begin Rzstringgrid1 Cells j i msExcelWorkSheet Cells Item i j Application ProcessMessages end else begin Screen Cursor crdefault exit end end Screen Cursor crdefault Application MessageBox 恭喜您 按照您的指示要求 数据成功导入 提示 mb ok end else begin Application MessageBox 没有选择要导入的文件 数据未导入成功 提示 mb ok exit end except on E Exception do MessageBox handl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 品誉咨询绩效考核方案(3篇)
- vi设计方案策划与咨询(3篇)
- 客服电话沟通标准用语与作业规范
- 建筑加固支顶施工方案设计
- 新时代教研人员岗位职责解读
- 光伏静压桩引孔施工方案
- 建筑工地光伏节能方案设计
- 松原酒店建筑方案设计分析
- 建筑更新方案设计规范
- 商品房建筑亮化方案设计
- 《基层常见病诊疗指南》
- 2025年及未来5年中国专用灯具行业市场调研及投资战略研究报告
- 2025年新版中国移动笔试题库及答案
- 2025年湖北省生态环保有限公司招聘33人笔试参考题库附带答案详解
- 集装箱驾驶员管理制度
- 第八章健美操健美操组合动作教学设计人教版初中体育与健康八年级全一册
- 4.11五四运动课件-统编版八年级历史上册
- 肿瘤患者中心静脉血管通路装置相关皮肤损伤临床护理实践指南 2
- 医疗安全培训课件妇科
- 脐带血栓课件
- 山东初级注安师考试题库及答案
评论
0/150
提交评论