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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV exported has a character at the end when opened in excel

Status
Not open for further replies.
Jul 4, 2002
17
0
0
GB
Problem

Exporting a file with
copy to x:\path\delgda.csv type delimited

when opened in excel it has a square character after the last line - as a new line.

How can I get rid of it, within the programme, and what is it?

Note for those that help - I take more that I give to this site but I am studying to try and become more use!

 
The "square" is probably an ASCII eof (0x1A). DOS files used these to indicate the real end of file, since the OS always gave file lengths in terms of physical blocks (often 256, 512 or 1024 characters).

Short of making the file one character shorter, there isn't much you can do about it. Can you just ignore it?

Here's some code I wrote a while back to strip both the EOF and the trailing CRLF.
Code:
*S_TR_ECL.PRG (Strip_Trailing_Eof_CrLf)
l_nSize = FSEEK(lnHandle,0,2)   && Determine file size
l_nOrgSize = l_nSize && save so we know if we've stripped anything
= FSEEK(lnHandle, -3, 2) && Sneak a peak at the last 3 characters
l_cLastChars = FREAD(lnHandle,3)
l_nLastChar = INT(ASC(SUBSTR(l_cLastChars,3,1)))

IF l_nLastChar = chr(26) && ASCII eof [or 0x1A in VFP]
   WAIT WINDOW "Stripping EOF" TIMEOUT 5 NOWAIT
   l_nSize = l_nSize - 1
   l_cLastChars = LEFT(l_cLastChars, 2) && throw away last
ENDIF

IF RIGHT(l_cLastChars, 2) = CHR(13)+CHR(10) && CRLF
   WAIT WINDOW "Stripping CRLF" TIMEOUT 5 NOWAIT
   l_nSize = l_nSize - 2
ENDIF

IF l_nSize <> l_nOrgSize
   = FCHSIZE(lnHandle, l_nSize) && make it shorter
ENDIF
********

Note: The extra code checking is due to the fact that while FP 2.x adds the EOF character, VFP doesn't. So you have to handle things a bit different if the last one character isn't EOF.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top