2015-06-04 34 views
1

您好我正在嘗試編寫一個谷歌電子表格自定義函數。它收到一個範圍並吐出乾淨的rootdomain。我只是遇到了「太多的處決」 - 我必須在整張表格上運行它。所以我增加了一個範圍。谷歌電子表格自定義功能代碼不工作:= RootDomain

現在反饋是「內部錯誤功能」 ......

幫助表示讚賞....這必須是可能的!

/** 
* Generates clean root domains 
* 
* @param {input} input The value to change to a root domain. 
* @return The clean root domain. 
* @RootDomain 
*/ 
function RootDomain(input) { 
    if (input == null) return ''; 
    if (input.map) {   // Test whether input is an array. 
    return input.map(RootDomain); // Recurse over array if so. 
    } else { 
    if (input = '') return ''; 
    regex = new RegExp(/((www)\.)?.*(\w+)\.([\w\.]{2,6})/); 
    return regex.exec(input)[0].replace(/^http(s)?:\/\//i, "").replace(/^www\./i, "").replace(/\/.*$/, ""); 
    } 
} 
+0

變化**如果(輸入= '')返回 ''; **的**,如果(輸入=== '')返回 ''; * *。當您僅使用一個'='號時,您正在將**輸入**設置爲空 –

+0

THX!問題是,有三個===它比較字符串,但如果INPUT爲空(當沒有輸入或單元格爲空時)會發生什麼 – SNH

+0

不,用===它會檢查輸入是否爲空。你在做什麼是做你不想要的輸入。 –

回答

1

而是執行此操作:

function RootDomain(input) { 
    if (input == null || input === '') { 
    return ''; 
    } else if (input.map) {   // Test whether input is an array. 
    return input.map(RootDomain); // Recurse over array if so. 
    } 
    var regex = new RegExp(/((www)\.)?.*(\w+)\.([\w\.]{2,6})/); 
    return regex.exec(input)[0].replace(/^http(s)?:\/\//i, "").replace(/^www\./i, "").replace(/\/.*$/, ""); 
    } 
+0

適用於1單元。現在做了:= rootdomain(D2:D10000 ),因爲否則我們會遇到一個計算問題「計算太多」或什麼的,現在的錯誤是#REF – SNH

+0

爲什麼你甚至要做100000行? –