DELPPHI 通过ADO读取EXCEL
来源:互联网 发布:理财风险数据 编辑:程序博客网 时间:2024/06/13 06:59
uses ComObj;
try
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.visible:=False;
ExcelApp.Workbooks.Open(Trim(edt1.Text));//创建COMOBJ对象,并且打开指定文件
except
ShowMessage('打开Excel文件出错,请检查文件是否损坏 或者 系统是否安装了 Microsoft Excel!');
exit;
end;
try
ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0; Data Source=' + Trim(edt1.Text) + ';Extended Properties=Excel 8.0';//设置ADO连接参数,此时并未打开连接
sheetname:= TStringList.Create;
for i:=1 to ExcelApp.WorkBooks[1].Worksheets.Count do //一个EXCEL有多页情况,必须循环多次来查询
sheetname.Add(ExcelApp.WorkBooks[1].Worksheets[i].Name);
finally
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp:=Unassigned;
end;
//这一段其实就是为了得到指定EXCEL文件的各个分页名,而且必须在ADO连接前释放COMOBJ对象,因为ExcelApp正在打开 指定文件(独占方式),,ADO等会也会打开会产生冲突
try
ERRcount:=0;
SUCcount:=0;
for i:=0 to sheetname.count-1 do
begin
try
adoquery1.close;
adoquery1.SQL.Text := 'Select distinct 列名1 from [' + SheetName[i] + '$]';/页名右边
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
pb2.Max := adoquery1.RecordCount;
pb2.Position :=0;
adoquery1.First;
adoquery1.DisableControls;
while not adoquery1.Eof do
begin
mobile := trim(adoquery1.fields[0].asstring);//此示例中仅为了获取第一列(列名1)
mbtype := GetMobileType(addphonestr(mobile));
if mbtype <> -1 then
begin
new(psendData);
psendData^.ssubItems := nil;
psendData^.sCaption := addphonestr(mobile);
psendData^.mbtype := 1 + mbtype; //-1错号,01小灵通,23手机
sendfilelist.Add(psendData);
end;
adoquery1.Next;
end;
end;
SUCcount:=SUCcount+1;//纪录成功加载的页数
except
ERRcount:=ERRcount+1;//纪录加载失败的页数
end;
end;
finally
sheetname.Free;
ADOConnection1.Close;
end;
- DELPPHI 通过ADO读取EXCEL
- VB通过ADO快速读取EXCEL与TXT文件
- ado.net读取excel
- ado.net读取excel
- ado excel读取
- ADO读取Excel内容
- ADO读取EXCEL
- ADO.NET 如何读取 Excel
- ADO.NET 如何读取 Excel
- ado.net 如何读取 excel
- ADO.NET 如何读取 Excel
- ado.net 如何读取 excel
- ado.net 如何读取 excel
- ado.net如何读取Excel
- ado.net读取EXCEL笔记
- ado.net 如何读取 excel
- 利用ADO读取Excel表
- VC ADO读取Excel单元格
- 计算机图形学入门Gossip学习笔记
- kernel 目录 解析
- EMF References
- Visual C#2005技术内幕 (試讀)
- Ajax4jsf
- DELPPHI 通过ADO读取EXCEL
- Windows Sockets网络程序设计核心
- [转贴]看看比尔·盖茨在关注什么(比尔·盖茨在哈佛大学毕业典礼上的演讲)
- Visual C# 2005技术内幕 (試讀)
- VC关于Timer函数,及SWITCH
- netstat 使用
- Wince总结(一)--控制开始菜单内容
- 关于java.lang.reflect.Field 和 java.lang.reflect.Method 的问题
- AJAX 学习笔记(7) 发送请求参数