On Nov 22, 2006, at 11:23 AM, Michael Check wrote:

We have an A4D system that we've created for a client that tracks
registrations.  They would like to have the system export reports as
CSV files in order to use them in Excel.  So I think our goal is to
allow the user to enter the criteria for the report. we would generate
it and then present the file for download to their system.

Does anyone have any experience with this technique or have some
suggestions on how to proceed with this feature?

Below is very simplified but actual code to create the CSV file via Active 4D.

Obviously you have to first make sure you have a selection of records, etc. This is just the code to create the CSV.

Be sure to explicitly define the destination, root relative pathing did not work for us.

Also, in order to serve the result you need to add to your ExtensionMap.ini (in your Active 4D folder) the following line:
.CSV    TEXT    XCEL    application/vnd.ms-excel


// Create CSV file via Active 4D code
// char(34) = double quote

C_text($packet)
C_time($docRef)
C_longint($loop)

$docRef:=Create document("/Drive/app_folder/web_folder/orders/ orders.csv")

// Header line
$packet:=char(34)+"Order ID"+char(34)+","
$packet:=$packet+char(34)+"Status"+char(34)+","
$packet:=$packet+char(34)+"Part Number"+char(34)+char(carriage return)
SEND PACKET($docRef;$packet)

// Data loop
for ($loop; 1; records in selection([Orders]))

        goto selected record([Orders];$loop)
        
        $packet:=char(34)+string([Orders]Orders_ID)+char(34)+","
        $packet:=$packet+char(34)+[Orders]Status+char(34)+","
$packet:=$packet+char(34)+[LineItems]PartNumber +char(34)+char(carriage return)
        
        SEND PACKET($docRef;$packet)
        
end for

CLOSE DOCUMENT($docRef)

// end A4D code

Hope this helps.

--
Bart Alcorn
National Service Center
800-500-6421 x 2360
AIM/iChat: balcornnsc


_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to