-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: GM upload dataset files uploads begins
- Loading branch information
1 parent
94f02bb
commit 6c92b60
Showing
14 changed files
with
4,233 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { ipcMain, app } from "electron"; | ||
import excel4node from "excel4node"; | ||
|
||
|
||
|
||
ipcMain.handle("convertJSONToSxlsx", async (jsondata, excelfile) => { | ||
return await convertJSONToXlsx(jsondata, excelfile); | ||
}) | ||
|
||
|
||
const convertJSONToXlsx = async (jsondata, excelfile) => { | ||
const requiredManifestHeaders = [ | ||
"filename", | ||
"timestamp", | ||
"description", | ||
"file type", | ||
"Additional Metadata", | ||
]; | ||
const blueHeader = ["filename", "File Name", "file name"]; | ||
const greenHeader = ["timestamp", "description", "file type"]; | ||
const yellowHeader = ["Additional Metadata"]; | ||
const wb = new excel4node.Workbook(); | ||
// create wb style that makes the background styling | ||
const greenHeaderStyle = createWorkbookStyle(wb, "a8d08d"); | ||
const yellowHeaderStyle = createWorkbookStyle(wb, "ffd965"); | ||
const blueHeaderStyle = createWorkbookStyle(wb, "A0C2E6"); | ||
const standardCellStyle = wb.createStyle({ | ||
font: { | ||
bold: false, | ||
color: "#000000", | ||
size: 12, | ||
name: "Calibri", | ||
}, | ||
}); | ||
|
||
const wsOptions = { | ||
sheetFormat: { | ||
defaultColWidth: 20, | ||
}, | ||
}; | ||
const ws = wb.addWorksheet("Sheet1", wsOptions); | ||
const headingColumnNames = Object.keys(jsondata[0]); | ||
//Write Column Title in Excel file | ||
let headingColumnIndex = 1; | ||
headingColumnNames.forEach((heading) => { | ||
let styleObject = yellowHeaderStyle; | ||
if (blueHeader.includes(heading)) { | ||
styleObject = blueHeaderStyle; | ||
} | ||
if (yellowHeader.includes(heading)) { | ||
styleObject = yellowHeaderStyle; | ||
} | ||
if (greenHeader.includes(heading)) { | ||
styleObject = greenHeaderStyle; | ||
} | ||
|
||
ws.cell(1, headingColumnIndex++) | ||
.string(heading) | ||
.style(styleObject); | ||
}); | ||
//Write Data in Excel file | ||
let rowIndex = 2; | ||
jsondata.forEach((record) => { | ||
let columnIndex = 1; | ||
Object.keys(record).forEach((columnName) => { | ||
ws.cell(rowIndex, columnIndex++) | ||
.string(record[columnName]) | ||
.style(standardCellStyle); | ||
}); | ||
rowIndex++; | ||
}); | ||
wb.write(excelfile); | ||
} | ||
|
||
const createWorkbookStyle = (wb, color) => { | ||
return wb.createStyle({ | ||
fill: { | ||
type: "pattern", | ||
patternType: "solid", | ||
fgColor: color, | ||
}, | ||
font: { | ||
bold: true, | ||
color: "#000000", | ||
size: 12, | ||
name: "Calibri", | ||
}, | ||
border: { | ||
left: { | ||
style: "thin", | ||
color: "#000000", | ||
}, | ||
right: { | ||
style: "thin", | ||
color: "#000000", | ||
}, | ||
top: { | ||
style: "thin", | ||
color: "#000000", | ||
}, | ||
bottom: { | ||
style: "thin", | ||
color: "#000000", | ||
}, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.