Export HTML Table To Excel(XLS) With Bold Headers

Export HTML Table To Excel(XLS) With Bold Headers

Just another jQuery based Table To Excel converter which exports your html table to an XLS file with bold column headers.

1. Your html table must have <thead> and <tbody> tags as these:

<table class="table">
  <thead>
    <tr>
      <th>Header content 1</th>
      <th>Header content 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Body content 1</td>
      <td>Body content 2</td>
    </tr>
    <tr>
      <td>Body content 3</td>
      <td>Body content 4</td>
    </tr>
    <tr>
      <td>Body content 5</td>
      <td>Body content 6</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td>Footer content 1</td>
      <td>Footer content 2</td>
    </tr>
  </tfoot>
</table>

2. Load the JavaScript file tableexport-xls-bold-headers.js after the latest jQuery library.

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" 
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
        crossorigin="anonymous">
</script>
<script src="tableexport-xls-bold-headers.js"></script>

3. Call the plugin to download the generated XLS file.

$('table').tableExport({
  filename: 'example.xls'
});

4. Sometimes you might need to set the columns to ignore.

$('table').tableExport({
  filename: 'example.xls',
  ignoreColumn: [0, 1]
});

5. Decide whether to ignore escape and html content.

$('table').tableExport({
  escape: 'true',
  htmlContent: 'false'
});

This awesome jQuery plugin is developed by carlopantaleo. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 09.03.2018
  • Source