Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COPY TO an Excel - including Memo fields
Message
From
29/10/2003 12:30:15
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
29/10/2003 12:02:58
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00844067
Message ID:
00844155
Views:
32
Tom,
Memo field might have CRLF in it. Yuri's solution is the way to go IMHO.
Cetin

>just ran into this last week. This is what I used as a solution:
>
>lcFieldString = ''
>lcMemo = ''
>
>
>CREATE CURSOR memx (pk I, memx m)
>INSERT INTO memx VALUES (1,"This is a memo field")
>INSERT INTO memx VALUES (2,"This is a memo field too")
>
>
>lnFieldCount = AFIELDS(laGetFields) && Builds array of fields from the
>                                    && selected table.
>
>*!* Prompt for Output file and use Low-Level functions
>*!* to create it.
>lcFile = "c:\temp\test.csv"
>lnHandle = FCREATE(lcFile)
>
>*!* Starts scanning the table and converts the fields
>*!* values according to their types **
>SCAN
>   WAIT WINDOW STR(RECNO()) + ' Of ' + STR(RECCOUNT()) NOWAIT
>
>   FOR lnCount = 1 TO lnFieldCount
>      lcType = laGetFields(lnCount, 2)
>
>      IF lcType # 'G' && Don't try to turn a general field into a string
>         lcString = EVALUATE(laGetFields(lnCount, 1))
>      EndIf
>
>      DO CASE
>         CASE lcType = 'M' && Process the Memo Fields
>            lnMemoLines = MEMLINES(EVALUATE(laGetFields(lnCount,1)))
>            FOR lnLoop = 1 TO lnMemoLines
>               IF lnLoop < lnMemoLines
>                  lcMemo = lcMemo + ;
>                     ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
>                                   lnLoop)) + ' '
>               ELSE
>                  lcMemo = lcMemo + ;
>                     ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
>                                   lnLoop))
>               ENDif
>            ENDfor
>
>            lcString = lcMemo
>            lcMemo = ''
>         CASE lcType = 'G' && Process the General Fields
>            lcString = 'Gen'
>         CASE lcType = 'D' && Process the Date Fields
>            lcString = DTOC(lcString)
>         CASE lcType = 'T' && Process the DateTime Fields
>            lcString = TTOC(lcString)
>         CASE lcType = 'N' && Process the Numeric Fields
>            lcString = STR(lcString, LEN(STR(lcString)), 2)
>         CASE lcType = 'I' && Process the Integer Fields
>            lcString = STR(lcString)
>         CASE lcType = 'L' && Process the Logical Fields
>            IF lcString = .T.
>               lcString = 'T'
>            ELSE
>               lcString = 'F'
>            ENDif
>      ENDcase
>
>      IF lnCount < lnFieldCount && Determines if the last field was
>                                && processed and sets the closing quote.
>         lcFieldString = lcFieldString + '"' + lcString + '"' + ','
>      ELSE
>         lcFieldString = lcFieldString + '"' + lcString + '"'
>      ENDif
>   ENDfor
>
>   FPUTS(lnHandle, lcFieldString) && Writes string to the text file.
>   lcFieldString = ''
>ENDscan
>
>FCLOSE(lnHandle)
>
>CLOSE All
>CLEAR All
>WAIT WINDOW 'Text File Creation Completed' NOWAIT
>
>
>
>
>Excel will properly read and parse a CSV file...
>
>
>>I saw the answer to this awhile ago and thought I saved it for future reference....now the future is here and I can't find it!
>>
>>I am using the COPY TO command to export records to an Excel spreadsheet but I also need to export the text in the memo field for each record. I know there was a limit of 254 chars on the workaround, and that is fine.
>>
>>Can someone refresh my memory?
>>
>>tks,
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform