Làm cách nào để đọc tệp excel lớn trong NodeJs?
Để đọc dữ liệu bảng tính và sau đó chuyển đổi nó thành một mảng các đối tượng JSON, hãy chuyển tùy chọn import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })6 khi gọi import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })7. Trong trường hợp đó, thay vì trả về một mảng các hàng ô, nó sẽ trả về một đối tượng có hình dạng import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })8 trong đó import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })9 sẽ là một mảng các đối tượng JSON được tạo từ dữ liệu bảng tính theo import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })6 và const readXlsxFile = require('read-excel-file/node') // File path. readXlsxFile('/path/to/file').then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // Readable Stream. readXlsxFile(fs.createReadStream('/path/to/file')).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // Buffer. readXlsxFile(Buffer.from(fs.readFileSync('/path/to/file'))).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })1 sẽ là một mảng gồm Show
Mỗi thuộc tính của một đối tượng JSON phải được mô tả bằng một "mục nhập" trong import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })6. Khóa của mục nhập phải là tiêu đề của cột trong bảng tính. Giá trị của mục nhập phải là một đối tượng có thuộc tính
phụ lục. Theo mặc định, khi chuyển đổi các giá trị ô thành thuộc tính đối tượng, nó sẽ bỏ qua tất cả các giá trị import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })47 (bỏ qua tất cả các ô trống). Đó là vì sự đơn giản. Tuy nhiên, trong một số trường hợp cạnh, có thể phải giữ tất cả các giá trị import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })47 cho tất cả các ô trống. Ví dụ: đó là trường hợp khi cập nhật dữ liệu trong cơ sở dữ liệu SQL từ bảng tính XLSX bằng cách sử dụng thư viện ORM Sequelize yêu cầu một thuộc tính rõ ràng là import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })47 để xóa nó trong một hoạt động import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })40. Để giữ tất cả các giá trị của import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })47, hãy chuyển tùy chọn import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })42 khi gọi import readXlsxFile from 'read-excel-file' // File. const input = document.getElementById('input') input.addEventListener('change', () => { readXlsxFile(input.files[0]).then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) }) // Blob. fetch('https://example.com/spreadsheet.xlsx') .then(response => response.blob()) .then(blob => readXlsxFile(blob)) .then((rows) => { // `rows` is an array of rows // each row being an array of cells. }) // ArrayBuffer. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer // // Could be obtained from: // * File // * Blob // * Base64 string // readXlsxFile(arrayBuffer).then((rows) => { // `rows` is an array of rows // each row being an array of cells. })7
|