Page 4 of 4

Re: Download to CSV

Posted: Mon Apr 04, 2022 11:20 pm
by kev1n
Hi,

Try this:

Remove the line

Code: Select all

include("nuconfig.php");
and replace it with

Code: Select all

global $nuConfigDBHost;
global $nuConfigDBName;
global $nuConfigDBUser;
global $nuConfigDBPassword;

Re: Download to CSV

Posted: Tue Apr 05, 2022 3:00 pm
by tpolimeni28
Hello so this worked, however the data that is being placed in the excel sheet isn't lining up correctly. Some data is being placed on the same rows and such its not getting separated into the physical columns/rows as I have it in nuBuilder. The header row has all columns in each cell straight across the top for the number of rows in the db if that makes sense. I have attached a screen capture of the NuBuilder page along with what the excel sheet looks like. Any suggestions on how to fix this? I have attached photos
kev1n wrote: Mon Apr 04, 2022 11:20 pm Hi,

Try this:

Remove the line

Code: Select all

include("nuconfig.php");
and replace it with

Code: Select all

global $nuConfigDBHost;
global $nuConfigDBName;
global $nuConfigDBUser;
global $nuConfigDBPassword;

Re: Download to CSV

Posted: Tue Apr 05, 2022 3:56 pm
by pmjd
Try setting the delimiter (the character that will be used to seperate out the entries) as follows

Code: Select all

// Set the CSV delimiter
$delimiter = ',';
Also Excel will import CSV files in different ways, can be worth going through the menu
Data > Get External Data > From Text
to manully select the format and delimiter.

Re: Download to CSV

Posted: Tue Apr 05, 2022 4:20 pm
by tpolimeni28
Thanks after I posted this, I figured out that I could do the following as well.. open a new page, blank doc, go to data, click cell a1 then do data from CSV. IS there away that I could make this export into a more readable excel file without doing this little trick. I didnt think of that until after I got keyboard happy and just posted.
pmjd wrote: Tue Apr 05, 2022 3:56 pm Try setting the delimiter (the character that will be used to seperate out the entries) as follows

Code: Select all

// Set the CSV delimiter
$delimiter = ',';
Also Excel will import CSV files in different ways, can be worth going through the menu
Data > Get External Data > From Text
to manully select the format and delimiter.

Re: Download to CSV

Posted: Tue Apr 05, 2022 4:48 pm
by kev1n
Maybe by using tab-separated values (\t) ?

This article describes some tweaks.

Re: Download to CSV

Posted: Tue Apr 05, 2022 10:10 pm
by tpolimeni28
kev1n wrote: Tue Apr 05, 2022 4:48 pm Maybe by using tab-separated values (\t) ?

This article describes some tweaks.
Thank you I see the column headers are just listed as column 1, 2, 3, etc Im assuming it has to do with this section of the code. Could I replace this code with naming the columns or do you have another suggestion. Im not a php guy so sorry for the questions

Code: Select all

//Get the column names.
$columnNames = array();
if(!empty($rows)){
    //We only need to loop through the first row of our result
    //in order to collate the column names.
    $firstRow = $rows[0];
    foreach($firstRow as $colName => $val){
        $columnNames[] = $colName;

Re: Download to CSV

Posted: Mon Dec 02, 2024 7:44 pm
by tpolimeni28
kev1n wrote: Sat Nov 23, 2019 10:49 am Only add the "Download to CSV" button if the Print button exists:

Code: Select all

if(nuFormType() == 'browse'){
    if ($('#nuPrintButton').length == 1) {
       nuAddActionButton('nuRunPHPHidden', 'Download to CSV', 'nuSetProperty("browse_sql",nuCurrentProperties().browse_sql); nuRunPHP("DownloadCSV")');
   }
}
Hello, I tried this code and when I attempt to use this, I get an error in the custom code field that Code must be both unique and not blank.

Re: Download to CSV

Posted: Mon Dec 02, 2024 8:20 pm
by kev1n
Hello,

Pass 0 or false as 2nd parameter in nuRunPHP(...)