Knowledge base data export to excel-use JavaScript to export Excel files in the browser

Our intelligent customer service knowledge base robot has been developed. The back-end database is the qdrant vector database, but the database does not have an export backup function, so I export the excel data from the knowledge base according to the simple pure front-end implementation.

Use a third-party library like SheetJS SheetJS is a popular JavaScript library that helps in working with Excel files. You can use SheetJS to export data to Excel files.

First, add the CDN link for the SheetJS library to your HTML file:

<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>

html part

<button onclick="exportToExcel()">Export to Excel</button>

JavaScript:

function exportToExcel() {
  const data = [
    ['Name', 'Age', 'Email'],
    ['John Doe', 30, '[email protected]'],
    ['Jane Smith', 25, '[email protected]'],
  ];

  const worksheet = XLSX.utils.aoa_to_sheet(data);
  const workbook = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
  XLSX.writeFile(workbook, 'data.xlsx');
}

Implement the following functions

Guess you like

Origin blog.csdn.net/taoshihan/article/details/131863310