Skip to content
Snippets Groups Projects
Commit db0304f8 authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #360 - remove "help" from cells in exported spreadsheets

parent 7bf9e415
No related branches found
No related tags found
No related merge requests found
......@@ -158,8 +158,36 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
}); // defaults to image/png
}
public static exportAsSpreadsheet(table: ElementRef) {
/**
* Exports a results data table to XLSX format, and removes "help" mentions
* from the parameters names columns if needed
* @param table results data table
* @param namesInFirstCol if true, will look for parameters names in 1st column
* (for fixed results), else in 1st row (variable results, by default)
*/
public static exportAsSpreadsheet(table: ElementRef, namesInFirstCol: boolean = false) {
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(table);
let regExCellKey;
if (namesInFirstCol) {
regExCellKey = new RegExp("^A\\d$");
} else {
regExCellKey = new RegExp("^\\w1$");
}
// browse all cells
for (const key in ws) {
// look for 1st row or 1st col
if (regExCellKey.test(key) === true) {
const regExCellName = new RegExp("help$");
const v: string = ws[key].v;
// remove "help" from cell name's ending
if (regExCellName.test(v) === true) {
const newV = v.substr(0, v.length - 4);
ws[key].v = newV;
}
}
}
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "default");
const wopts: any = { bookType: "xlsx", bookSST: false, type: "array" };
......
......@@ -272,6 +272,6 @@ export class FixedResultsComponent extends ResultsComponent {
}
public exportAsSpreadsheet() {
AppComponent.exportAsSpreadsheet(this.table.nativeElement);
AppComponent.exportAsSpreadsheet(this.table.nativeElement, true);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment