|
本帖最后由 jianganew 于 2014-9-28 12:53 编辑
请教大师们:
Local $oExcel = _ExcelBookOpen(@ScriptDir & "/" & "\" & "1.xls", 0, False)
$pianhao = GUICtrlRead($Input1)
$hang = $oExcel.activesheet.UsedRange.Rows.Count
$rng = $oExcel.activesheet.Range("A1:A" & $hang).cells.find($pianhao)
If IsObj($rng) Then
$i = $rng.row
_ExcelWriteCell($oExcel, GUICtrlRead($Input1), $i, 1)
_ExcelWriteCell($oExcel, GUICtrlRead($Combo1), $i, 2)
_ExcelWriteCell($oExcel, GUICtrlRead($Combo2), $i, 3)
_ExcelBookSave($oExcel)
Else
_ExcelRowInsert($oExcel, 2, 1)
$i = 2
_ExcelWriteCell($oExcel, GUICtrlRead($Input1), $i, 1)
_ExcelWriteCell($oExcel, GUICtrlRead($Combo1), $i, 2)
_ExcelWriteCell($oExcel, GUICtrlRead($Combo2), $i, 3)
_ExcelBookSave($oExcel)
EndIf
_ExcelBookClose($oExcel, 0)
以上代码,当A列值有包含关系时,写入会混乱:
如A列值已有:TE8AA、TE8AB、TE8AC、TE8AD
当我要写入新值“TE8A ”时,会把表格最前面的“TE8AA”覆盖掉。
请大师解惑:
$rng = $oExcel.activesheet.Range("A1:A" & $hang).cells.find($pianhao)
要如何写代码,才能精确查找到字符串值,而不是找到有包含“需查找字符”的值?
Kevinch大师指点:
$rng = $oExcel.activesheet.Range("A1:A" & $hang).cells.find($pianhao,default,default,1)
问题解决!
xlj310大师的解读:
http://www.autoitx.com/forum.php?mod=viewthread&tid=38465&highlight=excel%2B%D5%D2$oExcel.Selection.Find($sFindWhat, $oExcel.ActiveCell, $iDataType, $iWholeOrPart, Default, Default, $fMatchCase, Default, $fMatchFormat)
Find(
$sFindWhat;"要查找的值",
$oExcel.ActiveCell;"查找的起始位置(FindNext可以用此位置作哨兵)"
$iDataType;"查找值的字符类型xlValues为-4163, xlFormulas为-4123(默认),xlComments为-4144"
$iWholeOrPart;"完全匹配Or部分匹配,1为完全,2为部分",
$SearchOrder;"以行的方式Or列的方式查找, xlByRows值1(默认), xlByColumns值2",
$SearchDirection;"查找方向,向前查找(XlPrevious值2) 向后查找(xlNext值1,默认)"
$fMatchCase;"区分大小写,默认为False"
$MatchByter;"区分全角/半角"
$fMatchFormat;"格式"
)
|
|