Skip to content

Commit

Permalink
Merge pull request #525 from paulwarren-wk/write-excel-file
Browse files Browse the repository at this point in the history
  • Loading branch information
austinmatherne-wk authored Jul 27, 2023
2 parents f0f218b + c9c5277 commit a147609
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 379 deletions.
79 changes: 26 additions & 53 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -217,59 +217,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



exceljs


Copyright (c) 2014-2017 Guyon Roche


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.





file-saver
Copyright © 2016 [Eli Grey][1].


Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:


The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.


[1]: http://eligrey.com




interactjs

Copyright (c) 2012-2017 Taye Adeyemi <[email protected]>
Expand Down Expand Up @@ -436,4 +383,30 @@ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




write-excel-file

Copyright (c) 2018 gitlab.com/catamphetamine

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---
10 changes: 9 additions & 1 deletion iXBRLViewerPlugin/viewer/src/js/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ export class Inspector {

handleMessage(event) {
const jsonString = event.originalEvent.data;
const data = JSON.parse(jsonString);
let data;
try {
data = JSON.parse(jsonString);
}
catch (e) {
// Silently ignore any non-JSON messages as write-excel-file sends
// messages to itself when exporting files.
return;
}

if (data.task == 'SHOW_FACT') {
this.selectItem(data.factId);
Expand Down
41 changes: 25 additions & 16 deletions iXBRLViewerPlugin/viewer/src/js/tableExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import $ from 'jquery'
import FileSaver from 'file-saver'
import * as Excel from 'exceljs/dist/exceljs.min.js';
import writeXlsxFile from 'write-excel-file'
import { Fact } from './fact.js';


export class TableExport {
constructor(table, report) {
this._table = table;
Expand Down Expand Up @@ -122,43 +123,51 @@ export class TableExport {
}

_writeTable(data) {
const wb = new Excel.Workbook();
const ws = wb.addWorksheet('Table');
const excelRows = [];
const columns = [];

let s = '';
for (const [i, row] of data.entries()) {
const excelRow = [];
for (const [j, cell] of row.entries()) {
const cc = ws.getRow(i+1).getCell(j+1);
const cc = {};

if (cell.type === 'fact') {
columns[j] = { width: 18 };
cc.value = Number(cell.fact.value());
cc.numFmt = '#,##0';
ws.getColumn(j+1).width = 18;
cc.type = Number;
cc.format = '#,##0';
/* Make this an option - apply presentation signs */
if (cell.negative) {
cc.value = Math.abs(cc.value) * -1;
}
else {
cc.value = Math.abs(cc.value);
}
cc.border = {};
if (cell.topBorder) {
cc.border.top = {style: "medium", color: { argb: 'FF000000' }};
cc.topBorderStyle = 'medium';
cc.topBorderColor = '#000000';
}
if (cell.bottomBorder) {
cc.border.bottom = {style: "medium", color: { argb: 'FF000000' }};
cc.bottomBorderStyle = 'medium';
cc.bottomBorderColor = '#000000';
}
}
else if (cell.type === 'aspectLabel') {
cc.value = cell.value;
cc.type = String;

}
else {
cc.value = cell.value;
cc.font = { color : { argb: 'FF707070' } };
cc.type = String;
cc.color = '#707070';
}
excelRow.push(cc);
}
excelRows.push(excelRow);
}
return wb;
return { columns: columns, data: excelRows };
}

exportTable() {
Expand Down Expand Up @@ -243,10 +252,10 @@ export class TableExport {
}


const wb = this._writeTable(data);
wb.xlsx.writeBuffer().then( data => {
const blob = new Blob( [data], {type: "application/octet-stream"} );
FileSaver.saveAs( blob, 'table.xlsx');
const excelData = this._writeTable(data);
writeXlsxFile(excelData.data, {
columns: excelData.columns,
fileName: 'table.xlsx'
});
}
}
Loading

0 comments on commit a147609

Please sign in to comment.