Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:44:05+00:00 2026-06-09T01:44:05+00:00

I have a question about exporting dojo data grid to excel file. I have

  • 0

I have a question about exporting dojo data grid to excel file. I have made it work with csv file using the dojo exporter and some php code. However, how do I make it to save as excel file. I now about pear and some other libraries, but there has to be similar solution to the one I am using for the csv. Also, when I create my own exporter in dojo, does it need to have something more specific then the code I am using for the csv exporter. Also, what do I need to change in the php code to make it save as xls. The code is below. Thanks a lot in advance.

My dojo exporter:

function exportCsv(){
    var g = dijit.byId("grid");
    g.exportGrid("csv",{
                writerArgs: {
                    separator: ","
                }
                }, function(str){


                        var form = document.createElement('form');
                        dojo.attr(form, 'method', 'POST');
                        document.body.appendChild(form);
                        dojo.io.iframe.send({
                                url: "csv.php",
                                form: form,
                                method: "POST",
                                content: {exp: str},
                                timeout: 15000
                        });
                        document.body.removeChild(form);

                        }); 
}

My php code working with csv:

<?

$time = time();
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=\"grid_$time.csv\"");
$exportedData = $_POST['exp'];


echo stripslashes($exportedData);
exit;
?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:44:07+00:00Added an answer on June 9, 2026 at 1:44 am

    Here is a nice PHP tool, well suited for the purpose.

    http://www.phpclasses.org/package/1919-PHP-Stream-wrapper-to-read-and-write-MS-Excel-files.html

    The setup is quite simple, you have most of it setup to passthrough the .csv file as download attachment allready, try the following code.

    Conversion of CSV to XLS

    First setup files csv-data and classes

    require_once "excel.php"; 
    define('_CSV_SEPARATOR_', ',');
    // the excel class setsup xlsfile stream writer, point it to a tmp file
    $export_file = "xlsfile://tmp/example.xls"; 
    // the csv-contents must be put into an array, 
    // serialized and sent to the stream
    $import_file = "/path/to/CSV_FILE.csv";
    $import=explode("\n", file_get_contents($import_file));
    // column names should be first line
    $header = array_shift($import);
    

    Making sure, everything is looking nicely

    $header = explode(_CSV_SEPARATOR_, $header);
    for($i = 0; $i < count($header); $i++)
        $header[$i] = trim($header[$i]);
    

    Looping lines in remaining contents of csv-data

    // rest of text is data, split em up and list them with array indices,
    // and associative names as key in the rowdata
    $assocData = array();
    
    foreach($import as $line) {
       $row = explode(_CSV_SEPARATOR_, $line);
       $rowData = array();
       $unknowncount = 0;
       for($i = 0; $i < count($row); $i++) {
           if(!empty($header[$i])) $column = $header[$i];
           else $column = 'UNK'.$unknowncount++;
    
           $rowData[$column] = trim($row[$i]);
       }
       $assocData[]=$rowData;
    }
    

    Now, we write data to the export tmp-file and conversion is done

    $fp = fopen($export_file, "wb"); 
    if (!is_resource($fp)) 
    { 
        die("Cannot open $export_file"); 
    } 
    fwrite($fp, serialize($assocData)); 
    fclose($fp); 
    

    Throughputting the outputted tmp-file to client

    $export_file = "xlsfile://tmp/example.xls"; 
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
    header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); 
    header ("Cache-Control: no-cache, must-revalidate"); 
    header ("Pragma: no-cache"); 
    header ("Content-type: application/x-msexcel"); 
    header ("Content-Disposition: attachment; filename=\"" . basename($export_file) . "\"" ); 
    header ("Content-Description: PHP/INTERBASE Generated Data" ); 
    readfile($export_file); 
    exit; 
    

    Good luck and enjoy 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question about data joining. Say I have some elements that each contain a
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body
I have a question about SqlDataReader: Is there some way to modificated the values
Quick question about MSBuild. I have the following MSBuild file in directory d:\MyDirectory <Project
I had a question about boost python. I've been working on exporting some functionality
I have an Excel file with a large set of data. The built-in graphs
I have some questions about module exporting and their inheritance in node. I know
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.