NativeExcel 3.1在读取空单元格时的一个bug及修改

NativeExcel 3.1在读取空单元格时的一个bug及修改


考虑如下情况:
在Excel某单元格内有如下公式

=IF(A3<>"", B3, C3)

这个公式在Excel内运行无误,但NativeExcel处理时无论A3是否是空,都只能得到B3的值。
经检查源码,发现问题出在单元xlscalc.pas中的TXLSCalculator.CompareVariants方法中。
该方法有如下代码:

……
  isnull1 := VarIsNull(value1);
  isnull2 := VarIsNull(Value2);

  if isnull1 and isnull2 then
  begin
    Result := 0;
  end
  else
  begin
    vType1 := GetRetValueType(value1);
    vType2 := GetRetValueType(Value2);

	//问题出在下面这几句:强制转换了Variant变量的类型,却
	//没有更新vType1或vType2,导致后面判断类型时不相等。
    if isnull1 and not(isnull2) then
      ConvertValue(value1, vType2)
    else if isnull2 and not(isnull1) then
      ConvertValue(Value2, vType1);

    if vType1 = vType2 then
    begin
    	……

解决方法也很简单,补上更新vType变量的语句即可:

   if isnull1 and not(isnull2) then
    begin
      ConvertValue(value1, vType2);
      vType1 := GetRetValueType(value1); //更新vType1
    end
    else if isnull2 and not(isnull1) then
    begin
      ConvertValue(Value2, vType1);
      vtype2 := getretvaluetype(value2); //更新vType2
    end;

至此,重新编译,问题解决了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值