DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: cuiqingbo
今日帖子: 20
在线用户: 12
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 luckywangxw2 (delphifans) ★☆☆☆☆ -
普通会员
2022/7/6 11:34:09
标题:
delphi中操作excel表格 怎么判断Cells.find的结果 是否找到了 浏览:1360
加入我的收藏
楼主: DesRange:Variant;

.........

DesRange:=ExcelApp.WorkSheets[1].Cells.Find('抬头第1/1页');

请教一下,怎么根据返回值来判定 有没有找到
----------------------------------------------
Delphi爱好者
作者:
男 luckywangxw2 (delphifans) ★☆☆☆☆ -
普通会员
2022/7/6 15:12:10
1楼: 如果没有找到,使用DesRange.Row 会出现地址访问错误
----------------------------------------------
Delphi爱好者
作者:
男 tiez (骑牛夜旅) ★☆☆☆☆ -
普通会员
2022/7/6 16:12:52
2楼: 看看DesRange是不是空指针?
----------------------------------------------
-
作者:
男 luckywangxw2 (delphifans) ★☆☆☆☆ -
普通会员
2022/7/6 17:01:40
3楼: VarlsEmpty 与  VarlsNull 都不管用,
assigned(DesRange) 提示类型不兼容
----------------------------------------------
Delphi爱好者
作者:
男 luckywangxw2 (delphifans) ★☆☆☆☆ -
普通会员
2022/7/6 17:05:58
4楼: 一个操作Excel的单元     
这里给出一个Excel的操作单元,函概了部分常用Excel操作,不是我写的,是从Experts-Exchange 
看到后收藏起来的,给大家参考。 
// 该文件操作单元封装了大部分的Excel操作 
// use to manipulate Excel xls File 
// Dragon P.C. <2000.05.10> 
unit ExcelUnit; 
interface 
uses 
Dialogs, Messages, SysUtils, Grids, Cmp_Sec, ComObj, Ads_Misc; 
----------
谁见过这个单元,里面有个函数的声明Function ExcelFind( 
Excel : Variant; 
FindString : ShortString): Boolean; 
但是没有函数的实现部分
----------------------------------------------
Delphi爱好者
作者:
男 somis (somis) ★☆☆☆☆ -
盒子活跃会员
2022/7/6 21:11:31
5楼: 参考一下FlexCel中实现,建议用这个组件,毕竟比20年前的代码稳定可靠

procedure TForm3.BitBtn1Click(Sender: TObject);
var
  Cell: TCellAddress;
  Xls: TExcelFile;
begin
  Cell := TCellAddress.Empty; // initialize the value to null to start searching.

  Xls := TXlsFile.Create('d:\test.xls', false);
  try
    Cell := Xls.Find(Edit1.Text, TXlsCellRange.Null, Cell, false, true, true, false);
    if not Cell.isnull then
      showmessage(Cell.CellRef);
  finally
    FreeAndNil(Xls);
  end;

end;
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/7/6 23:58:59
6楼: NULL (C) = NIL (Delphi)
----------
to Variants try this:

procedure TForm1.Button1Click(Sender: TObject);
var
  x: Variant;
begin
  // x := null;
  //
  //  if Assigned(x) then = it's incompatible types
  // 
  if x = null then
    ShowMessage('x = null')
  else
    ShowMessage('x = not null');
end;
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/7/7 0:07:07
7楼: see if the function:
Function ExcelFind( Excel : Variant; FindString : ShortString): Boolean; 

is in "type lib" file or it is in "Excell language" (VBS)

in Delphi you can use:
---> Component -> Import Component .... to create a "LIB" (a unit .PAS with all internal definitions in a DLL in your system, like DLL from Excel)

if the function is directly from Excell DLL, then, your Object created in your project, automatically recognize it or not when it was used, in case (function "ExcelFind") if it exists, then ok, ELSE = error!

using a "Import Component" the Delphi allow create a "component in your Delphi - Pallete, like TButton for example).

in your case, I think that Expert-Exchange use "Import Component" to create a "TLB" (.pas file)

exists some "xxxx_TLB.pas" in your unit files?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 flcop (flcop) ▲▲▲▲△ -
普通会员
2022/7/7 0:17:16
8楼: 应该用VarIsClear
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/7/7 0:22:25
9楼: for "Variants" is correct verify if "= UNKNOWN" and using "VarIsClear()" can help too! of course!

because a "Variant" same dont used, appoint to "some" = pointer to something" (same that "nothing") --> Variant will be always a "pointer to something"
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 wangdonghai (wdh) ★☆☆☆☆ -
盒子活跃会员
2022/7/8 13:37:45
10楼: DesRange:Variant;

.........

DesRange:=ExcelApp.WorkSheets[1].Cells.Find('抬头第1/1页');
if VarIsType(DesRange,varDispatch) and Assigned(FindVarData(DesRange).VDispatch) then
        ShowMessage('找到了')
      else ShowMessage('没找到');
----------------------------------------------
-
作者:
男 yookee (yookee) ★☆☆☆☆ -
盒子活跃会员
2022/7/8 17:25:41
11楼: @flcop
应该用VarIsClear
此帖子包含附件:
PNG 图像
大小:33.2K
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行148.4375毫秒 RSS