Skip to content

Commit

Permalink
splitByClasses for CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Nov 20, 2023
1 parent d0e2b25 commit 43d921a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 44 deletions.
7 changes: 0 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@

## bugs

- spaceFilter for HetaCode

## features

- write reusable `Build` class
- split by classes in table
- checking legal functions inside Expressions and functionDefinition
- `#defineFunction`: circular dependences within functions, internal functions, different exports, functionDef vs units
- calculate units for pow function
Expand All @@ -46,7 +43,6 @@
- highlight multiline comments in Heta dictionary and array (with/without comma)
- atStart to exports: Matlab, DBSolve
- remove `isAmount`, `compartment` properties from `@Reaction`
- another approach to check heta-compiler new version (for no internet connection)

## ideas

Expand All @@ -71,9 +67,6 @@

## remove lodash

https://medium.com/swlh/are-we-ready-to-replace-lodash-60cd651f6c58
https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore

- _get
- _set
- _omit
Expand Down
47 changes: 31 additions & 16 deletions src/table-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ const schema = {
};

const bookTypes = {
xlsx: {fileExt: '.xlsx', containerSheets: 'ZIP', description: 'multiExcel 2007+ XML Format'},
xlsm: {fileExt: '.xlsm', containerSheets: 'ZIP', description: 'multiExcel 2007+ Macro XML Format'},
xlsb: {fileExt: '.xlsb', containerSheets: 'ZIP', description: 'multiExcel 2007+ Binary Format'},
biff8: {fileExt: '.xls', containerSheets: 'CFB', description: 'multiExcel 97-2004 Workbook Format'},
biff5: {fileExt: '.xls', containerSheets: 'CFB', description: 'multiExcel 5.0/95 Workbook Format'},
biff4: {fileExt: '.xls', containerSheets: 'none', description: 'singleExcel 4.0 Worksheet Format'},
biff3: {fileExt: '.xls', containerSheets: 'none', description: 'singleExcel 3.0 Worksheet Format'},
biff2: {fileExt: '.xls', containerSheets: 'none', description: 'singleExcel 2.0 Worksheet Format'},
xlml: {fileExt: '.xls', containerSheets: 'none', description: 'multiExcel 2003-2004 (SpreadsheetML)'},
ods: {fileExt: '.ods', containerSheets: 'ZIP', description: 'multiOpenDocument Spreadsheet'},
xlsx: {fileExt: '.xlsx', containerSheets: 'ZIP', description: 'multiExcel 2007+ XML Format', multischeet: true},
xlsm: {fileExt: '.xlsm', containerSheets: 'ZIP', description: 'multiExcel 2007+ Macro XML Format', multischeet: true},
xlsb: {fileExt: '.xlsb', containerSheets: 'ZIP', description: 'multiExcel 2007+ Binary Format', multischeet: true},
biff8: {fileExt: '.xls', containerSheets: 'CFB', description: 'multiExcel 97-2004 Workbook Format', multischeet: true},
biff5: {fileExt: '.xls', containerSheets: 'CFB', description: 'multiExcel 5.0/95 Workbook Format', multischeet: true},
biff4: {fileExt: '.xls', containerSheets: 'none', description: 'singleExcel 4.0 Worksheet Format', multischeet: true},
biff3: {fileExt: '.xls', containerSheets: 'none', description: 'singleExcel 3.0 Worksheet Format', multischeet: true},
biff2: {fileExt: '.xls', containerSheets: 'none', description: 'singleExcel 2.0 Worksheet Format', multischeet: true},
xlml: {fileExt: '.xls', containerSheets: 'none', description: 'multiExcel 2003-2004 (SpreadsheetML)', multischeet: true},
ods: {fileExt: '.ods', containerSheets: 'ZIP', description: 'multiOpenDocument Spreadsheet', multischeet: true},
fods: {fileExt: '.fods', containerSheets: 'none', description: 'multiFlat OpenDocument Spreadsheet'},
wk3: {fileExt: '.wk3', containerSheets: 'none', description: 'singleLotus Workbook (WK3)'},
csv: {fileExt: '.csv', containerSheets: 'none', description: 'singleComma Separated Values'},
Expand All @@ -69,6 +69,7 @@ class TableExport extends AbstractExport {

this.omitRows = q.omitRows || 0;
this.bookType = q.bookType || 'csv';
if (q.splitByClass!==undefined) this.splitByClass = q.splitByClass;

if (q.omit) this.omit = q.omit;
}
Expand Down Expand Up @@ -162,7 +163,7 @@ class TableExport extends AbstractExport {
content: fArr,
pathSuffix: '#0',
type: 'sheet',
name: this.space,
name: 'output',
headerSeq: sequence_out
}];
}
Expand All @@ -179,12 +180,26 @@ class TableExport extends AbstractExport {
);
XLSX.utils.book_append_sheet(wb, ws, x.name);
});

let bookType = bookTypes[this.bookType];

if (bookType.multischeet) {
return [{
content: XLSX.write(wb, { type: 'buffer', bookType: this.bookType}),
type: 'buffer',
pathSuffix: '/output' + bookType.fileExt
}];
} else {
return wb.SheetNames.map((key, i) => {
return {
content: XLSX.write(wb, { type: 'buffer', bookType: this.bookType, sheet: i}),
type: 'buffer',
pathSuffix: '/' + key + bookType.fileExt
};
});
}

return [{
content: XLSX.write(wb, { type: 'buffer', bookType: this.bookType}),
type: 'buffer',
pathSuffix: '/output' + bookTypes[this.bookType].fileExt
}];

}

static get validate(){
Expand Down
25 changes: 4 additions & 21 deletions src/xlsx-export/index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
const TableExport = require('../table-export');
const { ajv } = require('../utils');

const schema = {
type: 'object',
properties: {
splitByClass: {type: 'boolean'},
}
};

class XLSXExport extends TableExport {
constructor(q = {}, isCore = false){
constructor(q = {}, isCore = false) {
super(q, isCore);

// check arguments here
let logger = this._container.logger;
let valid = XLSXExport.isValid(q, logger);
if (!valid) { this.errored = true; return; }

if (q.splitByClass!==undefined) this.splitByClass = q.splitByClass;

this.bookType = 'xlsx';
}
get className(){
get className() {
return 'XLSXExport';
}
get defaultFilepath() {
return 'xlsx';
}
get format(){
get format() {
return 'XLSX';
}
static get validate(){
return ajv.compile(schema);
}
}

module.exports = XLSXExport;

0 comments on commit 43d921a

Please sign in to comment.