Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting a table into a csv file

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
Hi all,

I'm currently trying to export a table into a csv file, I also want the first line in the csv file to be the field names.

By using the following code:
Code:
exportspreadsheet("POHeader.db", ":WORK:POHeader1.csv", True )

I can create a csv file containing everything I need. However, there is also the following character exported after the final line:



I cannot have accept that as this csv file is to be directly imported into another system and the  will cause a crash.

So I tried using the following code:

Code:
var

ts           textsream
tc           tcursor
mystring     string
fieldnames   Array[] string
cNum         number

endvar

ts.open(":WORK:POHeader.csv","nw")

tc.open("POHeader.db")
tc.enumFieldnames(fieldNames)

cNum = 1

scan tc:

	 myString = ""
	 while cNum <= 7 ; the number of fields

		  myString = myString+tc.(fieldnames[cNum])
		  if cNum = 7 ; last field
				then    myString = myString+""
					 else    myString = myString+","
		  endif
		  cNum = cNum+1

	 endWhile

	 ts.writeLine(myString)
	 cNum = 1

endscan

tc.close()
ts.close()

This gives me all data without the field names, which I need!

Has anyone any ideas?

Thanks in advance,

Woody
 
cnum=fieldnames.size() ; # of items in fieldnames array

ts.writestring(fieldnames[1])
for i from 2 to cNum
ts.writestring(","+fieldnames)
endfor
ts.writeline("") ; newline

scan tc :
ts.writestring(tc.(1))
for i from 2 to cNum
ts.writestring(","+tc.(i))
endfor
ts.writeline("")
endscan



Tony McGuire
"It's not about having enough time. It's about priorities.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top