Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    alex
    alex's Avatar
    Guest
    try this code

    <?
    // Connect database.
    mysql_connect("localhost","root","");
    mysql_select_db("testdb");

    // Get data records from table.
    $result=mysql_query("select * from sales");

    // 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,"Report");

    // Make column labels. (at line 3)
    xlsWriteLabel(2,0,"Id");
    xlsWriteLabel(2,1,"Gas");
    xlsWriteLabel(2,2,"Cost Amount");
    xlsWriteLabel(2,3,"Retail");
    xlsWriteLabel(2,4,"Gross Profit");
    xlsWriteLabel(2,5,"new");

    $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['GAS']);
    xlsWriteNumber($xlsRow,2,$row['CostAmount']);
    xlsWriteNumber($xlsRow,3,$row['Retail']);
    xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
    xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

    $xlsRow++;
    }
    xlsEOF();
    exit();
    ?>

  2. #2
    Sunita N
    Sunita N's Avatar
    Guest

    Excel sheet writer performace in php?

    I have a thousands of recordsets from mysql database which need to be exported to excel sheet. I am using pear excel sheet writer in php to export the data to excels ,but it is taking too long time (15-20 mins ) to export to excel .Any one please help me to get it done in seconds.

  3. #3
    alex
    alex's Avatar
    Guest
    try this code

    <?
    // Connect database.
    mysql_connect("localhost","root","");
    mysql_select_db("testdb");

    // Get data records from table.
    $result=mysql_query("select * from sales");

    // 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,"Report");

    // Make column labels. (at line 3)
    xlsWriteLabel(2,0,"Id");
    xlsWriteLabel(2,1,"Gas");
    xlsWriteLabel(2,2,"Cost Amount");
    xlsWriteLabel(2,3,"Retail");
    xlsWriteLabel(2,4,"Gross Profit");
    xlsWriteLabel(2,5,"new");

    $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['GAS']);
    xlsWriteNumber($xlsRow,2,$row['CostAmount']);
    xlsWriteNumber($xlsRow,3,$row['Retail']);
    xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
    xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

    $xlsRow++;
    }
    xlsEOF();
    exit();
    ?>

  4. #4
    alex
    alex's Avatar
    Guest
    try this code

    <?
    // Connect database.
    mysql_connect("localhost","root","");
    mysql_select_db("testdb");

    // Get data records from table.
    $result=mysql_query("select * from sales");

    // 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,"Report");

    // Make column labels. (at line 3)
    xlsWriteLabel(2,0,"Id");
    xlsWriteLabel(2,1,"Gas");
    xlsWriteLabel(2,2,"Cost Amount");
    xlsWriteLabel(2,3,"Retail");
    xlsWriteLabel(2,4,"Gross Profit");
    xlsWriteLabel(2,5,"new");

    $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['GAS']);
    xlsWriteNumber($xlsRow,2,$row['CostAmount']);
    xlsWriteNumber($xlsRow,3,$row['Retail']);
    xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
    xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

    $xlsRow++;
    }
    xlsEOF();
    exit();
    ?>

  5. #5
    alex
    alex's Avatar
    Guest
    try this code

    <?
    // Connect database.
    mysql_connect("localhost","root","");
    mysql_select_db("testdb");

    // Get data records from table.
    $result=mysql_query("select * from sales");

    // 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,"Report");

    // Make column labels. (at line 3)
    xlsWriteLabel(2,0,"Id");
    xlsWriteLabel(2,1,"Gas");
    xlsWriteLabel(2,2,"Cost Amount");
    xlsWriteLabel(2,3,"Retail");
    xlsWriteLabel(2,4,"Gross Profit");
    xlsWriteLabel(2,5,"new");

    $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['GAS']);
    xlsWriteNumber($xlsRow,2,$row['CostAmount']);
    xlsWriteNumber($xlsRow,3,$row['Retail']);
    xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
    xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

    $xlsRow++;
    }
    xlsEOF();
    exit();
    ?>

  6. #6
    alex
    alex's Avatar
    Guest
    try this code

    <?
    // Connect database.
    mysql_connect("localhost","root","");
    mysql_select_db("testdb");

    // Get data records from table.
    $result=mysql_query("select * from sales");

    // 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,"Report");

    // Make column labels. (at line 3)
    xlsWriteLabel(2,0,"Id");
    xlsWriteLabel(2,1,"Gas");
    xlsWriteLabel(2,2,"Cost Amount");
    xlsWriteLabel(2,3,"Retail");
    xlsWriteLabel(2,4,"Gross Profit");
    xlsWriteLabel(2,5,"new");

    $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['GAS']);
    xlsWriteNumber($xlsRow,2,$row['CostAmount']);
    xlsWriteNumber($xlsRow,3,$row['Retail']);
    xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
    xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

    $xlsRow++;
    }
    xlsEOF();
    exit();
    ?>

  7. #7
    alex
    alex's Avatar
    Guest
    try this code

    <?
    // Connect database.
    mysql_connect("localhost","root","");
    mysql_select_db("testdb");

    // Get data records from table.
    $result=mysql_query("select * from sales");

    // 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,"Report");

    // Make column labels. (at line 3)
    xlsWriteLabel(2,0,"Id");
    xlsWriteLabel(2,1,"Gas");
    xlsWriteLabel(2,2,"Cost Amount");
    xlsWriteLabel(2,3,"Retail");
    xlsWriteLabel(2,4,"Gross Profit");
    xlsWriteLabel(2,5,"new");

    $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['GAS']);
    xlsWriteNumber($xlsRow,2,$row['CostAmount']);
    xlsWriteNumber($xlsRow,3,$row['Retail']);
    xlsWriteNumber($xlsRow,4,$row['GrossProfit']);
    xlsWriteLabel($xlsRow,5,"<body>asdfasdf</body>");

    $xlsRow++;
    }
    xlsEOF();
    exit();
    ?>

 

 

Quick Reply Quick Reply

Click here to log in


What is the sum of 36 and 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How can I make condition for cell in excel sheet ?
    By Omid in forum Discuss Environment
    Replies: 0
    Last Post: 01-27-2011, 10:31 AM
  2. Replies: 0
    Last Post: 01-22-2011, 06:33 AM
  3. Replies: 0
    Last Post: 01-22-2011, 06:33 AM
  4. Insert images to headers of excel sheet using php?
    By gon_in_winds in forum Discuss PHP
    Replies: 0
    Last Post: 03-11-2010, 12:17 AM
  5. Insert images to headers of excel sheet using php?
    By gon_in_winds in forum Discuss PHP
    Replies: 0
    Last Post: 03-10-2010, 05:37 AM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •