用ADOConnection ADOTable 链接Excel。分别用了DBGrid和StringGrid。
在DBGrid中的记录数是正确的,用StringGrid却总是少最后一条记录. //导入数据到StringGrid
colcount := fromADOTable.Fields.Count;//得到数据集中的字段数与记录数
rowcount := fromADOTable.RecordCount; fromProgressBar.Max := rowcount;//进度条的初始化
fromProgressBar.Position := 0; fromStringGrid.ColCount := colcount+1; //调整StringGrid行、列数。列数增加一行,以便确定是否导入
fromStringGrid.RowCount := rowcount; fromStringGrid.Cells[0,0] := '序';
fromStringGrid.Cells[1,0] := '是否导入'; Lbcolandrow.Caption := '数据源中共有'+InttoStr(colcount)+'个字段和'+ InttoStr(rowcount)+'条记录!'; for row := 0 to rowcount-1 do
begin
fromStringGrid.Cells[1,row+1] := '是'; //用户确定是否导入
fromStringGrid.Cells[0,row+1] := InttoStr(row+1); //每条记录作标记,既第一列排序
for col := 0 to colcount-1 do
begin
if fromADOTable.Fields[col].Value <> null then//如果记录不会空,则赋值
begin
fromStringGrid.Cells[col+2,row+1] := fromADOTable.Fields[col].Value;
end;
end; if not fromADOTable.Eof then //如果不是最后一条记录,则指针下移
begin
fromADOTable.Next;
fromProgressBar.Position := row;
end;
end;
ShowMessage('共执行了:'+InttoStr(number));
在DBGrid中的记录数是正确的,用StringGrid却总是少最后一条记录. //导入数据到StringGrid
colcount := fromADOTable.Fields.Count;//得到数据集中的字段数与记录数
rowcount := fromADOTable.RecordCount; fromProgressBar.Max := rowcount;//进度条的初始化
fromProgressBar.Position := 0; fromStringGrid.ColCount := colcount+1; //调整StringGrid行、列数。列数增加一行,以便确定是否导入
fromStringGrid.RowCount := rowcount; fromStringGrid.Cells[0,0] := '序';
fromStringGrid.Cells[1,0] := '是否导入'; Lbcolandrow.Caption := '数据源中共有'+InttoStr(colcount)+'个字段和'+ InttoStr(rowcount)+'条记录!'; for row := 0 to rowcount-1 do
begin
fromStringGrid.Cells[1,row+1] := '是'; //用户确定是否导入
fromStringGrid.Cells[0,row+1] := InttoStr(row+1); //每条记录作标记,既第一列排序
for col := 0 to colcount-1 do
begin
if fromADOTable.Fields[col].Value <> null then//如果记录不会空,则赋值
begin
fromStringGrid.Cells[col+2,row+1] := fromADOTable.Fields[col].Value;
end;
end; if not fromADOTable.Eof then //如果不是最后一条记录,则指针下移
begin
fromADOTable.Next;
fromProgressBar.Position := row;
end;
end;
ShowMessage('共执行了:'+InttoStr(number));
解决方案 »
- File not found: 'UnitShowModalFor.dcu'
- Access问题
- 请教: 如何让程序在执行某个任务时,显示一个对话框,直到该任务完成时关闭。。
- 我的机子上怎么找不到serversocker和clientsocker这两个控件呢?(D7)
- 请问那位高手有使用SOCKET传输文件的实例(源代码),或相关书籍下载?
- 简单的问题,大家来侃侃!!!
- HELP ME 来者高分相送
- 同志们,老问题,新问,对于我来说是技术难题,不是什么错误,请帮帮忙!!!
- Object Pascal:从对象指针谈起
- 做数据库安装程序的时候,数据库别名怎么设置?
- IT速查手册,程序员的维权基地
- 谁有这种动画的源码?
因为你前面还有个表头。所以应该是记录数+表头。
->
for row := 0 to rowcount do
if not fromADOTable.Eof then //如果不是最后一条记录,则指针下移
begin
fromADOTable.Next;
fromProgressBar.Position := row;
end;