feat: playground add submenu
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import mammoth from 'mammoth';
|
||||
import XLSX from 'xlsx';
|
||||
|
||||
export const isNotEmptyValue = (value: any) => {
|
||||
if (Array.isArray(value)) {
|
||||
@@ -196,35 +194,3 @@ export function readBlob(blob: Blob): Promise<string> {
|
||||
reader.readAsText(blob, 'utf-8');
|
||||
});
|
||||
}
|
||||
|
||||
export function readWordContent(file: File): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (e: any) {
|
||||
const arrayBuffer = e.target.result;
|
||||
mammoth
|
||||
.extractRawText({ arrayBuffer })
|
||||
.then((result) => {
|
||||
resolve(result.value);
|
||||
})
|
||||
.catch((error) => reject(error));
|
||||
};
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
|
||||
export function readExcelContent(file: File): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (e: any) {
|
||||
const arrayBuffer = e.target.result;
|
||||
const workbook = XLSX.read(arrayBuffer, { type: 'string' });
|
||||
const ws = workbook.Sheets[workbook.SheetNames[0]]; // get the first worksheet
|
||||
const data = XLSX.utils.sheet_to_json(ws);
|
||||
resolve(JSON.stringify(data));
|
||||
};
|
||||
reader.onerror = (error) => reject(error);
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user