http://.co.il/dev/xls_creation/
הקוד..
PHP קוד:
<?php
$content = "";
if (isset($_POST['cn49c']))
{
function xlsBOF()
{
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0,0x0);
}
function xlsEOF()
{
echo pack("ss", 0x0A, 0x00);
}
function xlsWriteNumber($Row, $Col, $Value)
{
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
}
function xlsWriteLabel($Row, $Col, $Value)
{
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
}
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");;
if (preg_match("/^[0-9a-zA-Z]+$/", $_POST['x95nc']))
header("Content-Disposition: attachment;filename=" . $_POST['x95nc'] . ".xls ");
elsez
header("Content-Disposition: attachment;filename=nitsan_" . rand(0, 9999) . ".xls ");
header("Content-Transfer-Encoding: binary");
xlsBOF();
xlsWriteLabel(0,0,"List of values:");
$content = explode("\n", $_POST['cn49c']);
for ($i = 0; $i < count($content); $i++)
{
$content[$i] = explode(",", $content[$i]);
for ($j = 0; $j < count($content[$i]); $j++)
if (preg_match("/^([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/", $content[$i][$j]))
xlsWriteNumber(2 + $i, $j, $content[$i][$j]);
else
xlsWriteLabel(2 + $i, $j, $content[$i][$j]);
}
xlsEOF();
exit;
}
else
{
$content .= <<<EOF
Each new line is new row and ',' is the cols separator<br />
<form action="index.php" method="post">
Filename: <input type='text' value='' name='x95nc' />.xls<br />
<textarea name="cn49c" cols="60" rows="8"></textarea>
<div class='button'><input type="submit" value="xls it!" /></div>
</form>
EOF;
}