2016-10-25 130 views
7

我有一個使用jQuery插件Datatables的Google腳本生成網站。 我在使用Excel HYPERLINK導出到Excel函數的Datatables插件時遇到問題。jQuery Datatables導出到excelHtml5 HYPERLINK問題

我想在導出的Excel文件點擊的超鏈接,所以我格式化我的鏈接中的Javascript如下:產生

=HYPERLINK("photourl";"Photo 1") 

的Excel導出,格式爲罰款。但是,它顯示了上面的片段,而不是可點擊的鏈接。當我選擇該單元格並單擊該定義而不進行更改時,它會自動顯示可點擊的網址。

有什麼我可以做的把它變成一個可點擊的鏈接?

+0

這可能會有幫助。 http://superuser.com/questions/836324/cells-not-updating-automatically/836325 – Badr

+0

我沒有設法糾正從數據表導出。我通過從Datatable獲取所有數據並將其寫入新的電子表格,然後將該電子表格作爲Excel下載,從而解決了我的問題。 –

回答

0

一種解決方案是使用以Excel超鏈接式格式例如表達,:

= '= HYPERLINK(」 https://[my網站]的.com /' & [標識符] & ' 「」,' & [友好Excel Value] &'「)'

然後您會發現在Excel中它不會自動識別公式。要強制識別,最簡單的方法是用等號'='替換(Ctrl + H)所有等於'='。

該鏈接應該工作。

http://office.microsoft.com/en-gb/excel-help/hyperlink-function-HP010062412.aspx

https://superuser.com/questions/448376/what-is-the-excel-hotkey-to-re-calculate-all-formula-in-sheet

1

出口的Execl的是不使用任何服務器端語言非常艱難的工作,但你可以寫XML代碼到數據表導出XLS甲,我有一些工作示例 請找代碼和文件here

這是jQuery插件

和我寫的示例代碼導出文件

<html> 
     <head> 
      <meta charset="UTF-8"> 
      <link rel="stylesheet" href="css/chintanTableDesign_1.css"/> 
      <title></title> 
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
      <script src="http://eportal.esparkbiz.com/asset/js/export_execl_js/jquery.battatech.excelexport.js" language="javascript" type="text/javascript"></script> 

     </head> 
     <body> 
      <table class="tableChintan" width="100%"> 
       <tr> 
        <th colspan="10" style="font-size: 25px;text-align: center"> 
         ABC Pvt. ltd. 
        </th> 
        <th> 
         <select id="type_account" name="type_account" onchange="GetFilter();"> 
          <option value="ALL" >ALL</option> 
          <option value="AC" >AC</option> 
          <option value="CASH" >CASH</option> 
          <option value="PF" selected>PF</option>       
         </select> 
        </th> 
        <th> 
         <a id="btnExport" href="javascript:void(0);"> EXPORT</a> 
        </th> 
       </tr></table> 
      <table class="tableChintan" width="100%" id="tblExport"> 
       <tr> 
        <th>Employee Name</th> 
        <th>Month</th> 
        <th>BASIC</th> 
        <th>DA</th> 
        <th>HRA</th> 
        <th>TA</th> 
        <th>Sp Allownce</th> 
        <th>LEAVE ENCASH</th> 
        <th>abs_days</th> 
        <th>extra_days</th> 
        <th>PF EMP</th> 
        <th>PF COMP</th> 
    <!--    <th>ESI EMP</th> 
        <th>ESI COMP</th>--> 
        <th>PT</th> 
        <th>TOTAL SAL CHEQUE</th> 
        <th>actual_sal </th> 
        <th>actual_sal WP</th> 
        <th>NA</th> 
        <th></th> 

       </tr> 
       </tr></table>  
    </table> 
     </body> 
    </html> 

    <script type="text/javascript"> 
     $(document).ready(function() { 
      $("#btnExport").click(function() { 
       $("#tblExport").btechco_excelexport({ 
        containerid: "tblExport" 
        , datatype: $datatype.Table 
       }); 
      }); 

     }); 
</script> 

請不要忘了,包括您的jquery.min.js

請不要嘗試,如果你想強行重命名文件,然後讓我知道我有同樣的

另一個jQuery插件享受!!!!!!!!!!!!

0

我希望我的解決方案能夠幫助某人將excel導出中的鏈接擴展到已經非常有用的庫文件夾 。

經過數小時的搜索後,我發現很多人在Excel導出的鏈接和Datatables論壇中尋找解決方案。

主要問題是默認導出只有兩種不同的格式被考慮。數字和內聯字符串。 鏈接既不是內聯字符串,也不是數字,它是一個函數,女巫需要類型。

在我尋找解決方案時,我發現很多有用的部分。

  1. 您必須調整導出,爲此已提供「自定義」選項。 https://datatables.net/extensions/buttons/examples/html5/excelTextBold.html 在此示例中,列C中的所有單元格均被考慮。我們想要遍歷所有單元格,並在那裏找到可能的URL。

  2. 我們想用公式替換鏈接。默認情況下,它具有單元格類型inlinesting,這必須由類型str和用作值的公式替換。 感謝Dzyann,他展示了它的工作原理。 https://datatables.net/forums/discussion/42097/can-you-export-a-table-and-format-a-cell-to-use-a-formula-using-orthogonal-data

  3. 要強調鏈接,應該提供格式[4]。 列出可用的格式:https://datatables.net/reference/button/excelHtml5#Built-in-styles

我的解決方案,爲我的工作要求:

// (1.) customize export 
    customize: function(xlsx) { 

     var sheet = xlsx.xl.worksheets['sheet1.xml']; 

     // Loop over all cells in sheet 
     $('row c', sheet).each(function() { 

      // if cell starts with http 
      if ($('is t', this).text().indexOf("http") > -1) { 

       // (2.) change the type to `str` which is a formula 
       $(this).attr('t', 'str'); 
       //append the formula 
       $(this).append('<f>' + 'HYPERLINK("'+$('is t', this).text()+'","'+$('is t', this).text()+'")'+ '</f>'); 
       //remove the inlineStr 
       $('is', this).remove(); 
       // (3.) underline 
       $(this).attr('s', '4'); 
      } 
     }); 
}