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.
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.
Comments
21 comments
What ABBYY application are you using to achieve this?
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
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
First You should change VBScript to VBNet
Then you should put : this code
Imports system.io
on the most top of script
Result is as expected.
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?
Maybe you could try document.field("country_id).text instead of document.field("country_id").value
See if its works
Is there any other way to create hidden field with a defined value?
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
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:
Result on csv is just "" (empty)
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.
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
So I can just add more conditional for multiple hidden fields?
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:
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:
Result:
DATE_OF_BIRTH
Standard CSV export: 13/04/1989
Custom CSV export: 4/13/1989
Thank you.
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.
error:
Thank you.
Dim format as string = "dd-MM-yyyy"
Dim stringofdate as string = getdatedob.tostring(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!
Please sign in to leave a comment.