Jump to content
Fórum Script Brasil
  • 0

Php + Excel + Mysql


FlavioSV
 Share

Question

2 answers to this question

Recommended Posts

  • 0

tem como sim, dá uma olhadinha no código abaixo, e testa(ainda não testei), mas acredito que tá tudo funcionando..... um abraço

class Export {

function spreadsheet ( $server , $database , $user , $password , $query , $filename) {

$connection = mysql_pconnect( $server , $user , $password ) or trigger_error(mysql_error(), E_USER_ERROR);

mysql_select_db ( $database );

$recordset = mysql_query ( $query , $connection ) or die ( mysql_error ( ) );

$columns = mysql_num_fields ( $recordset );

$rows = mysql_num_rows ( $recordset );

$row_recordset = mysql_fetch_array ( $recordset , MYSQL_NUM );

header('Content-type: application/x-msdownload');

header('Content-Disposition: attachment; filename='.$filename.'.xls');

header('Pragma: no-cache');

header('Expires: 0');

for ( $i=0 ; $i < $columns ; $i++ ) {

$spreadsheet .= strtoupper ( mysql_field_name ( $recordset , $i ) ) . "\t";

}

$spreadsheet .= "\n";

for ( $i=0 ; $i < $rows ; $i++ ) {

$spreadsheet .= "\n";

for ( $n=0 ; $n < $columns ; $n++ ) {

$spreadsheet .= $row_recordset[$n]."\t";

}

$row_recordset = mysql_fetch_array ( $recordset , MYSQL_NUM );

}

print "$header\n$spreadsheet";

}

}

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.1k
    • Total Posts
      647.1k
×
×
  • Create New...