Delphi与Excel
来源:互联网 发布:什么是网络互联 编辑:程序博客网 时间:2024/06/07 20:14
uses comobj,excel97,excel2000;
//从Excel写数据到Access库
prodedure ExcelToMdb(EXLfile:string;);
var
sheet,XLApp,workbook : variant;
iRow,MaxRow:integer;
begin
screen.Cursor:=crHourGlass;
try
//创建对象
XLApp:=createOleObject('Excel.Application');
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=false;
XLApp.WorkBooks.Add(EXLfile);
workbook := XLApp.workbooks[1];
sheet:=workbook.worksheets[1];
//sheet:=XLApp.WorkBooks[1].worksheets[1];
//取得最大行数 maxRow
XLApp.ActiveCell.SpecialCells(xlLastCell).Select;
maxRow:=XLApp.ActiveCell.Row; //最大行数
//写数据到Access库
ADOTable1.open;
for iRow:=2 to MaxRow do
if sheet.cells[iRow,1]<>'' then //关键字不为空
begin
ADOTable1.Append ;
ADOTable1.fieldByName('ID').asInteger:=
strToInt(sheet.cells[iRow,1]);
ADOTable1.fieldByName('code').asString:=sheet.cells[iRow,2]; //编码
ADOTable1.fieldByName('name').asString:=sheet.cells[iRow,3]; //名称
ADOTable1.post;
end;
finally
if not VarIsEmpty(XLApp) then begin //释放对象
XLApp.displayAlerts:=false;
XLApp.ScreenUpdating:=true;
XLApp.quit;
end;
screen.Cursor:=crDefault;
end;
end;
//=================== 其他一些属性方法 ===============//
curRow:=XLApp.ActiveCell.Row; //当前行数
XLApp.displayAlerts:=false; //运行宏时是否显示警告和消息
XLApp.ScreenUpdating:=false; //屏幕更新功能,提高速度;
//结束运行后,ScreenUpdating 设回到 True
XLApp.run('macroName',params...)//运行宏
workbook.save ;
workBook.SaveAs(AFileName,xlNormal,'','',False,False);
- Delphi与Excel
- Delphi与Excel
- Delphi 与 Excel (二)
- Delphi与Excel
- Delphi与Excel
- delphi与Excel 2
- delphi 与 Excel数据交换
- delphi与Excel(一)delphi控制Excel
- delphi与Excel(二)delphi控制Excel具体代码
- Delphi与Excel的编程学习
- Delphi与Excel的亲密接触
- Delphi与Excel的亲密接触
- Delphi与Excel的亲密接触
- Delphi与Excel的亲密接触
- [Delphi-码农]Delphi EXCEL导入
- delphi操纵Excel之一
- Delphi 控制Excel
- Delphi控制Excel
- DELPHI中进程、窗口句柄、文件属性、程序运行状态
- Delphi与XML
- 征集咱们BLOG的副标题!
- Delphi 与 XML 示例(直接利用IXMLDocument)
- Charset in J2EE Web Application
- Delphi与Excel
- Delphi中Excel的快速导入
- 免费发布一个简单而有趣的计算工具
- 困倦,因为9/11报告
- C#里的委托和事件实现Observer
- BBS 设计思路系列 ---- 逐步完善的道具中心
- 没有这个东东真的不行
- Delphi_Excel例子:单元格拷贝粘贴
- 用ADox获得表的唯一索引