close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Export to CSV or XML extension

Thread began 6/22/2018 11:05 am by vernon webb | Last modified 6/25/2018 12:38 pm by Ray Borduin | 111 views | 7 replies |

vernon webb

Export to CSV or XML extension

Is there an extension or that allows me to quickly setup an export to CSV or XML?

Sign in to reply to this post

Ray BorduinWebAssist

We don't offer one, but it is easy to build.

Just build an HTML page that displays your content comma separated just like you would any other results page. You will have to view source on the page to make sure it looks right. Commas after each value and new lines for each row.

Once you have it formatted properly you can add a header to the top of the page to make it download like a csv file instead of display in the browser like:

php:
<?php

    header
('Content-Type: application/csv');
    
// tell the browser we want to save it instead of displaying it
    
header('Content-Disposition: attachment; filename="csvfilename.csv";');
?>
Sign in to reply to this post

vernon webb

Any clue on fixing this? The recordset does exist

php:
<?php

//Export to Excel Server Behavior
if (isset($_GET['Export'])&&($_GET['Export']=="Export Spreadsheet")){
    
$delim="";
    
$delim_replace="";
    if(
$delim==""){
        
$lang=(strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'],",")===false)?$_SERVER['HTTP_ACCEPT_LANGUAGE']:substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'],","));
        
$semi_array=array("af","zh-hk","zh-mo","zh-cn","zh-sg","zh-tw","fr-ch","de-li","de-ch","it-ch","ja","ko","es-do","es-sv","es-gt","es-hn","es-mx","es-ni","es-pa","es-pe","es-pr","sw");
        
$delim=(in_array($lang,$semi_array) || substr_count($lang,"en")>0)?",":";";
    }
    
$output="";
    
$output="1 = RecruitSavvy   2 = CareerSoft   3 = Warm Calling   4 = Unclaimed Property that 5 = Resume Search Only   6 = Career Changers   7 = Brokerage\n\n";
    
$include_hdr="1";
    if(
$include_hdr=="1"){
        
$totalColumns_WADAcustomers=mysql_num_fields($WADAcustomers);
        for (
$x=0$x<$totalColumns_WADAcustomers$x++) {
            if(
$x==$totalColumns_WADAcustomers-1){$comma="";}else{$comma=$delim;}
            
$output $output.(ereg_replace("_"" ",mysql_field_name($WADAcustomers$x))).$comma;
        }
        
$output $output."\r\n";
    }

    do{
$fixcomma=array();
            foreach(
$row_WADAcustomers as $r){array_push($fixcomma,ereg_replace($delim,$delim_replace,$r));}
        
$line join($delim,$fixcomma);
            
$line=ereg_replace("\r\n"" ",$line);
            
$line "$line\n";
            
$output=$output.$line;}while($row_WADAcustomers mysql_fetch_assoc($WADAcustomers));
    
header("Content-Type: application/xls");
    
header("Content-Disposition: attachment; filename=client_report.csv");
    
header("Content-Type: application/force-download");
    
header("Cache-Control: post-check=0, pre-check=0"false);
    echo 
$output;
    die();
}
?>
Sign in to reply to this post

Ray BorduinWebAssist

php:
<?php

//Export to Excel Server Behavior
if (isset($_GET['Export'])&&($_GET['Export']=="Export Spreadsheet")){
    
$delim="";
    
$delim_replace="";
    if(
$delim==""){
        
$lang=(strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'],",")===false)?$_SERVER['HTTP_ACCEPT_LANGUAGE']:substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'],","));
        
$semi_array=array("af","zh-hk","zh-mo","zh-cn","zh-sg","zh-tw","fr-ch","de-li","de-ch","it-ch","ja","ko","es-do","es-sv","es-gt","es-hn","es-mx","es-ni","es-pa","es-pe","es-pr","sw");
        
$delim=(in_array($lang,$semi_array) || substr_count($lang,"en")>0)?",":";";
    }
    
$output="";
    
