mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 23:06:00 +00:00
workign excel import
This commit is contained in:
19
packages/api/src/controllers/files.js
Normal file
19
packages/api/src/controllers/files.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const exceljs = require('exceljs');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
openedReaders: {},
|
||||
|
||||
analyseExcel_meta: 'get',
|
||||
async analyseExcel({ filePath }) {
|
||||
const workbook = new exceljs.Workbook();
|
||||
await workbook.xlsx.readFile(filePath);
|
||||
return {
|
||||
tables: workbook.worksheets.map((sheet) => {
|
||||
const header = sheet.getRow(1);
|
||||
const columns = _.range(header.cellCount).map((index) => ({ columnName: header.getCell(index + 1).value }));
|
||||
return { pureName: sheet.name, columns };
|
||||
}),
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -19,6 +19,7 @@ const sessions = require('./controllers/sessions');
|
||||
const runners = require('./controllers/runners');
|
||||
const jsldata = require('./controllers/jsldata');
|
||||
const config = require('./controllers/config');
|
||||
const files = require('./controllers/files');
|
||||
|
||||
const { rundir } = require('./utility/directories');
|
||||
|
||||
@@ -53,6 +54,7 @@ function start(argument = null) {
|
||||
useController(app, '/runners', runners);
|
||||
useController(app, '/jsldata', jsldata);
|
||||
useController(app, '/config', config);
|
||||
useController(app, '/files', files);
|
||||
|
||||
if (process.env.PAGES_DIRECTORY) {
|
||||
app.use('/pages', express.static(process.env.PAGES_DIRECTORY));
|
||||
|
||||
Reference in New Issue
Block a user