Community

Export to CSV: How to get Line Items Table columns headers

Hello

 

I wonder if you can help me - I'm trying to export line items table as separate CSV file using VBscript, and I don't know how to get name of column headers. I know how to write rows (modified script from help):

'Start writing Line Items --------------------------------------------------
csvFileName = fso.BuildPath (exportFolderPath, invoiceNumber & ".csv" )
set csvFile = fso.CreateTextFile( csvFileName, true )

dim table, row, cell
set table = me.Field("Document Section 1\InvoiceTable")

csvFile.Write
for each row in table.Items
    for each cell in row.Children
        csvFile.Write cell.Value & ","
    next
    csvFile.WriteBlankLines 1
next

I know I can write them to file manually, but sure there can be script way to do it.

 

Thank you in advance

0

Comments

3 comments

  • Avatar
    Ekaterina

    Hello Oleg

    Yes, you can do it by script:

    dim  csvFile, csvFileName

    set fso = CreateObject("Scripting.FileSystemObject")

    csvFileName = "C:\Users\Ekaterina.Voronich\Desktop\HotFolder\TestExportTable.csv"

    set csvFile = fso.CreateTextFile( csvFileName, true )

    dim table, row, cell

    set table = me.Field("Document Section 1\InvoiceTable")

    csvFile.Write "ColumnName1, ColumnName2, ColumnName3, ColumnName4, ColumnName5, ColumnName6, ColumnName7" <- insert the string with column headers here

    csvFile.WriteBlankLines 1

    for each row in table.Items

        for each cell in row.Children

            csvFile.Write cell.Value & ","

        next

        csvFile.WriteBlankLines 1

    next

     

    csvFile.Close

    0
  • Avatar
    oleg.karpun

    Hello Ekaterina

     

    Thank you for your help.

    I meant a little different thing - is it possible automatically find out headers of columns, since they exist in configuration already ?

    So instead manually writing:

    csvFile.Write "ColumnName1, ColumnName2, ColumnName3, ColumnName4, ColumnName5, ColumnName6, ColumnName7"

    we would have a script do it for us ?

     

    Thank you in advance

    0
  • Avatar
    Ekaterina

    Hello Oleg

    To extract table headers you could use cell.Name property for the first element in your cycle.

    0

Please sign in to leave a comment.