2016-10-25 220 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'); 
      } 
     }); 
}