diff --git a/client/src/app/editor/editor.component.ts b/client/src/app/editor/editor.component.ts index 116f3cb..6f5a3cb 100644 --- a/client/src/app/editor/editor.component.ts +++ b/client/src/app/editor/editor.component.ts @@ -940,13 +940,30 @@ export class EditorComponent implements OnInit, AfterViewInit { return row.map((col: any, index: number) => { if (!col && col !== 0) col = '' - if (isNaN(col)) { - col = col.replace(/"/g, '""') + /** + * Keeping this for the reference + * Code below used to convert JSON to CSV + * now the XLSX is converting to CSV + */ + // if (isNaN(col)) { + // // Match and replace the double quotes, ignore the first and last char + // // in case they are double quotes already + // col = col.replace(/(? -1) { - col = '"' + col + '"' - } - } + // if (col.search(/,/g) > -1 || + // col.search(/\r|\n/g) > -1 + // ) { + // // Missing quotes at the end + // if (col.search(/"$/g) < 0) { + // col = col + '"' // So we add them + // } + + // // Missing quotes at the start + // if (col.search(/^"/g) < 0) { + // col = '"' + col // So we add them + // } + // } + // } const colName = this.headerShow[index] const colRule = this.dcValidator?.getRule(colName) @@ -961,20 +978,27 @@ export class EditorComponent implements OnInit, AfterViewInit { this.data = csvArrayData - let csvContent = csvArrayHeaders.join(',') + '\n' - // Apply licence rows limitation if exists - csvContent += csvArrayData - .slice(0, this.licenceState.value.submit_rows_limit) - .map((e) => e.join(',')) - .join('\n') + // Apply licence rows limitation if exists, it is only affecting data + // which will be send to SAS + const strippedCsvArrayData = csvArrayData.slice(0, this.licenceState.value.submit_rows_limit) + // To submit to sas service, we need clean version of CSV of file + // attached. XLSX will do the parsing and heavy lifting + // First we create worksheet of json (data we extracted) + let ws = XLSX.utils.json_to_sheet(strippedCsvArrayData, { + skipHeader: true + }); + // create CSV to be uploaded from worksheet + let csvContentClean = XLSX.utils.sheet_to_csv(ws); + // Prepend headers + csvContentClean = csvArrayHeaders.join(',') + '\n' + csvContentClean if (this.encoding === 'WLATIN1') { - let encoded = iconv.decode(Buffer.from(csvContent), 'CP-1252') + let encoded = iconv.decode(Buffer.from(csvContentClean), 'CP-1252') let blob = new Blob([encoded], { type: 'application/csv' }) let newCSVFile: File = this.blobToFile(blob, this.filename + '.csv') this.uploader.addToQueue([newCSVFile]) } else { - let blob = new Blob([csvContent], { type: 'application/csv' }) + let blob = new Blob([csvContentClean], { type: 'application/csv' }) let newCSVFile: File = this.blobToFile(blob, this.filename + '.csv') this.uploader.addToQueue([newCSVFile]) } diff --git a/client/src/environments/_eula.ts b/client/src/environments/_eula.ts index 684dea6..3d7cba2 100644 --- a/client/src/environments/_eula.ts +++ b/client/src/environments/_eula.ts @@ -18,4 +18,4 @@ In any case, you must not make any such use of this software as to develop softw UNLESS EXPRESSLY AGREED OTHERWISE, 4GL APPS PROVIDES THIS SOFTWARE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, AND IN NO EVENT AND UNDER NO LEGAL THEORY, SHALL 4GL APPS BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING FROM USE OR INABILITY TO USE THIS SOFTWARE. -` +` \ No newline at end of file