$output="1 = RecruitSavvy   2 = CareerSoft   3 = Warm Calling   4 = Unclaimed Property that 5 = Resume Search Only   6 = Career Changers   7 = Brokerage\n\n";
    
$include_hdr="1";
    if(
$include_hdr=="1"){
        
$columns array_keys($WADAcustomers->Results); 
        for (
$x=0$x<sizeof($columns); $x++) {
            if(
$x!=0$output.=","
            
$output.= (ereg_replace("_"" ",$columns[$x]));
        }
        
$output $output."\r\n";
    }

   for (
$x=0$x<sizeof($WADAcustomers->Results); $x++) {
        
$fixcomma=array();
        foreach(
$WADAcustomers->Results[$x] as $r){array_push($fixcomma,ereg_replace($delim,$delim_replace,$r));}
        
$line join($delim,$fixcomma);
        
$line=ereg_replace("\r\n"" ",$line);
        
$line "$line\n";
        
$output=$output.$line;
    }
    
header("Content-Type: application/xls");
    
header("Content-Disposition: attachment; filename=client_report.csv");
    
header("Content-Type: application/force-download");
    
header("Cache-Control: post-check=0, pre-check=0"false);
    echo 
$output;
    die();
}
?>
Sign in to reply to this post

vernon webb

There's a problem with this line:

$output.= (ereg_replace("_", " ",$columns[$x]));

Sign in to reply to this post

Ray BorduinWebAssist

The line:
$columns = array_keys($WADAcustomers);

should be:
$columns = array_keys($WADAcustomers->Results);

I've updated it above.

Sign in to reply to this post

vernon webb

Still no good. there was a semicolon missing also which I fixed here

if($x!=0) $output.=",";

But when I hit the Export Spreadsheet I get a 500 error

Sign in to reply to this post

Ray BorduinWebAssist

Your code uses the function: ereg_replace();

That function has been removed in php7, so the code had to be updated accordingly. Here is the updated code:

php:
<?php

//Export to Excel Server Behavior
if (isset($_GET['Export'])&&($_GET['Export']=="Export Spreadsheet")){
    
$delim="";
    
$delim_replace="";
    if(
$delim==""){
        
$lang=(strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'],",")===false)?$_SERVER['HTTP_ACCEPT_LANGUAGE']:substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'],","));
        
$semi_array=array("af","zh-hk","zh-mo","zh-cn","zh-sg","zh-tw","fr-ch","de-li","de-ch","it-ch","ja","ko","es-do","es-sv","es-gt","es-hn","es-mx","es-ni","es-pa","es-pe","es-pr","sw");
        
$delim=(in_array($lang,$semi_array) || substr_count($lang,"en")>0)?",":";";
    }
    
$output="";
    
$output="1 = RecruitSavvy   2 = CareerSoft   3 = Warm Calling   4 = Unclaimed Property that 5 = Resume Search Only   6 = Career Changers   7 = Brokerage\n\n";
    
$include_hdr="1";
    if(
$include_hdr=="1"){
        
$columns array_keys($WADAcustomers->Results[0]); 
        for (
$x=0$x<sizeof($columns); $x++) {
            if(
$x!=0$output.=",";
            
$output.= str_replace("_"" ",$columns[$x]);
        }
        
$output $output."\r\n";
    }

   for (
$x=0$x<sizeof($WADAcustomers->Results); $x++) {
        
$fixcomma=array();
        foreach(
$WADAcustomers->Results[$x] as $r){array_push($fixcomma,str_replace($delim,$delim_replace,$r));}
        
$line join($delim,$fixcomma);
        
$line=str_replace("\r\n"" ",$line);
        
$line "$line\n";
        
$output=$output.$line;
    }
    
header("Content-Type: application/xls");
    
header("Content-Disposition: attachment; filename=client_report.csv");
    
header("Content-Type: application/force-download");
    
header("Cache-Control: post-check=0, pre-check=0"false);
    echo 
$output;
    die();
}
?>
Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...