配色: 字号:
excel自定义拆分文本函数
2021-07-02 | 阅:  转:  |  分享 
  
''鍏ㄥ眬瀹氫箟鑷畾涔夊嚱鏁帮紝涓や釜鍙傛暟瑕佺敵鏄?
PublicFunctionsplitext(strContentAsString,varTypeAsVariant)

''瀹氫箟鍙橀噺

DimobjRegAsObject

DimobjFoundAsObject

DimtextPatternAsString

Dimarr



SetobjReg=CreateObject("vbscript.regexp")

varType=LCase(varType)

''璁剧疆鍒ゆ柇鍙婂搴旂殑姝e垯琛ㄨ揪寮?
SelectCasevarType

Case1,"鏁板瓧"

textPattern="-?\d+(\.\d+)?"

Case2,"鑻辨枃瀛楁瘝"

textPattern="[a-z]+"

Case3,"涓枃"

textPattern="[\u4e00-\u9fa5]+"

EndSelect



WithobjReg

.Global=True

.IgnoreCase=True

.Pattern=textPattern



SetobjFound=.Execute(strContent)



EndWith



IfobjFound.Count=0Then

splitext=""

ExitFunction

EndIf



ReDimarr(0ToobjFound.Count-1)

ForEachcellInobjFound

arr(i)=objFound(i)

i=i+1

Next



splitext=arr

SetobjReg=Nothing

SetobjFound=Nothing



''瀹冪殑浣滅敤灏辨槸鎻愬彇瀛楃涓蹭腑闇€瑕佺殑瀛楃锛岃娉曚负锛歴plitext(strContent,varType)锛?缁撴灉浼氶粯璁よ繑鍥炴壘鍒扮殑绗竴涓瓧绗︼紝濡傛灉鏈夊涓悓绫诲瀷鐨勫瓧绗︼紝鍙互閰嶅悎index鍑芥暟浣跨敤



''varType鍙傛暟涓?鏃讹紝鎻愬彇锛氭暟瀛楋紝涓?鏃讹紝鎻愬彇鑻辨枃锛屼负3鏃讹紝鎻愬彇姹夊瓧



EndFunction



献花(0)
+1
(本文系lxpi83h2mnl...首藏)