madddidley
09-26-2006, 08:08 PM
Hello,
I found this tutorial that takes whats in the database and puts it into an excel document. It exports the information to the file but for some reason the "postContent" gets messed up or something because the text becomes these little squares. I have no idea what would cause this, so I'm going to post the script. Maybe someone can see if I'm doing something wrong.
// Connect database.
// Functions for export to excel.
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;
}
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=blogFaceExport.xls ");
header("Content-Transfer-Encoding: binary ");
xlsBOF();
/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/
xlsWriteLabel(0,0,"Export Posts");
// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Post Title");
xlsWriteLabel(2,1,"Post Content");
xlsWriteLabel(2,2,"Post Date");
$xlsRow = 3;
// Get data records from table.
$result=mysql_query("select * from posts order by postId asc");
while($row=mysql_fetch_array($result)){
$month=substr($row[postDate], 4, 2);
$day=substr($row[postDate], 6, 2);
$year=substr($row[postDate], 0, 4);
$thedate="$month-$day-$year $row[postTime]";
$postTitle=stripslashes($row['postTitle']);
$postContent=strip_tags(stripslashes($row['postContent']));
xlsWriteLabel($xlsRow,0,$postTitle);
xlsWriteLabel($xlsRow,1,$postContent);
xlsWriteLabel($xlsRow,2,$thedate);
$xlsRow++;
}
xlsEOF();
exit();
mysql_close($db); //clean up
Again, if someone could help point me in the right direction. That would be sweet.
www.maddapps.com
I found this tutorial that takes whats in the database and puts it into an excel document. It exports the information to the file but for some reason the "postContent" gets messed up or something because the text becomes these little squares. I have no idea what would cause this, so I'm going to post the script. Maybe someone can see if I'm doing something wrong.
// Connect database.
// Functions for export to excel.
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;
}
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=blogFaceExport.xls ");
header("Content-Transfer-Encoding: binary ");
xlsBOF();
/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/
xlsWriteLabel(0,0,"Export Posts");
// Make column labels. (at line 3)
xlsWriteLabel(2,0,"Post Title");
xlsWriteLabel(2,1,"Post Content");
xlsWriteLabel(2,2,"Post Date");
$xlsRow = 3;
// Get data records from table.
$result=mysql_query("select * from posts order by postId asc");
while($row=mysql_fetch_array($result)){
$month=substr($row[postDate], 4, 2);
$day=substr($row[postDate], 6, 2);
$year=substr($row[postDate], 0, 4);
$thedate="$month-$day-$year $row[postTime]";
$postTitle=stripslashes($row['postTitle']);
$postContent=strip_tags(stripslashes($row['postContent']));
xlsWriteLabel($xlsRow,0,$postTitle);
xlsWriteLabel($xlsRow,1,$postContent);
xlsWriteLabel($xlsRow,2,$thedate);
$xlsRow++;
}
xlsEOF();
exit();
mysql_close($db); //clean up
Again, if someone could help point me in the right direction. That would be sweet.
www.maddapps.com