SOLUTION

You can use $() method to get access to all rows even not present in DOM and construct a new table using these rows. Then you can execute table2excel() on a newly constructed table to get Excel file that contains all rows.

For example:

$(function() {
   var startDate = $(".startDate").val();
   var endDate = $(".endDate").val();

   $("#exportExcel").click(function(){
      $('<table>')
         .append(
            $("#table_id").DataTable().$('tr').clone()
         )
         .table2excel({
            exclude: ".excludeThisClass",
            name: "Worksheet Name",
            filename: "SomeFile" //do not include extension
         });
   });

   $("#table_id").dataTable();
});

DEMO

See this page for code and demonstration.

NOTES

Excel 2013 displays the following error when opening the file produced by table2excel.js.

Excel cannot open the file [filename] because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

Because of this error, I would rather use DataTables TableTools plug-in instead even though it can only produce CSV files and also uses Flash.

Answer from Gyrocode.com on Stack Overflow
🌐
DataTables
datatables.net › extensions › buttons › examples › initialisation › export.html
DataTables example - File export
new DataTable('#example', { layout: { topStart: { buttons: ['copy', 'csv', 'excel', 'pdf', 'print'] } } }); In addition to the above code, the following Javascript library files are loaded for use in this example: The HTML shown below is the raw HTML table element, before it has been enhanced ...
🌐
Bootsnipp
bootsnipp.com › snippets › yyoZ1
Bootstrap Snippet Bootstrap 4 - DataTables with PDF, Excel Export Feature using HTML CSS Bootstrap jQuery
$(document).ready(function() { $('#table_id').DataTable({ dom: 'Bfrtip', responsive: true, pageLength: 25, // lengthMenu: [0, 5, 10, 20, 50, 100, 200, 500], buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print' ] }); });
🌐
Bootstrap Table
bootstrap-table.com › docs › extensions › export
Table Export · Bootstrap Table
Export data type, support: 'basic', 'all', 'selected'. ... Set true to export the table footer. ... Export types, support types: ['json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'xlsx', 'pdf'].
🌐
Bbbootstrap
bbbootstrap.com › home › snippets › bootstrap 4 export table to excel file
Bootstrap 4 Export table to excel file Example
Bootstrap 4 Export table to excel file snippet for your project 📌📌. this snippet is created using HTML, CSS, Bootstrap 4, Javascript
🌐
DataTables
datatables.net › extensions › buttons › examples › styling › bootstrap4.html
DataTables example - Bootstrap 4
Javascript · HTML · CSS · Ajax · Server-side script · Comments · The Javascript shown below is used to initialise the table shown in this example: $('#example').DataTable({ layout: { topStart: { buttons: ['copy', 'excel', 'pdf', 'colvis'] } } }); new DataTable('#example', { layout: { ...
🌐
GitHub
github.com › shubhamgt2 › bootstrap-4-responsive-datatable-and-export-to-pdf-csv › blob › master › index.html
bootstrap-4-responsive-datatable-and-export-to-pdf-csv/index.html at master · shubhamgt2/bootstrap-4-responsive-datatable-and-export-to-pdf-csv
<script src="https://cdn.datatables.net/responsive/2.2.3/js/responsive.bootstrap4.min.js"></script> <script> $(document).ready(function() { var table = $('#example').DataTable( { lengthChange: false, buttons: [ 'copy', 'excel', 'csv', 'pdf', 'colvis' ] } ); ·
Author   shubhamgt2
🌐
Prepbootstrap
prepbootstrap.com › bootstrap-template › table-export-to-excel
Export a Table to Excel Template | PrepBootstrap
This template shows a standard Bootstrap table containing some data, which is parsed by the ShieldUI's DataSource widget and exported to Excel using the Excel Export functionality provided by the same library.
Find elsewhere
🌐
YouTube
youtube.com › watch
Bootstrap v5 Data Table. Export Table Data in Excel, PDF, CSV, Print and Copy. - YouTube
In this tutorial, I'm going to show you how to use Bootstrap5 Data Table in a very easy way and how to Export Table Data in Copy, CSV, Excel, PDF and Print. ...
Published   April 1, 2024
🌐
GitHub
github.com › fg1998 › bootstrapExcelExport
GitHub - fg1998/bootstrapExcelExport: Bootstrap plugin to export html tables to excel · GitHub
This is a simple usage plugin to export HTML <table> to excel files. In fact, alow user to save html data to disk as a .xls file. It was developed with Twitter Bootstrap in mind, but you can use with regular html tables instead.
Starred by 4 users
Forked by 2 users
Languages   HTML
🌐
DataTables
datatables.net › extensions › buttons › examples › styling › bootstrap.html
DataTables example - Bootstrap 3
Javascript · HTML · CSS · Ajax · Server-side script · Comments · The Javascript shown below is used to initialise the table shown in this example: $('#example').DataTable({ layout: { topStart: { buttons: ['copy', 'excel', 'pdf', 'colvis'] } } }); new DataTable('#example', { layout: { ...
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
How to export data table to excel - Material Design for Bootstrap
General Bootstrap questions · Topic: How to export data table to excel · Mankongwatcharakul priority asked 6 years ago · I use datatable.net and I need to export to excel Could you help me please? Add comment · Jakub Mandra staff answered 6 years ago · 0 0 Best answer ·
Top answer
1 of 2
4

You have this package: https://www.npmjs.com/package/xlsx In your html, create a button and with the @click="exportInvoiceButton()". That's one of the way you can do it in Frontend, but, alternatively, and probably the best way to do this export is from the backend, so you can have more flexibility of what to export.

import XLSX from 'xlsx';    
//...
methods: {
        //...
        exportInvoiceButton() {
            const invoices = this.invoices.reduce((ac, invoice) => { 
                ac.push({ 
                    billing_sku_id: invoice.billing_sku_id, 
                    billing_sku_name: invoice.billing_sku_name,
                    total_units: invoice.total_units,
                    // ...
                }); 
                return ac;
            }, [])
    
            var invoicesWS = XLSX.utils.json_to_sheet(invoices)
    
            // A workbook is the name given to an Excel file
            var wb = XLSX.utils.book_new() // make Workbook of Excel
    
            // add Worksheet to Workbook
            // Workbook contains one or more worksheets
            XLSX.utils.book_append_sheet(wb, invoicesWS, 'Invoices list') // invoices list is name of Worksheet
    
    
            // export Excel file
            XLSX.writeFile(wb, 'Invoices.xlsx')
    
        }
        //...
    }
2 of 2
3

I found a solution with the help of vue-html2pdf package. First I created a separate component called TableCompo and the code of it comes here:

TableCompo.vue:

<template>
  <div id="tableMe">
    <b-table-simple outlined id="htmltable">
      <b-thead class="b-table__head">
        <b-tr>
          <b-th class="small-tab">Goods</b-th>
          <b-th>Units</b-th>
          <b-th>Price Per Unit</b-th>
          <b-th>Total Price</b-th>
        </b-tr>
      </b-thead>
      <b-tbody v-for="(service, index) in goodsGroupedByCategory" :key="index">
        <b-tr class="category-line">
          <b-th class="small-tab cs-textstyle-paragraph-small-bold">{{
              index
            }}</b-th>
          <b-td></b-td>
          <b-td></b-td>
          <b-th class="cs-textstyle-paragraph-small-bold">{{
              service.reduce(function (prev, curr) {
                return prev + curr.total_units * curr.price_per_unit;
              }, 0)
            }}</b-th>
        </b-tr>
        <b-tr
            v-for="serviceItem in service"
            :key="serviceItem.id"
            class="item-line"
        >
          <b-td class="big-tab cs-textstyle-paragraph-small">{{
              serviceItem.billing_sku_name
            }}</b-td>
          <b-td class="cs-textstyle-paragraph-small">{{
              serviceItem.total_units
            }}</b-td>
          <b-td class="cs-textstyle-paragraph-small">{{
              serviceItem.price_per_unit
            }}</b-td>
          <b-td class="cs-textstyle-paragraph-small">{{
              serviceItem.total_units * serviceItem.price_per_unit
            }}</b-td>
        </b-tr>
      </b-tbody>
    </b-table-simple>
  </div>
</template>

<script>
import _ from "lodash";

export default {
  name: "TableCompo",
  data() {
    return {
      invoice: [
        {
          id: "123",
          billing_sku_id: "FOOD_ITEMS",
          billing_sku_name: "Rice",
          total_units: 1,
          billing_sku_category: "Food Items",
          price_per_unit: 3,
        },
        {
          id: "456",
          billing_sku_id: "FOOD_ITEMS",
          billing_sku_name: "Wheat",
          total_units: 3,
          billing_sku_category: "Food Items",
          price_per_unit: 5,
        },
        {
          id: "789",
          billing_sku_id: "ELECTRICITY_ITEMS",
          billing_sku_name: "Bulb",
          total_units: 5,
          billing_sku_category: "Electricity Items",
          price_per_unit: 50,
        },
      ],
    };
  },
  computed: {
    goodsGroupedByCategory() {
      return _.groupBy(this.invoice, "billing_sku_category");
    },
  },
}
</script>

<style scoped>
#tableMe {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
  padding: 10px;
}
</style>

After that I created a parent component (or a view) that using this component and vue-html2pdf package to export the content of table as pdf:

TableView.vue:

<template>
  <div>
    <b-button @click="generateReport" class="mb-3">Export</b-button>
    <!-- first usage of table component: this is for showing the table in browser for users -->
    <table-compo></table-compo>

    <vue-html2pdf
        :show-layout="false"
        :float-layout="true"
        :enable-download="true"
        :preview-modal="false"
        :paginate-elements-by-height="1400"
        filename="my-table"
        :pdf-quality="2"
        :manual-pagination="false"
        pdf-format="a5"
        pdf-orientation="landscape"
        pdf-content-width="100%"
        ref="html2Pdf"
    >
      <section slot="pdf-content">
      <!-- second usage of table component: this is for putting the contents of table to final pdf  -->
        <table-compo></table-compo>
      </section>
    </vue-html2pdf>
  </div>
</template>

<script>
import VueHtml2pdf from 'vue-html2pdf';
import TableCompo from '../components/TableCompo'
export default {
  name: "TableView",
  components: {
    VueHtml2pdf,
    TableCompo
  },
  methods: {
    /*
        Generate Report using refs and calling the
        refs function generatePdf()
    */
    generateReport () {
      this.$refs.html2Pdf.generatePdf();
    }
  },
}
</script>

<style scoped>

</style>

If you are not happy with my settings, see the documentation of that package to find your desired settings.

🌐
DataTables
datatables.net › download
Download
Required for the Excel HTML5 export button. ... Required for the PDF HTML5 export button. ... Button that will display a printable view of the table. ... Click-and-drag column reordering. ... Column specific buttons and search controls. ... Date picker used in Editor, SearchBuilder and other components for DataTables.
🌐
Rip Tutorial
riptutorial.com › add export buttons to table in bootstrap 4
datatables Tutorial => Add export buttons to table in Bootstrap 4
You can export your table data to excel, pdf or copy it to the clipboard. This manual is intended for the bootstrap 4 framework.
🌐
YouTube
youtube.com › shubham gupta
Bootstrap 4 Responsive Datatable Export to PDF, CSV - YouTube
In this video, I will show you how to create responsive Data Table with Bootstrap 4 and export it to CSV, PDF.References:https://datatables.net/extensions/re...
Published   August 21, 2018
Views   24K
🌐
DataTables
datatables.net › extensions › buttons › examples › styling › bootstrap5.html
DataTables example - Bootstrap 5
Javascript · HTML · CSS · Ajax · Server-side script · Comments · The Javascript shown below is used to initialise the table shown in this example: $('#example').DataTable({ layout: { topStart: { buttons: ['copy', 'excel', 'pdf', 'colvis'] } } }); new DataTable('#example', { layout: { ...
🌐
JSFiddle
jsfiddle.net › opchggs3 › 3
jquery datatable export table to PDF/Excel demo - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
🌐
CodePen
codepen.io › GiSmo › pen › pbjzXw
Datatables buttons export excel
$(document).ready(function() { var table = $('#example').DataTable({ dom: 'Bfrtip', buttons: [ { extend: 'excel', text: 'Export excel', className: 'exportExcel', filename: 'Export excel', exportOptions: { modifier: { page: 'all' } } }, { extend: 'copy', text: '<u>C</u>opie presse papier', className: 'exportExcel', key: { key: 'c', altKey: true } }, { text: 'Alert Js', className: 'exportExcel', action: function(e, dt, node, config) { alert('Activated!'); // console.log(table); // new $.fn.dataTable.Buttons(table, { // buttons: [{ // text: 'gfdsgfsd', // action: function(e, dt, node, config) { // alert('ok!'); // } // }] // }); } }] }); });
🌐
Stack Overflow
stackoverflow.com › questions › 62889534 › export-all-records-to-excel-from-bootstrap-table
jquery - Export all records to excel from bootstrap table - Stack Overflow
<script src="~/wwwroot/plugins...ns/bootstraptable/extensions/export/tableExport.js"></script> ... You can set the exportDataType table option to all....