Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Download to CSV

Questions related to customising nuBuilder Forte with JavaScript or PHP.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Download to CSV

Unread post 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;
tpolimeni28
Posts: 25
Joined: Mon Apr 04, 2022 4:00 pm
Has thanked: 1 time

Re: Download to CSV

Unread post 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;
You do not have the required permissions to view the files attached to this post.
pmjd
Posts: 132
Joined: Fri Mar 12, 2021 10:38 am
Has thanked: 3 times
Been thanked: 1 time

Re: Download to CSV

Unread post 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.
tpolimeni28
Posts: 25
Joined: Mon Apr 04, 2022 4:00 pm
Has thanked: 1 time

Re: Download to CSV

Unread post 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.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Download to CSV

Unread post by kev1n »

Maybe by using tab-separated values (\t) ?

This article describes some tweaks.
tpolimeni28
Posts: 25
Joined: Mon Apr 04, 2022 4:00 pm
Has thanked: 1 time

Re: Download to CSV

Unread post 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;
tpolimeni28
Posts: 25
Joined: Mon Apr 04, 2022 4:00 pm
Has thanked: 1 time

Re: Download to CSV

Unread post 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.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Download to CSV

Unread post by kev1n »

Hello,

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