嗨,我正在导出我的mysql数据的excel格式目前我有14k+记录,但问题是它卡住了188kb,但当我试图削减结果到100记录,它不会中断下载。
这是我的代码:

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;
}

  mysql_connect($dbhost,$dbuser,$dbpass);
  //mysql_select_db($dbname) or die("Unable to select database");
  $result = mysql_db_query($dbname, "select id, or_number, name, client_code, address, vehicle_info, vehicle_color, plate_num, sticker_type, application_date, amount_paid, traffic_violations, delivery_date, edited_by, phase, version FROM owner order by application_date desc");




// Send Header
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=epal.xls"); // à¹à¸¥à¹‰à¸§à¸™à¸µà¹ˆà¸à¹‡à¸Šà¸·à¹ˆà¸­à¹„ฟล์
header("Content-Transfer-Encoding: binary ");

            xlsBOF();
            xlsWriteLabel(0,0,"Current SLVA Owner List:");
            xlsWriteLabel(2,0,"#");
            xlsWriteLabel(2,1,"OR #");
            xlsWriteLabel(2,2,"Name");
            xlsWriteLabel(2,3,"Client Code");
            xlsWriteLabel(2,4,"Address");
            xlsWriteLabel(2,5,"Vehicle Info");
            xlsWriteLabel(2,6,"Vehicle Color");
            xlsWriteLabel(2,7,"Plate #");
            xlsWriteLabel(2,8,"Sticker Type");
            xlsWriteLabel(2,9,"Application Date");
            xlsWriteLabel(2,10,"Amount Paid");
            xlsWriteLabel(2,11,"Traffic Violations");
            xlsWriteLabel(2,12,"Delivery Date");
            xlsWriteLabel(2,13,"Edited By");
            xlsWriteLabel(2,14,"Phase");
            xlsWriteLabel(2,15,"Version");


            $xlsRow = 3;
            while(list($id, $or_number, $name, $client_code, $address, $vehicle_info, $vehicle_color, $plate_num, $sticker_type, $application_date, $amount_paid, $traffic_violations, $delivery_date, $edited_by, $phase, $version) = mysql_fetch_row($result)) {
                      xlsWriteLabel($xlsRow,0, $id);
                      xlsWriteLabel($xlsRow,1,$or_number);
                      xlsWriteLabel($xlsRow,2,$name);
                      xlsWriteLabel($xlsRow,3,$client_code);
                      xlsWriteLabel($xlsRow,4,$address);
                      xlsWriteLabel($xlsRow,5,$vehicle_info);
                      xlsWriteLabel($xlsRow,6,$vehicle_color);
                      xlsWriteLabel($xlsRow,7,$plate_num);
                      xlsWriteLabel($xlsRow,8,$sticker_type);
                      xlsWriteLabel($xlsRow,9,$application_date);
                      xlsWriteLabel($xlsRow,10,$amount_paid);
                      xlsWriteLabel($xlsRow,11,$traffic_violations);
                      xlsWriteLabel($xlsRow,12,$delivery_date);
                      xlsWriteLabel($xlsRow,13,$edited_by);
                      xlsWriteLabel($xlsRow,14,$phase);
                      xlsWriteLabel($xlsRow,15,$version);

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

我去了几个站点/线程,但仍然没有找到解决方案。:'(

最佳答案

这只是一个猜测,但您可能需要提前计算文档大小并设置“内容长度”标题

header("Content-length: " . strlen($document));

必须将输出存储在字符串中,以便计算长度(输出缓冲可能有助于捕获xlsWriteLabel的使用)
ob_start();
xlsBOF();
xlsWriteLabel();
// etc etc
xlsEOF();
$document = ob_get_contents();
ob_end_clean();
header("Content-length: " . strlen($document));
echo $document;
exit();

关于php - Excel下载卡188kb,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10630789/

10-16 18:53