Jump to content

Help - Export recordset to MS Excel from PHP/MSSQL


garian_of_brunlea

Recommended Posts

Hiya

 

This is the code I use for PHP/MySQL on another site and it works great, but this new site I am working on is PHP/MSSQL and I cannot get the export to Excel to work.

 

MySQL Method (how can I change this to work with MSSQL)

while($row = mysql_fetch_row($glRes)){
  $line = '';
  foreach($row as $value){
    if(!isset($value) || $value == ""){
      $value = "\t";
    }else{
      $value = str_replace('"', '""', $value);
      $value = '"' . $value . '"' . "\t";
    }
    $line .= $value;
  }
  $data .= trim($line)."\n";
}
  $data = str_replace("\r", "", $data);
if ($data == "") {
  $data = "\no matching records found\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=report.xls");
header("Pragma: no-cache");
header("Expires: 0");

echo $header."\n".$data;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.