亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

停止 table2excel 在導出的 excel 中將比率值(如 50:10)視為時間

停止 table2excel 在導出的 excel 中將比率值(如 50:10)視為時間

千巷貓影 2023-02-24 17:50:49
我有一個 html 表,其中包含一些列值作為字符串以及比率數字 (50:10、60:30)我的問題是當我使用 table2excel 導出它時,一些比率值被視為時間。見下圖:我的出口代碼:$("#pat_inj_table").table2excel({    name: "Report",    filename: name,});我在table2excel文檔中找到了這段代碼,我認為它對解決我的問題很有用:Table2Excel.extend((cell, cellText) => {  // {HTMLTableCellElement} cell - The current cell.  // {string} cellText - The inner text of the current cell.  // cell should be described by this type handler  if (selector) return {    t: ...,    v: ...,  };  // skip and run next handler  return null;});但我不知道如何使用上面的代碼。
查看完整描述

1 回答

?
12345678_0001

TA貢獻1802條經驗 獲得超5個贊

有兩種方法可以識別處理程序中的單元格。


在每個單元格上添加屬性(例如,<td type="string">10:20</td>)并根據該屬性識別數據

Table2Excel.extend((cell, cellText) => {

  return $(cell).attr('type') == 'string' ? {

    t: 's',

    v: cellText

  } : null;

});

var table2excel = new Table2Excel({

  defaultFileName: "myFile"

});

table2excel.export($(".table"));

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type="text/javascript" src="https://rusty1s.github.io/table2excel/dist/table2excel.js"></script>

<table class="table" excel-name="excel-name">

  <thead>

    <tr>

      <th>#</th>

      <th>Column heading</th>

      <th>Column heading</th>

      <th>Column heading</th>

    </tr>

  </thead>

  <tbody>

    <tr class="active">

      <td>1</td>

      <td type="string">10:20</td>

      <td>Column content</td>

      <td>Column content</td>

    </tr>

  </tbody>

</table>

使用正則表達式解析已知格式的數據并使用它來識別單元格

Table2Excel.extend((cell, cellText) => {

  return cellText && /\d+:\d+/gi.test(cellText) ? { t: 's', v: cellText } : null;

});

var table2excel = new Table2Excel({

  defaultFileName: "myFile"

});

table2excel.export($(".table"));

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type="text/javascript" src="https://rusty1s.github.io/table2excel/dist/table2excel.js"></script>

<table class="table" excel-name="excel-name">

  <thead>

    <tr>

      <th>#</th>

      <th>Column heading</th>

      <th>Column heading</th>

      <th>Column heading</th>

    </tr>

  </thead>

  <tbody>

    <tr class="active">

      <td>1</td>

      <td type="string">10:20</td>

      <td>Column content</td>

      <td>Column content</td>

    </tr>

  </tbody>

</table>

看看這個jsFiddle 演示。



查看完整回答
反對 回復 2023-02-24
  • 1 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號