Excel处理数据

最近遇到一些批量处理用户数据的问题,然后发现了excel处理数据挺方便,虽然也可以写java方法。excel处理直接丢数据库更直接,所以我走捷径了。和代码逻辑差不多,方法也很好理解,Replace、if、LCase一些函数用起来类似。

VBA脚本方法 处理中文转拼音首字母

Function pinyin(p As String) As String
i = Asc(p)
Select Case i
Case -20319 To -20284: pinyin = "A"
Case -20283 To -19776: pinyin = "B"
Case -19775 To -19219: pinyin = "C"
Case -19218 To -18711: pinyin = "D"
Case -18710 To -18527: pinyin = "E"
Case -18526 To -18240: pinyin = "F"
Case -18239 To -17923: pinyin = "G"
Case -17922 To -17418: pinyin = "H"
Case -17417 To -16475: pinyin = "J"
Case -16474 To -16213: pinyin = "K"
Case -16212 To -15641: pinyin = "L"
Case -15640 To -15166: pinyin = "M"
Case -15165 To -14923: pinyin = "N"
Case -14922 To -14915: pinyin = "O"
Case -14914 To -14631: pinyin = "P"
Case -14630 To -14150: pinyin = "Q"
Case -14149 To -14091: pinyin = "R"
Case -14090 To -13319: pinyin = "S"
Case -13318 To -12839: pinyin = "T"
Case -12838 To -12557: pinyin = "W"
Case -12556 To -11848: pinyin = "X"
Case -11847 To -11056: pinyin = "Y"
Case -11055 To -2050: pinyin = "Z"
Case Else: pinyin = p
End Select
End Function
Function getpy(str)
For i = 1 To Len(str)
getpy = Replace(LCase(getpy & pinyin(Mid(str, i, 1)))," ","")
Next i
End Function

#方法使用
=getpy(A1)

1.在B列查找C列数据,返回对应的A列数据

#返回最先找到的:
=INDIRECT("A"&MATCH(C2,B:B,0))
=MATCH(C2,B:B,)-1
{=MATCH(1,1/(B$2:B$22=C2))}
#返回最后找到的:
=LOOKUP(1,0/(B$2:B$22=C2),A$2:A$22)
=LOOKUP(1,0/(B$2:B$22=C2),ROW($1:$22))
{=MATCH(1,0/(B$2:B$22=C2))}
{=MATCH(1,0/(C2=B$2:B$22),1)}
=MATCH(1,FREQUENCY(C2,B$2:B$22+1/ROW($3:$23)),)
#按出现的先后顺序返回:
{=MATCH(COUNTIF(C$2:C2,C2),COUNTIF(OFFSET(B$2,,,ROW($1:$22)),C2),)}
{=MIN(IF(COUNTIF(OFFSET(B$2,,,COLUMN(A:OV)),C2)=COUNTIF(C$2:$C2,C2),COLUMN(A:OV)))}
{=SMALL(IF(B$2:B$22=C2,A$2:A$22),COUNTIF(C$2:C2,C2))}
{=SMALL(IF(B$2:B$22=C2,ROW($1:$21)),COUNTIF(C$2:C2,C2))}
=LOOKUP(COUNTIF(C$2:C2,C2)-1,COUNTIF(OFFSET(B$1,,,ROW($1:$23)),C2),ROW($1:$22))
=SMALL(IF(C2=B$2:B$22,ROW($3:$23)-2,""),COUNTIF(C$2:C2,C2))