将引导表内容导出为ex​​cel

时间:2016-08-18 06:42:33

标签: javascript jquery excel twitter-bootstrap

我写了一个带有一些内容的bootstrap表,如图所示。我编写了一个代码来将表导出为ex​​cel。但是,excel包含表的html部分,包括内容。我只想要在excel中出现内容。我怎样才能重写我的代码来做到这一点?



$('#export').click(function() {
  window.open('data:application/vnd.ms-excel,' + $('#table').html());
  e.preventDefault();
});

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row" id="table">
  <table class="table table-bordered">
    <tbody>
      <tr>
        <td><b>Event name</b></td>
        <td>Event 1</td>
        <td></td>
      </tr>
      <tr>
        <td><b>Registrar name</b></td>
        <td>Moe</td>
        <td></td>
      </tr>
      <tr>
        <td><b>From</b></td>
        <td>08/18/2016 9:00 AM</td>
        <td></td>
      </tr>
      <tr>
        <td><b>To</b></td>
        <td>08/19/2016 12:00 AM</td>
        <td></td>
      </tr>
      <tr>
        <td><b>Amount collected</b></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>Cash</td>
        <td>USD 2,200.00</td>
        <td></td>
      </tr>
      <tr>
        <td>Credit</td>
        <td>USD 4,050.00</td>
        <td></td>
      </tr>
      <tr>
        <td>AR</td>
        <td>USD 4,400.00</td>
        <td></td>
      </tr>
      <tr>
        <td>FOC</td>
        <td>USD 0.00</td>
        <td></td>
      </tr>
      <tr>
        <td>Transfer</td>
        <td>USD 0.00</td>
        <td></td>
      </tr>
      <tr>
        <td><b>Total</b></td>
        <td>USD 10,650.00</td>
        <td></td>
      </tr>
      <tr>
        <td><b>Ticket issued</b></td>
        <td></td>
        <td><b>Total</b></td>
      </tr>
      <tr>
        <td>Cash - 550 USD</td>
        <td>4</td>
        <td>USD 2,200.00</td>
      </tr>
      <tr>
        <td>Credit card - 450 USD</td>
        <td>9</td>
        <td>USD 4,050.00</td>
      </tr>
      <tr>
        <td>AR - 550 USD</td>
        <td>8</td>
        <td>USD 4,400.00</td>
      </tr>
      <tr>
        <td>FOC</td>
        <td>0</td>
        <td>USD 0.00</td>
      </tr>
      <tr>
        <td>Transfer</td>
        <td>0</td>
        <td>USD 0.00</td>
      </tr>
      <tr>
        <td><b>Total</b></td>
        <td><b>0</b></td>
        <td><b>USD 10,650.00</b></td>
      </tr>
    </tbody>
  </table>
  <input type="button" class="btn btn-primary" id="export" value="Export to Excel">
</div>
&#13;
&#13;
&#13;

JSFiddle:https://jsfiddle.net/ok26s32c/

0 个答案:

没有答案