Categories
Web site

Easy way to create XLS file from PHP

Everybody knows phpMyAdmin can export file to Excel format but phpMyAdmin just export .csv file,not real Excel file format. If you are interest in PHP programming and need to export to the real Excel format please check it out !

Example PHP export to XLS file format.

1. Create Function for XLS

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