2017-04-07 40 views
0

有沒有辦法從單元中獲取超鏈接或任何公式?Google Sheet API沒有PHP庫中的CellEntry的getFormulaR1C1

基本上,在工作表中我有一個帶有超鏈接公式的單元格(= HYPERLINK('http://blabla.com','link1'))。當我試圖獲得這個單元格的價值時,它只給我看到可見的內容('link1')。有沒有其他的方式來公式,而不是可見的內容?

enter image description here

+0

什麼API調用? –

+0

這裏是我的依賴關係:「asimlqt/php-google-spreadsheet-client」:「2. *」,「google/apiclient」:「1. *」 –

回答

0

有似乎是一個辦法做到這一點使用Google Apps腳本(無論你正在使用PHP等等..)在此SO thread提到:您正在使用

function getURL() { 
    var range = SpreadsheetApp.getActiveSheet().getActiveCell(); 

    //logs - Google 
    Logger.log(range.getValue()); 

    //logs - =HYPERLINK("http://www.google.com", "Google") 
    Logger.log(range.getFormulaR1C1()); 

    //simple regex to get first quoted string 
    var url = /"(.*?)"/.exec(range.getFormulaR1C1())[1]; 

    //logs - http://www.google.com 
    Logger.log(url); 
} 
+1

它應該在Sheets V4 API中得到很好的支持。只需要請求valueRenderOption = FORMULA,然後按照您描述的方式解析結果。 –

+1

或者,您可以使用spreadsheets.get並從CellData中獲取值,這裏有一個「超鏈接」字段和一個「有效值」值。一個應該有URL和另一個顯示字符串。感謝山姆 –

+0

,你可以發表回答 – noogui