Is there a way to do export excel from server code?

Hi,

I have been trying to generate excel from grid and have been battling with
‘413 request entity too large’ nginx errors. I tried smaller data sets and it seems to be failing at
somewhere in the simplexml_load_string() in generate.php . I wanted to know if there is a way we can
provide the xml data directly to the $xml = simplexml_load_string($xmlString); instead of the $POST (I mean is it the same format
as that used in grid.parse()? The data we are displaying the grid is sourced extremely complex and is generated from several object methods
hence the problem. We need to export excel and am stuck with this client to server posting issues.

My second question is in your doc [url]http://docs.dhtmlx.com/connector__php__grid_data_export.html[/url] its mentioned that

Can I use render_array() method for this because I think that can help…?

Thanks in advance…

I tried the following function but there is no output

function exportgridxls($filteredParticipants = null) {
    global $account, $user, $arr_filters;
    require(SITE_ROOT . 'include/connector/convert.php'); 

    
    $mysqli = new Db;

    $config = new GridConfiguration();
    
    $setHeader = "ID,First Name,Last Name,E-mail,Survey Link,E-mail Sent";
    $setInitWidths = '50,120,150,150,200,130';
    $setColAlign = "center,left,left,center,left,left";

    foreach($account->userDataFields as $dataFieldId => $dataFieldName){
        if($account->dataFieldsVisible[$dataFieldId]) {
            $setHeader .= "," . $dataFieldName;
            $setInitWidths .= ',150';
            $setColAlign .= ",center";           
        };
    };
    $setHeader .= ",Status,Completed,Completion Date,Furthest Page Reached";
    $setInitWidths .= ',100,150,200,250';
    $setColAlign .= ",center,center,left,left"; 
    $config->setHeader($setHeader);
    //$config->setInitWidths($setInitWidths);
    $config->setColAlign($setColAlign);    
    
    //grid data
    $data = array();
    $userParticipants = is_null($filteredParticipants) ? $account->userParticipants : $filteredParticipants;
        
    foreach ($userParticipants as $participant_id => $participant) {
    
        if(empty($participant->data)|| empty($participant->tagging)) $participant->getData(); 
        $pdata = array("id" => $participant->id,"firstname" => $participant->firstName ,"lastname" => $participant->lastName ,"email" => $participant->email,"survey" => RADAR_SURVEY_LINK. 'participant/' . $participant->key);
        $pdata["lastmail"] = $participant->tsLastEmail;

            foreach($account->userDataFields as $dataFieldId => $dataFieldName){
                if($account->dataFieldsVisible[$dataFieldId]) {
                  if(empty($participant->tagging) || !array_key_exists($dataFieldName,$participant->tagging)){
                      $pdata["$dataFieldName"] = "";
                  }else{
                       $pdata["$dataFieldName"] = $participant->tagging["$dataFieldName"];
                  };              

                };//data field
            };
        $pdata["completed"] = ($participant->completed == true) ? 'Completed' : 'Incomplete';
        $pdata["completeddate"] = ($participant->tsComplete == 0) ? '' : date('d-m-Y h:s:i', $participant->tsComplete);
        $data[] = $pdata;
    };
    if(count($data)){
        $convert = new ConvertService(
        RADAR_SURVEY_LINK . "app/ajax_participants/<?=$account->id?>/exportxl"
        );
        $conn = new GridConnector($mysqli, "MySQLi");
        $conn->set_config($config);
        $convert->excel();
        $columns = implode(",",array_keys($data[0]));
        $conn->render_array($data, "id", $columns); 
    };
}

The request to the function returned the following but no excel


Any idea what might be going wrong here ?

The export excel url code

$convert = new ConvertService(
        RADAR_SURVEY_LINK . "app/ajax_participants/<?=$account->id?>/exportxl"
        );

is processed as follows:

   case 'exportxl':
        include SITE_ROOT . 'include/dhxexportxl/generate.php';

I tried the following code
in the client side

grdParticipants.toExcel('/app/ajax_participants/<?=$account->id?>/exportxl');

The header info is:


But I do not see excel exported

The grid is:


The grix_xml variable content from url is

grid_xml:%3Crows%20profile%3D'color'%3E%3Chead%3E%3Ccolumns%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'55'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'int'%20color%3D''%20id%3D'ID'%3E%3C!%5BCDATA%5BID%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'90'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'First%20Name'%3E%3C!%5BCDATA%5BFirst%20Name%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'76'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Last%20Name'%3E%3C!%5BCDATA%5BLast%20Name%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'286'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Email'%3E%3C!%5BCDATA%5BE-mail%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'216'%20align%3D'center'%20type%3D'link'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Link'%3E%3C!%5BCDATA%5BSurvey%20Link%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'153'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'date'%20color%3D''%20id%3D'Emails'%3E%3C!%5BCDATA%5BE-mail%20Sent%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'97'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Respondent%20Type'%3E%3C!%5BCDATA%5BRespondent%20Type%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'83'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Agency'%3E%3C!%5BCDATA%5BAgency%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'97'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Respondent%20Company'%3E%3C!%5BCDATA%5BRespondent%20Company%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'118'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Company%20Assessed'%3E%3C!%5BCDATA%5BCompany%20Assessed%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'78'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Key%20Decision%20Maker'%3E%3C!%5BCDATA%5BKey%20Decision%20Maker%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'85'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Salutation'%3E%3C!%5BCDATA%5BSalutation%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'85'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Auto%20Alert%20Salutation'%3E%3C!%5BCDATA%5BAuto%20Alert%20Salutation%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'57'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Auto%20Alert%20To(s)'%3E%3C!%5BCDATA%5BAuto%20Alert%20To(s)%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20width%3D'125'%20align%3D'center'%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Status'%3E%3C!%5BCDATA%5BStatus%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20width%3D'150'%20align%3D'center'%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Completed'%3E%3C!%5BCDATA%5BCompleted%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'153'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'date'%20color%3D''%20id%3D'Completion%20Date'%3E%3C!%5BCDATA%5BCompletion%20Date%5D%5D%3E%3C%2Fcolumn%3E%3Ccolumn%20%20rowspan%3D%222%22%20%20width%3D'265'%20align%3D''%20type%3D'ro'%20hidden%3D'false'%20sort%3D'str'%20color%3D''%20id%3D'Furthest%20Page%20Reached'%3E%3C!%5BCDATA%5BFurthest%20Page%20Reached%5D%5D%3E%3C%2Fcolumn%3E%3C%2Fcolumns%3E%3C%2Fhead%3E%0A%3Crow%3E%3Ccell%3E%3C!%5BCDATA%5B19975%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BFabienne%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BFerrand%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5Bvinu.felix%40gmail.com%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BFrench%20RADAR%20Demo%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B2016-09-22%2019%3A35%3A31%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BGocad%20Services%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BCh%C3%A8re%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BACTIVE%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BIncomplete%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5B%C2%A0%5D%5D%3E%3C%2Fcell%3E%3Ccell%3E%3C!%5BCDATA%5BFrench%20RADAR%20Demo%20-%20Intro%20page%5D%5D%3E%3C%2Fcell%3E%3C%2Frow%3E%3C%2Frows%3E

and dhtmlx grid uses
enableSmartRendering ,true,150
enablePreRendering 75

We are using nginx/1.10.1 with php 5.3.3
and dhtmlx pro 5

Anyone please help.

Hi Guys,

Any idea what could be wrong ??

:open_mouth:

When you are using smart-rendering or dynamic loading, the data export will include only part of rows. You need to use server-side export in such case.

Anyway, as for your original issue, when working with client-side export, “/app/ajax_participants/<?=$account->id?>/exportxl” points to the export script, not to the connector, right? Does this script works for any other dataset ?

According to provided logs, export must run correctly. If necessary I can share a sample which works correctly locally.

Hi Stanislav,

Apologies for the delay in response.

Brilliant, you are correct! something in the server was stopping the excel from generating.
The only other issue is that I’m getting this message before the exported excel opens in excel


Any idea why?

Please post an example of such file ( result of export, which shows message during opening )
You can send it directly to support@dhtmlx.com with reference to this post, or attach to the post

Hi Stanislav,

its my fault. I tried to change public $outputType = ‘excel2007’;
in the gridExcelGenerator.php, making it to excel2003 fixed it.

Thank you for checking back so quick.

Hi Stanislav,

Thank you for all your help.
One last question. When I’m trying to export using our URL (I have sent the url in your support email with forum topic).
We get corruption( 0 byte xls file) when we have 600-1000 rows but it works fine in your website dhtmlx export link
most of the time. I do not see any error logs in the folder or on screen when this happens so I’m a bit confused.

We are using apache 2.2.17 /php 5.3.22
running on Windows server 2008 enterprise 4GB RAM/6 GB Free space on drive.

the folder cfg files for apache are attached.

Can you suggest what config system is required for export of excel?
The usage is not frequent but this fails everytime on our server when we have so many rows
foldercfg.zip (554 Bytes)

Most probably it is the memory limit of php script
Try to add the next to the .htacces

php_value memory_limit 64M

Online version uses Java export service, so it may have a bit different limits.

I tried to test on microsoft azure by placing the generator code in azure cloud.
It gives me
“The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.”

Is there anything that we need to specifically configure if we are hosting the code in azure cloud?

-Thanks,

Try to increase the PHP memory limit; it is a common pitfall. The big excel files may require a lot of memory to be constructed.