以下是引用gouweicao78在2008-7-22 2:05:29的发言:要说“最快”,《精粹》中定义名称的方法是目前最快的,测试5000条公式速度0.109秒。 黄兄第1条公式16.688秒,下面我给个解法,0.984秒: =--TEXT(SUM((MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A$1,"月"," "),"日",),{1,2,3,4,6,8},{1,1,1,1,2,5})),TEXT(ROW($1:$32)-1,"[dbnum1]d"),)-1)*10^{7,6,5,4,2,0}),"#-00-00") 共165字,如果要考虑“元月”,再增加20字符。速度1.016秒。也取个自己熟悉的诨号“庖丁解牛”,将字符分解开来,年份一个字一个字得查找,月份、日期分开查找,速度赢在ROW($1900:$2100)、ROW($1:$366)这两个数组大户上。而且,适用日期到9999-12-31。 把老师的公式再脱去一层"外衣"(少用一次SUBSTITUTE函数),给公式再减减肥(共152字): =--TEXT(SUM((MATCH(TRIM(MID(SUBSTITUTE(A3,"月","日 "),{1,2,3,4,6,9},{1,1,1,1,2,4})&"*"),TEXT(ROW($1:$32)-1,"[dbnum1]d日"),)-1)*10^{7,6,5,4,2,0}),"#-00-00") 目前,除了我原来那个短但巨慢的公式以及原精粹的解法除外,现将目前又新增的解法归纳如下: 130字符 偷梁换柱法: =--(1899+MATCH(LEFT(A1,4),TEXT(ROW($1900:$2100),"[dbnum1]0"),)&TEXT(MATCH(MID(A1,6,8),TEXT(ROW($1:$366),"[dbnum1]m月d日"),),"-m-d")) 150字符 =--(1899+MATCH(LEFT(B1,4),TEXT(ROW($1900:$2100),"[dbnum1]0"),)&TEXT(MATCH(SUBSTITUTE(MID(B1,6,8),"元","一"),TEXT(ROW($1:$366),"[dbnum1]m月d日"),),"-m-d")) 164字符 替换法: =--TEXT(SUM((MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(A1,"月"," "),"日",),{1,2,3,4,6,9},{1,1,1,1,2,4})),TEXT(ROW($1:$32)-1,"[dbnum1]d"),)-1)*10^{7,6,5,4,2,0}),"#-00-00") 148字符 替换法加偷梁换柱法: =SUM((MATCH(MID(A1,{1,2,3,4},1),TEXT(ROW($1:$10)-1,"[dbnum1]"),)-1)*10^{3,2,1,0})&TEXT(MATCH(MID(A1,6,8),TEXT(ROW($1:$366),"[dbnum1]m月d日"),),"-m-d") 217字符 两步替换法: =--(SUM((MATCH(MID(A3,{1,2,3,4},1),TEXT(ROW($1:$10)-1,"[dbnum1]"),)-1)*10^{3,2,1,0})&""&TEXT(SUM((MATCH(TRIM(MID(SUBSTITUTE(MID(A3,6,8),"月","日 "),{1,4},{3,5})),TEXT(ROW($1:$32)-1,"[dbnum1]d日"),)-1)*10^{2,0}),"-#-00")) 152字符 简化替换法: =--TEXT(SUM((MATCH(TRIM(MID(SUBSTITUTE(A3,"月","日 "),{1,2,3,4,6,9},{1,1,1,1,2,4})&"*"),TEXT(ROW($1:$32)-1,"[dbnum1]d日"),)-1)*10^{7,6,5,4,2,0}),"#-00-00") 172字符 =--TEXT(SUM((MATCH(TRIM(MID(SUBSTITUTE(SUBSTITUTE(B1,"月","日 "),"元","一"),{1,2,3,4,6,9},{1,1,1,1,2,4})&"*"),TEXT(ROW($1:$32)-1,"[dbnum1]d日"),)-1)*10^{7,6,5,4,2,0}),"#-00-00")
dlQk7xe6.rar
(8.54 KB, 下载次数: 108)
[此贴子已经被作者于2008-10-15 19:56:01编辑过] |