mirror of
https://github.com/WebTools-NG/WebTools-NG
synced 2025-03-09 00:37:20 +00:00
#79 tryed and failed :(
This commit is contained in:
parent
710bd170a9
commit
8db011d9a7
3 changed files with 118 additions and 6 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -8350,6 +8350,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"jquery-csv": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/jquery-csv/-/jquery-csv-1.0.11.tgz",
|
||||
"integrity": "sha512-KDPc3wFLTFO68p/4IqsODZCjBp+y9axDa/pr36pDKrWk6yyHf8Nk1FqAGXvaUb6H7J1zJSYszABIFj0a40QXRA=="
|
||||
},
|
||||
"js-message": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
"file-saver": "^2.0.2",
|
||||
"file-size": "^1.0.0",
|
||||
"is-electron": "^2.2.0",
|
||||
"jquery-csv": "^1.0.11",
|
||||
"jsonpath-plus": "^4.0.0",
|
||||
"minimist": "^1.2.5",
|
||||
"node-fetch": "^2.6.0",
|
||||
|
|
|
@ -717,7 +717,109 @@ const excel2 = new class Excel {
|
|||
row.forEach(element => {
|
||||
excel2.AddRow(sheet, element)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async sleep(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async createXLSXFile( {csvFile, level, libType, libName} )
|
||||
{
|
||||
//const Excel = require('exceljs');
|
||||
const fs = require('fs')
|
||||
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
var csv = require('jquery-csv/src/jquery.csv')
|
||||
|
||||
csv
|
||||
// This will loop thru a csv file, and add to an xlsx file
|
||||
|
||||
|
||||
|
||||
// First create a WorkBook
|
||||
const workBook = await excel2.NewExcelWorkBook()
|
||||
// Create Sheet
|
||||
let sheet = await excel2.NewSheet(workBook, libName, level)
|
||||
// Add the header to the sheet
|
||||
const header = await excel2.AddHeader(sheet, level, libType)
|
||||
|
||||
|
||||
excel2.AddRow(sheet, ['ged1', 'ged2'])
|
||||
|
||||
var readline = require('readline');
|
||||
readline
|
||||
// let row = []
|
||||
|
||||
// var myInterface = readline.createInterface({
|
||||
// input: fs.createReadStream(csvFile)
|
||||
// });
|
||||
|
||||
|
||||
// var lineno = 0;
|
||||
// myInterface.on('line', async function (line) {
|
||||
// lineno++;
|
||||
// console.log('Line number ' + lineno + ': ' + line);
|
||||
// /* var row = line.split(',"');
|
||||
// console.log('Ged1: ' + row[1])
|
||||
// console.log('Ged2: ' + row[2])
|
||||
// console.log('Ged Row: ' + JSON.stringify(row)) */
|
||||
|
||||
// //var lineArray = excel2.csvStringToArray(line)
|
||||
|
||||
|
||||
// row = csv.toArray(line);
|
||||
// //var lineArray = excel2.CSVToArray(line, ',')
|
||||
// console.log('Ged lineArray: ' + JSON.stringify(row))
|
||||
// console.log('Ged1: ' + row[1])
|
||||
// console.log('Ged2: ' + row[2])
|
||||
|
||||
|
||||
// excel2.AddRow(sheet, row)
|
||||
// console.log('Ged wait')
|
||||
// await excel2.sleep(2000)
|
||||
// //await sheet.addRow(lineArray);
|
||||
// console.log('Ged continue')
|
||||
// });
|
||||
|
||||
// myInterface.on('close', function(){
|
||||
// console.log('Ged done reading')
|
||||
// })
|
||||
|
||||
var fd = fs.openSync(csvFile, 'r');
|
||||
var bufferSize = 2048;
|
||||
var buffer = new Buffer(bufferSize);
|
||||
|
||||
var leftOver = '';
|
||||
var read, line, idxStart, idx;
|
||||
while ((read = fs.readSync(fd, buffer, 0, bufferSize, null)) !== 0) {
|
||||
leftOver += buffer.toString('utf8', 0, read);
|
||||
idxStart = 0
|
||||
while ((idx = leftOver.indexOf("\n", idxStart)) !== -1) {
|
||||
line = leftOver.substring(idxStart, idx);
|
||||
console.log("one line read: " + line);
|
||||
idxStart = idx + 1;
|
||||
}
|
||||
leftOver = leftOver.substring(idxStart);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
console.log('GED Pause')
|
||||
await excel2.sleep(4000)
|
||||
console.log('GED Save')
|
||||
|
||||
// Save Excel file
|
||||
await excel2.SaveWorkbook(workBook, libName, level, "xlsx")
|
||||
|
||||
csvFile, header
|
||||
}
|
||||
|
||||
async createOutFile( {libName, level, libType, outType, baseURL, accessToken} )
|
||||
{
|
||||
|
@ -780,15 +882,19 @@ const excel2 = new class Excel {
|
|||
}
|
||||
stream.end();
|
||||
// Rename to real file name
|
||||
var newFile = tmpFile.replace('.tmp', '.csv')
|
||||
fs.rename(tmpFile, newFile, function (err) {
|
||||
if (err) throw err;
|
||||
console.log('renamed complete');
|
||||
});
|
||||
var newFile = tmpFile.replace('.tmp', '.csv')
|
||||
fs.renameSync(tmpFile, newFile);
|
||||
console.log('renamed complete');
|
||||
// Need to export to xlsx as well?
|
||||
if (wtconfig.get('ET.ExpExcel')){
|
||||
console.log('Ged export to excel')
|
||||
await excel2.createXLSXFile( {csvFile: newFile, level: level, libType: libType, libName: libName})
|
||||
}
|
||||
store.commit("UPDATE_EXPORTSTATUS", `Export finished. File:"${newFile}" created`)
|
||||
|
||||
|
||||
|
||||
|
||||
// Save Excel file
|
||||
// const result = await excel2.SaveWorkbook(workBook, libName, level, outType)
|
||||
// return result
|
||||
|
|
Loading…
Add table
Reference in a new issue