请问怎样对Excel文件某列的数据进行替换?

OverIsOver 2005-05-17 11:14:38
请指点一二了,谢谢 :)
...全文
171 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
OverIsOver 2005-05-23
  • 打赏
  • 举报
回复
怕被扣信誉分,只好结贴了~
OverIsOver 2005-05-18
  • 打赏
  • 举报
回复
晕了,就这样结贴偶不甘心啊 :)
现在我是这样做的:
procedure SetXls_DescToValue(ADOCmd:TAdoCommand;const fname,SheetName:String;
const FieldLst:TStrings;DictLst:TMyItemList);
var
StrOpenDB:String;
i, iPosOfItem, j : Integer;
sSQL : String;
begin
StrOpenDB:='OpenDataSource(''Microsoft.Jet.OLEDB.4.0'', ''Data Source='+fname+';User ID=Admin;Password=;Extended properties=Excel 5.0'')...['+SheetName+'$]';
for i:=0 to FieldLst.Count-1 do
begin
if (FieldLst[i][1]='i') and (FieldLst[i][2]='m') then //Èç¹ûÊÇim×Ö¶Î
begin
iPosOfItem := DictLst.IndexOf(FieldLst[i]);
if iPosOfItem<>-1 then
begin
for j:=0 to DictLst.Items[iPosOfItem].DescList.Count-1 do
begin
sSQL := 'Update '+StrOpenDB+' set '+FieldLst[i]+'='''
+ DictLst.Items[iPosOfItem].GetValueByDesc( DictLst.Items[iPosOfItem].DescList[j] )
+ ''' where '+FieldLst[i]+'='''+DictLst.Items[iPosOfItem].DescList[j]+'''';
Application.ProcessMessages;
ADOCmd.CommandText := sSQL;
//LogT('¿ªÊ¼Exec',[],True);
ADOCmd.Execute;
//LogT('Íê³ÉExec'+DictLst.Items[iPosOfItem].DescList[j],[],False);
end;
end;
end
end;
end;
OverIsOver 2005-05-17
  • 打赏
  • 举报
回复
不是直接赋值啊,可能有几十列、三万多行,这样挨个循环费时哦
PS:除了把excel文件做数据源的方法进行update,有没有类似Replace之类的呢?
用TApplicationExcel或者ComObj都可以啊
hellolongbin 2005-05-17
  • 打赏
  • 举报
回复
excel1.cells[1,1].value:='test'

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