NetTalk Central

Author Topic: Creating CSV need first row to have the names of the fields  (Read 2885 times)

Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
Creating CSV need first row to have the names of the fields
« on: February 01, 2024, 02:12:31 AM »
Hi,
 Im sequentially copying tps records to a CSV file by date
        ExpCSV:Label1                   =  LOG:NAME
        ExpCSV:Label2                   =  loclogin 
        ExpCSV:Label3                   = FORMAT(LOG:Datein,@D6)
        ExpCSV:Label4                   = FORMAT(LOG:timeIn,@T4)
I need the first row to have the name of the corresponding column ie Name  ID  Datein  TimeIn etc


?? How to please.
Thanks
Richard
NT 14.16

osquiabro

  • Hero Member
  • *****
  • Posts: 687
    • View Profile
    • Email
Re: Creating CSV need first row to have the names of the fields
« Reply #1 on: February 01, 2024, 04:09:26 AM »
use basic driver

FIRSTROWHEADER

DRIVER('BASIC', '/FIRSTROWHEADER=[ON|OFF]' )

[ Buffers" = ] SEND(file, '/FIRSTROWHEADER [ = ON|OFF]' )

This indicates if the first row of the file contains the labels of the columns.

By default this switch is off. If turned on, then CREATE(file) will add a line containing the labels of the fields separated by the comma character (as specified by the COMMA switch or ','), further the first line will always be skipped when reading from the file.


Johan de Klerk

  • Full Member
  • ***
  • Posts: 217
  • Johan de Klerk
    • View Profile
    • Designer Software
Re: Creating CSV need first row to have the names of the fields
« Reply #2 on: February 01, 2024, 04:54:01 AM »
Hi Richard,

If you have StringTheory then it is easy and fast.

IF ~EXISTS('yourfilename.CSV')
    ST.SetValue('Name,Login,Datein,TimeIn'&'<13,10>')
    ST.SaveFile('yourfilename.CSV',FALSE)
    ST.SetValue(ExpCSV:Label1&','&ExpCSV:Label2&','&ExpCSV:Label3&','&ExpCSV:Label4&'<13,10>')
    ST.SaveFile('yourfilename.CSV',TRUE)
ELSE
    ST.SetValue(ExpCSV:Label1&','&ExpCSV:Label2&','&ExpCSV:Label3&','&ExpCSV:Label4&'<13,10>')
    ST.SaveFile('yourfilename.CSV',TRUE)
END

Not tested and there might be a better and faster way.

Regards

Johan de Klerk




Clarion 10, NT 11.57

Richard I

  • Sr. Member
  • ****
  • Posts: 398
    • View Profile
    • Email
Re: Creating CSV need first row to have the names of the fields
« Reply #3 on: February 01, 2024, 11:24:06 AM »
Thanks guys, but too easy with-
First time through before gathering data, but after initialisation 

SET(ExportCSV)
       ExpCSV:Label1        = 'Employee Name'
       ExpCSV:Label2        =  'Payroll ID'
       ExpCSV:Label3        = 'Date In'
ExportCSV.Insert

Cheers
Richard
« Last Edit: February 01, 2024, 11:26:33 AM by Richard I »