I am using react-html-to-excel
to convert my table to excel but what I want is to not to export the first column to excel i.e the first column should not exported t
You can create a simple hack to manipulate the table HTML code by overriding the ReactHTMLTableToExcel.format function which gets the table HTML to format the XLS document.
ReactHTMLTableToExcel.format = (s, c) => {
// If there is a table in the data object
if (c && c['table']) {
// Get the table HTML
const html = c.table;
// Create a DOMParser object
const parser = new DOMParser();
// Parse the table HTML and create a text/html document
const doc = parser.parseFromString(html, 'text/html');
// Get all table rows
const rows = doc.querySelectorAll('tr');
// For each table row remove the first child (th or td)
for (const row of rows) row.removeChild(row.firstChild);
// Save the manipulated HTML table code
c.table = doc.querySelector('table').outerHTML;
}
return s.replace(/{(\w+)}/g, (m, p) => c[p]);
};
And you've got the table HTML filtered and with the first column removed.
You can check this working in this Stackblitz project.