From f02aada80b19d19e4dfcd9657606862e05231cde Mon Sep 17 00:00:00 2001 From: ivansg44 Date: Wed, 10 Jun 2020 17:21:16 -0700 Subject: [PATCH] Import/export xls files (#56) --- main.html | 3 ++- main.js | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/main.html b/main.html index d6c0764e..5f9c29a8 100644 --- a/main.html +++ b/main.html @@ -18,7 +18,7 @@ @@ -97,6 +97,7 @@
diff --git a/main.js b/main.js index 4e07963e..c34e2c8e 100644 --- a/main.js +++ b/main.js @@ -302,6 +302,8 @@ const exportFile = (matrix, baseName, ext, xlsx) => { xlsx.utils.book_append_sheet(workbook, worksheet, 'Sheet1'); if (ext === 'xlsx') { xlsx.writeFile(workbook, `${baseName}.xlsx`); + } else if (ext === 'xls') { + xlsx.writeFile(workbook, `${baseName}.xls`); } else if (ext === 'tsv') { xlsx.writeFile(workbook, `${baseName}.tsv`, {bookType: 'csv', FS: '\t'}); } else if (ext === 'csv') { @@ -311,7 +313,7 @@ const exportFile = (matrix, baseName, ext, xlsx) => { /** * Read local file opened by user. - * Only reads `xlsx`, `csv` and `tsv` files. + * Only reads `xlsx`, `xlsx`, `csv` and `tsv` files. * @param {File} file User file. * @param {Object} xlsx SheetJS variable. * @return {Promise>>} Matrix populated by user's file data. @@ -627,7 +629,7 @@ $(document).ready(() => { $fileInput.change(() => { const file = $fileInput[0].files[0]; const ext = file.name.split('.').pop(); - const acceptedExts = ['xlsx', 'tsv', 'csv']; + const acceptedExts = ['xlsx', 'xls', 'tsv', 'csv']; if (!acceptedExts.includes(ext)) { const errMsg = `Only ${acceptedExts.join(', ')} files are supported`; $('#open-err-msg').text(errMsg);