We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    Is there a way to export the content in a database to an Excel-file? I use dbEdit in Evolution 1.03, and I wan’t to make an "Export to Excel"-button in the dbEdit-controlpanel for my organisation-customers.

    I remember I saw it once, but I just can’t find it.

    Thanks. smiley
      I think, thererfor I am! But what I am, and why...?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Google is our friend:
      Use a SELECT ... INTO OUTFILE ... statement to write a CSV file or a tab-delimited file that you can open directly in Excel.

      I also found this
      <?php
      // Connect database.
      mysql_connect("localhost","","");
      mysql_select_db("tutorial");
      
      // Get data records from table.
      $result=mysql_query("select * from name_list order by id asc");
      
      // Functions for export to excel.
      function xlsBOF() {
      echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
      return;
      }
      function xlsEOF() {
      echo pack("ss", 0x0A, 0x00);
      return;
      }
      function xlsWriteNumber($Row, $Col, $Value) {
      echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
      echo pack("d", $Value);
      return;
      }
      function xlsWriteLabel($Row, $Col, $Value ) {
      $L = strlen($Value);
      echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
      echo $Value;
      return;
      }
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Content-Type: application/force-download");
      header("Content-Type: application/octet-stream");
      header("Content-Type: application/download");;
      header("Content-Disposition: attachment;filename=orderlist.xls ");
      header("Content-Transfer-Encoding: binary ");
      
      xlsBOF();
      
      /*
      Make a top line on your excel sheet at line 1 (starting at 0).
      The first number is the row number and the second number is the column, both are start at '0'
      */
      
      xlsWriteLabel(0,0,"List of car company.");
      
      // Make column labels. (at line 3)
      xlsWriteLabel(2,0,"No.");
      xlsWriteLabel(2,1,"Company");
      
      $xlsRow = 3;
      
      // Put data records from mysql by while loop.
      while($row=mysql_fetch_array($result)){
      
      xlsWriteNumber($xlsRow,0,$row['id']);
      xlsWriteLabel($xlsRow,1,$row['name']);
      
      $xlsRow++;
      }
      xlsEOF();
      exit();
      ?>

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 29076
        • 615 Posts
        Thanks Susan. smiley Again. smiley

        Found another way, it was right there in the Export settings in phpMyAdmin. But I would still like to have the export function on a button (in dbEdit in Manager), so I’ll try the script in your example.
          I think, thererfor I am! But what I am, and why...?