0

我正在尝试解析以下两条记录。我之前问了一个问题,修复了我一直试图解析的记录,但现在我的客户说以下两条记录不起作用。这次我也遇到了另一个错误:无效的记录长度:列长度为 19,得到 17

以下是记录(顶部有一条记录,底部来自具有多条记录的不同文件):

lineItemXref,sku,poStatus,transactionDate,requestedShipDate,estimatedReceiptDate,qtyOrdered,qtyOpen,qtyCanceled,qtyReceived,vendorCode,contractedPrice,openExtendedCost,locationCode,poNumber,fileUpdate,notes,vendorNotes,vendorSku
USR355-1,ISHD00WTUS-00478,Pending Receipt,09/21/2021,12/22/2021,02/10/2022,1944,1944,0,0,77,16.00,31104,DISTRIBUTION ALTERNATIVES,USR355-1,12/31/2021,"InStyler BLU Turbo Ionic Dryer 
-Project: ISHDD
-US Retail
-White
-TUV Certification
-120V
-9ft Cord; Plug Type A
-Retail Box-revised A/W to ""TURBO IONIC""
-Instruction Manual
-Hard Diffuser removed
-New Pulp Tray without diffuser cavity
-Concentrator (small version)
-Rating Label
-Cord Label
-Check Point label
-Sensormatic Security Label",,

    lineItemXref,sku,poStatus,transactionDate,requestedShipDate,estimatedReceiptDate,qtyOrdered,qtyOpen,qtyCanceled,qtyReceived,vendorCode,contractedPrice,openExtendedCost,locationCode,poNumber,fileUpdate,notes,vendorNotes,vendorSku
PO510-4,80150-BUF-OAKR-1,Pending Receipt,05/16/2021,1/15/2022,2/26/2022,110,110,0,0,726,75.00,8250,Destined for Consolidation,PO510,01/18/2022,"Copenhagen Sideboard Oak Rattan Box 1
""SAILORSB01-W Melamine Plastic Rattan""
",,SAILORSB01-W Melamine Plastic Rattan
PO510-5,80150-BUF-OAKR-2,Pending Receipt,05/16/2021,1/15/2022,2/26/2022,110,110,0,0,726,47.50,5225,Destined for Consolidation,PO510,01/18/2022,"Copenhagen Sideboard Oak Rattan Box 2
""SAILORSB01-W Melamine Plastic Rattan""
",,SAILORSB01-W Melamine Plastic Rattan
PO510-6,80200-BUF-OAK,Pending Receipt,05/16/2021,1/15/2022,2/26/2022,110,110,0,0,726,102.00,11220,Destined for Consolidation,PO510,01/18/2022,"Visby Sideboard Oak
""LINESB02 Melamine""",,LINESB02 Melamine

有 19 个标题列,当您计算记录列(使用逗号作为分隔符)时,有 19 个。我不确定为什么它不能正确解析。这是我目前使用的代码,它适用于除上述记录之外的所有引用字段。必须有一个我丢失的参数或其他东西。我正在将 csv-parse 与节点 js 一起使用。任何帮助,将不胜感激。我的客户很恐慌!

public async processCSV (tenant: string, files: { [field: string]: MultipartFileContract | MultipartFileContract[] }) : Promise<any[]> {
    try {
      for (const file of Object.values(files)) {
        const f = file as MultipartFileContract

        // @ts-ignore
        const filePath = path.resolve(f['csv'].tmpPath!)
        const records: any[] = []

        const parser = fs.createReadStream(filePath).pipe(parse({ columns: true, relax: true, escape: '\\' }))

        for await (const record of parser) {
          records.push(record)
        }

        return records
      }

      return []
    } catch (err) {
      throw ServiceHelper.handleError('DataImportService.processCSV', err)
    }
  }
4

0 回答 0