Skip to content

Instantly share code, notes, and snippets.

@jbrooksuk
Created October 4, 2013 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrooksuk/6824507 to your computer and use it in GitHub Desktop.
Save jbrooksuk/6824507 to your computer and use it in GitHub Desktop.
<?php
class XLS {
public function __construct($strFileName) {
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=$strFileName.xls");
header("Content-Transfer-Encoding: binary");
$this->xlsBOF();
}
public function __destruct() {
$this->xlsEOF();
}
public function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
}
public function xlsWriteLabel($Row, $Col, $Value) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
}
public function xlsWriteRow($Row, $Values) {
$Col = 0;
foreach($Values as $Value) {
$this->xlsWriteLabel($Row, $Col, utf8_decode($Value));
$Col++;
}
}
// PRIVATE INTERNAL FUNCTIONS
private function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
}
private function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment