Excel stuff moved to et.js. Excel columns

have ids
This commit is contained in:
UKDTOM 2020-06-13 15:53:24 +02:00
parent 760a9ba510
commit 2a43deb519
3 changed files with 67 additions and 61 deletions

View file

@ -1,5 +1,6 @@
var def = JSON.parse(JSON.stringify(require('./definitions.json')));
const log = require('electron-log');
import {wtconfig, wtutils} from '../../../wtutils'
const et = new class ET {
constructor() {
@ -38,6 +39,67 @@ const et = new class ET {
});
return out
}
getFieldKey(libType, fieldName) {
return def[libType]['fields'][fieldName]['key']
}
}
export {et};
const excel = new class Excel {
constructor() {
}
NewSheet(Workbook, Library, Level) {
const sheet = Workbook.addWorksheet(Library + '-' + Level, {
views: [
{state: 'frozen', ySplit: 1}
]
});
return sheet
}
AddHeader(Sheet, Level, libType) {
const columns = []
let key
for (var i=0; i<Level.length; i++) {
key = et.getFieldKey(libType, Level[i])
log.debug('Column: ' + Level[i] + ' - ' + key)
//let column = { header: Level[i], key: 'id', width: 10 }
let column = { header: Level[i], key: key }
columns.push(column)
}
Sheet.columns = columns
/* Sheet.autoFilter = {
from: 'A1',
to: 'D1',
} */
}
SaveWorkbook(Workbook, Library, Level, Type) {
const fs = require('fs')
const dateFormat = require('dateformat');
const OutDir = wtconfig.get('ET.OutPath', wtutils.UserHomeDir)
const timeStamp=dateFormat(new Date(), "yyyy.mm.dd_h.MM.ss");
const name = OutDir + '/' + Library + '_' + Level + '_' + timeStamp + '.' + Type;
log.debug('Saving output file as: ' + name)
// Save Excel on Hard Disk
Workbook.xlsx.writeBuffer()
.then(buffer => fs.writeFileSync(name, buffer))
}
NewExcelFile() {
const Excel = require('exceljs');
// A new Excel Work Book
const workbook = new Excel.Workbook();
// Some information about the Excel Work Book.
workbook.creator = 'WebTools-NG';
workbook.lastModifiedBy = '';
workbook.created = new Date();
workbook.modified = new Date();
return workbook
}
}
export {et, excel};

View file

@ -4,7 +4,7 @@ import Vuex from "vuex"
import App from './App.vue'
import router from './router'
import store from './store'
import {wtutils, wtconfig, dialog, excel} from './wtutils'
import {wtutils, wtconfig, dialog} from './wtutils'
/*Icons - Styling - Design Frameworks - Sidemenu*/
import Buefy from 'buefy'
@ -75,7 +75,7 @@ const libType = 'movie'
// ET Stuff
import {et} from './components/modules/ExportTools/et'
import {et, excel} from './components/modules/ExportTools/et'
// Get possible levels for movie
console.log('Possible levels key/val are: ' + JSON.stringify(et.getLevels(libType)))
console.log('Possible levels key only names: ' + et.getLevelKeys(libType))
@ -91,7 +91,7 @@ const Sheet = excel.NewSheet(WorkBook, libName, level)
// Now get the fields, to use as header
const header = et.getLevelFields(level, libType)
//const header = et.getLevelKeys()
excel.AddHeader(Sheet, header)
excel.AddHeader(Sheet, header, libType)
// Save Excel file
excel.SaveWorkbook(WorkBook, libName, level, 'xlsx')

View file

@ -184,60 +184,4 @@ const wtutils = new class WTUtils {
}
const excel = new class Excel {
constructor() {
}
NewSheet(Workbook, Library, Level) {
const sheet = Workbook.addWorksheet(Library + '-' + Level, {
views: [
{state: 'frozen', ySplit: 1}
]
});
return sheet
}
AddHeader(Sheet, Level) {
const columns = []
for (var i=0; i<Level.length; i++) {
log.debug('Column: ' + Level[i])
//let column = { header: Level[i], key: 'id', width: 10 }
let column = { header: Level[i] }
columns.push(column)
}
Sheet.columns = columns
/* Sheet.autoFilter = {
from: 'A1',
to: 'D1',
} */
}
SaveWorkbook(Workbook, Library, Level, Type) {
const fs = require('fs')
const dateFormat = require('dateformat');
const OutDir = wtconfig.get('ET.OutPath', wtutils.UserHomeDir)
const timeStamp=dateFormat(new Date(), "yyyy.mm.dd_h.MM.ss");
const name = OutDir + '/' + Library + '_' + Level + '_' + timeStamp + '.' + Type;
log.debug('Saving output file as: ' + name)
// Save Excel on Hard Disk
Workbook.xlsx.writeBuffer()
.then(buffer => fs.writeFileSync(name, buffer))
}
NewExcelFile() {
const Excel = require('exceljs');
// A new Excel Work Book
const workbook = new Excel.Workbook();
// Some information about the Excel Work Book.
workbook.creator = 'WebTools-NG';
workbook.lastModifiedBy = '';
workbook.created = new Date();
workbook.modified = new Date();
return workbook
}
}
export {wtutils, wtconfig, dialog, excel};
export {wtutils, wtconfig, dialog};