If you are looking to simply have the user download the report rather than save it on the server, this is some code we use for that. The report is placed in a text var (should have probably used a blob since it ends up in a blob... Oh, well...) then write the blob into the output.
Obviously we don't send a CSV file, but you can fix that.

+++++++
        C_TEXT($Report_t)
        $Report_t:=""
        C_BLOB($OutBlob_x)
        
        $row := $ProfileRowSet->getRow
        while($ProfileRowSet->next)
                $Report_t:=$Report_t+\\
                        $row{"name"}+Char(tab)+ \\
                        $row{"contactName"}+Char(tab)+ \\
                        $row{"artistCategory"}+Char(tab)+ \\  
                        $row{"badgeList"}+Char(tab)+ \\
                        $row{"email"}+Char(tab)+ \\
                        $row{"phone"}+Char(13)
                        
        end while
        text to blob($Report_t;$OutBlob_x;text without length)

set response header("Content- Disposition";"attachment;filename=JuriedProfiles.txt")
        
/* Per AF, If IE user elects "Open" instead of "Save" option, IE may delete the cached file before it can be opened in a supporting application. this can result in File Not Found error or an empty document. Setting cache control to private should stop that. */

        set cache control("private")
        
        write blob ($OutBlob_x;"application/vnd.ms-excel")

++++ End Code

On Nov 22, 2006, at 9:11 AM, Bart Alcorn wrote:

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/



Kind Regards,

*********************************************************************
Bill Leddy
[EMAIL PROTECTED]
William Leddy Business Consulting
Custom Database Solutions
3145 17th Street
Sacramento, CA  95818                              Phone: (916) 444-2903

                        "On the desktop and on the web"

*********************************************************************


_______________________________________________
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