Community

Enclose double quotes on csv export

Hello,
I'm trying to figure out how to enclose double quotes for my csv fields. Can someone help?
Here's an example of what I'm trying to achieve:

NAME,GENDER,MOTHER_NAME,PLACE_OF_BIRTH,DATE_OF_BIRTH,COUNTRY_ID
"Barrack Obama","M","Stanley Ann Dunham","Hawaii","04/08/61","US","US"

Thanks in advance.

0

Comments

21 comments

  • Avatar
    ITSymeta
    Hello

    What ABBYY application are you using to achieve this?
    0
  • Avatar
    Jakarta Development
    Sorry for the late reply. I'm using FlexiCapture 10 pro. Can you help shed some lights?
    0
  • Avatar
    Feri Santosa


    There's export script you can try :

    Dim name,gender,mothername,placeofbirth, dateofbirth,countryid as string
    name = """" & document.field("NAME").value & """"
    gender = """" & document.field("GENDER").value & """"
    mothername = """" & document.field("PLACE_OF_BIRTH").value & """"
    dateofbirth = """" & document.field("DATE_OF_BIRTH").value & """"
    countryid = """" & document.field("COUNTRY_ID").value & """"

    Dim tekstowrite as string = name & "," & gender & "," & mothername & "," & dateofbirth & "," & countryid & microsoft.visualbasic.vbcrlf

    Dim writer as streamwriter
    writer = system.io.file.createtext("d:\mycsv.csv")
    writer.write(tekstowrite)
    writer.close





    0
  • Avatar
    Jakarta Development
    Hi ScanAddicted, Thank you. I will try as soon as possible.
    0
  • Avatar
    Jakarta Development
    Here's my take based on your example:

    Dim name,gender,mothername,pob,dob,country as string

    name = """" & document.field("NAME").value & """"
    gender = """" & document.field("GENDER").value & """"
    mothername = """" & document.field("MOTHER_NAME").value & """"
    pob = """" & document.field("PLACE_OF_BIRTH").value & """"
    dob = """" & document.field("DATE_OF_BIRTH").value & """"
    country = """" & document.field("COUNTRY").value & """"

    Dim tekstowrite as string = name & "," & gender & "," & mothername & "," & pob & "," & dob & "," & country & microsoft.visualbasic.vbcrlf
    Dim writer as streamwriter

    writer = system.io.file.createtext("d:\mycsv.csv")
    write.write(tekstowrite)
    write.close

    ABBYY said Expected end of statement (line 1, pos 44) and refuse to safe.

    Sorry I'm not a programmer

    There's export script you can try : Dim name,gender,mothername,placeofbirth, dateofbirth,countryid as string name = """" & document.field("NAME").value & """" gender = """" & document.field("GENDER").value & """" mothername = """" & document.field("PLACE_OF_BIRTH").value & """" dateofbirth = """" & document.field("DATE_OF_BIRTH").value & """" countryid = """" & document.field("COUNTRY_ID").value & """" Dim tekstowrite as string = name & "," & gender & "," & mothername & "," & dateofbirth & "," & countryid & microsoft.visualbasic.vbcrlf Dim writer as streamwriter writer = system.io.file.createtext("d:\mycsv.csv") writer.write(tekstowrite) writer.close


    0
  • Avatar
    Feri Santosa


    First You should change VBScript to VBNet

    Then you should put : this code

    Imports system.io

    on the most top of script
    0
  • Avatar
    Jakarta Development
    Updated script based on ScanAddicted's suggestion:



    Imports system.io





    Dim vbcrlf as string = microsoft.visualbasic.vbcrlf


    Dim namafiledetail as string = "D:\YOURTARGETFOLDER\export.csv"


    Dim barisawaldetail as string = "NAME,GENDER,MOTHER_NAME,PLACE_OF_BIRTH,DATE_OF_BIRTH,COUNTRY_ID" & vbcrlf


    Dim isidetail as string = ""


    Dim barisdata as string = ""


    Dim title as string


    barisdata = barisdata & """" & document.Field("Document Section 1\NAME").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\GENDER).value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\MOTHER_NAME").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\PLACE_OF_BIRTH").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\DATE_OF_BIRTH").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\COUNTRY_ID").value

    isidetail = isidetail & barisdata & vbcrlf





    if file.exists(namafiledetail) = false then


    Dim writer2 as streamwriter


    writer2 = File.createtext(namafiledetail)


    writer2.write(barisawaldetail & isidetail)


    writer2.close


    else


    Dim reader2 as streamreader


    reader2 = file.opentext(namafiledetail)


    Dim isidetaillama as string = reader2.readtoend


    reader2.close


    Dim writer2 as streamwriter


    writer2 = File.createtext(namafiledetail)


    writer2.write(isidetaillama & isidetail)


    writer2.close


    end if





    Result is as expected.
    0
  • Avatar
    Jakarta Development
    So I put some dummy checkmark to accommodate some hidden fields that has certain value.
    Eg. COUNTRY_ID and the value is ID.
    I set the Data Type property to when not selected, input: ID.

    All is well when exporting to standard csv. There will be a field named COUNTRY_ID and ID as it's value.
    But when I use the above custom script the value of the COUNTRY_ID is "False"

    Any explanations?

    ps.
    Why did I use checkmarks for hidden field? Because I don't know how to using text field.
    I suppose I should use text field and another custom script to set the value of the hidden field?
    0
  • Avatar
    Feri Santosa


    Maybe you could try document.field("country_id).text instead of document.field("country_id").value

    See if its works
    0
  • Avatar
    Jakarta Development
    No joy. Still outputing "False".

    Is there any other way to create hidden field with a defined value?
    0
  • Avatar
    Feri Santosa
    Could you show me the setting of this checkmark? Specially the datatype..
    0
  • Avatar
    Feri Santosa
    Never mind.

    Try this. Just copy paste your code with minor adjustment





    Imports system.io





    Dim vbcrlf as string = microsoft.visualbasic.vbcrlf


    Dim namafiledetail as string = "D:\YOURTARGETFOLDER\" & document.field("Document Section 1\NAME").value & ".csv"


    Dim barisawaldetail as string = "NAME,GENDER,MOTHER_NAME,PLACE_OF_BIRTH,DATE_OF_BIRTH,COUNTRY_ID" & vbcrlf


    Dim isidetail as string = ""


    Dim barisdata as string = ""



    Dim replacementid as string

    if document.field(""Document Section 1\COUNTRY_ID").value = False then
    replacementid = "ID"
    else
    replacementid = document.field(""Document Section 1\COUNTRY_ID").value
    end if




    Dim title as string


    barisdata = barisdata & """" & document.Field("Document Section 1\NAME").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\GENDER).value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\MOTHER_NAME").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\PLACE_OF_BIRTH").value & ""","


    barisdata = barisdata & """" & document.Field("Document Section 1\DATE_OF_BIRTH").value & ""","


    barisdata = barisdata & """" & replacementid & """"

    isidetail = isidetail & barisdata & vbcrlf





    if file.exists(namafiledetail) = false then


    Dim writer2 as streamwriter


    writer2 = File.createtext(namafiledetail)


    writer2.write(barisawaldetail & isidetail)


    writer2.close


    else


    Dim reader2 as streamreader


    reader2 = file.opentext(namafiledetail)


    Dim isidetaillama as string = reader2.readtoend


    reader2.close


    Dim writer2 as streamwriter


    writer2 = File.createtext(namafiledetail)


    writer2.write(isidetaillama & isidetail)


    writer2.close


    end if
    0
  • Avatar
    Jakarta Development
    Data Type
    When convert to strings use:
    Custom
    Selected [none]
    Not Seleced [ID]

    On separate note, I also tried creating a text field instead checkmark field and put this script:
    me.field("CITIZENSHIP").text = "ID"

    Result on csv is just "" (empty)
    0
  • Avatar
    Feri Santosa
    I see. You want to create a field that always contains "ID" no matter what happen.

    There are two ways how to do this :

    1. Recommended :

    change my lastcode from :
    Dim replacementid as string

    if document.field(""Document Section 1\COUNTRY_ID").value = False then
    replacementid = "ID"
    else
    replacementid = document.field(""Document Section 1\COUNTRY_ID").value
    end if

    '---------- become

    replacementid = "ID"


    2. Not recommended (why you need to verify something constant?)

    a. Create Field Text sample: "document section1\constant"
    b. Create Rules Script
    c. Make sure the field is not readonly
    d. Put the script document.field("document section1\constant").value = "ID"

    Better using no 1.



    0
  • Avatar
    Feri Santosa
    sorry. replace
    Dim replacementid as string

    if document.field(""Document Section 1\COUNTRY_ID").value = False then
    replacementid = "ID"
    else
    replacementid = document.field(""Document Section 1\COUNTRY_ID").value
    end if

    with

    Dim replacementid as string
    replacementid = "ID
    0
  • Avatar
    Jakarta Development
    AWESOME! It works.

    So I can just add more conditional for multiple hidden fields?
    0
  • Avatar
    Feri Santosa
    Sure. You can create any conditional as many as you want.
    0
  • Avatar
    Jakarta Development
    Sorry, I got one more question regarding this matter.

    I noticed that the DATE_OF_BIRTH output value when exporting using this script is MM/DD/YYYY even when the Data Type was set to DD/MM/YYYY.

    The output csv using regular export function is correct DD/MM/YYYY.

    How to fix it?

    I tried

    1a.
    DATE_OF_BIRTH data type is now text (output eg. 13011990)

    2a.
    script:
    Dim getDatedob as string = document.Field("Document Section 1\DATE_OF_BIRTH").Value
    Dim flipDatedob = Date.ParseExact(getDatedob, "dd/MM/yyyy", Nothing)


    It spits out:
    [Processing error]:
    Document 1: EnclosedDoubleQuote_2: System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) at Main.Execute(IDocument Document, IProcessingCallback Processing)

    1b.
    DATE_OF_BIRTH data type is now date DD/MM/YYYY (output eg. 13/04/1989)

    2b.
    script:
    Dim getDatedob as String = document.Field("Document Section 1\DATE_OF_BIRTH").Value
    Dim flipDatedob as Date = Date.Parse(getDatedob)


    Result:
    DATE_OF_BIRTH
    Standard CSV export: 13/04/1989

    Custom CSV export: 4/13/1989



    Thank you.
    0
  • Avatar
    Jakarta Development
    Sorry, I got one more question regarding this matter.

    I noticed that the DATE_OF_BIRTH output value when exporting using this script is MM/DD/YYYY even when the Data Type was set to DD/MM/YYYY.

    The output csv using regular export function is correct DD/MM/YYYY.

    How to fix it?

    I tried to make the DATE_OF_BIRTH data type as text.
    Managed to get string data out of it.
    But can't seem to convert that string to date.


    Dim getDatedob as String = document.Field("Document Section 1\DATE_OF_BIRTH").Value
    Dim flipDatedob as String
    flipDatedob = DateTime.ParseExact(getDatedob, "d/M/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None)


    error:

    [Processing error]:

    Document 1: EnclosedDoubleQuote_2: System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) at System.DateTime.ParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style) at Main.Execute(IDocument Document, IProcessingCallback Processing)





    Thank you.
    0
  • Avatar
    Feri Santosa
    Dim getdatedob as date = document.field("Document Section 1\DATE_OF_BIRTH).value

    Dim format as string = "dd-MM-yyyy"
    Dim stringofdate as string = getdatedob.tostring(format)


    0
  • Avatar
    Jakarta Development
    I haven't tested it, because it turned out that I need to set my REGIONAL setting to related format.
    This is suitable for locally used PC.
    I will try this solution if I need to export the project to other PC.

    Thanks a lot @ScanAddicted!

    Dim getdatedob as date = document.field("Document Section 1\DATE_OF_BIRTH).value Dim format as string = "dd-MM-yyyy" Dim stringofdate as string = getdatedob.tostring(format)



    0

Please sign in to leave a comment.