31-01-2008, 13:11
|
|
|
|
חבר מתאריך: 02.10.05
הודעות: 2,355
|
|
לא פותר את הבעיה..
קוד PHP:
<?php $linkID=mysql_connect('--', '--', '--');
// Fixing UTF-8 Problem, and conneting to the ssten Database mysql_query("SET NAMES utf8"); mysql_select_db('teneView');
// Fixing UTF-8 Problem, and conneting to the ssten Database mysql_query("SET NAMES utf8"); mysql_select_db('teneView');
$result = mysql_query('select * from `pages`', $linkID); $count = mysql_num_fields($result);
$header = ''; for ($i = 0; $i < $count; $i++){ $header .= mysql_field_name($result, $i)."\t,"; }
$data = ''; while($row = mysql_fetch_row($result)){ $line = ''; foreach($row as $value){ if(!isset($value) || $value == ""){ $value = "\t"; }else{ # important to escape any quotes to preserve them in the data. $value = str_replace('"', '""', $value); # needed to encapsulate data in quotes because some data might be multi line. # the good news is that numbers remain numbers in Excel even though quoted. $value = '"' . $value . '"' . "\t,"; } $line .= $value; } $data .= trim($line)."\n"; } # this line is needed because returns embedded in the data have "\r" # and this looks like a "box character" in Excel $data = str_replace("\r", "", $data);
# Nice to let someone know that the search came up empty. # Otherwise only the column name headers will be output to Excel. if ($data == "") { $data = "\nno matching records found\n"; }
# Nice to let someone know that the search came up empty. # Otherwise only the column name headers will be output to Excel.
# This line will stream the file to the user rather than spray it across the screen //header("Content-type: application/octet-stream");
# replace excelfile.xls with whatever you want the filename to default to header('Pragma: public'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header ("Pragma: no-cache"); header("Expires: 0"); header('Content-Transfer-Encoding: none'); header("Content-Type: application/vnd.ms-excel"); // This should work for IE & Opera header("Content-Type: application/x-msexcel"); // This should work for the rest header('Content-Disposition: attachment; filename="'.basename("excelfile.xls").'"');
echo $header."\n".$data; ?>
ניסיתי גם להשאיר רק Content-Type אחד וזה לא עזר..
ניסיתי אפילו לכתוב את המידע הבינארי, וזה בכלל ייצא אסון..
הנה המחלקה שכתבתי:
קוד PHP:
<?php /*-----------------------------------------*\ | TeneView System, 2007 (C) | | Developed by Nadav Tenenbaum | | Version 1.0 Beta | | ------------------------------------------| | File: excel.class.php | | MVC: View | | Excel writer class | \*-----------------------------------------*/
class ExcelFile { var $pos; // Array: Holding row and col position var $fileDATA; // String: Holding the excel binary data var $started; // Bool: is the file stated? var $ended; // Bool: is the file ended?
function ExcelFile() { // Set initial position $this->pos = array('row'=>0, 'col'=>0); // Zero-set position $this->fileDATA = ''; // Make file data empty $this->started = false; // File is not yet started $this->ended = false; // file is not yet ended $this->BOF(); } function BOF() { // Void: Mark the .xls Begin Of File mark if(!$this->started) { $this->fileDATA = pack("vvvvvv", 0x809, 0x08, 0x00,0x10, 0x0, 0x0); $this->started = true; } } function EOF() { // Void: Mark the .xls End Of File mark if(!$this->ended) { $this->fileDATA .= pack("vv", 0x0A, 0x00); $this->ended = true; } } function textCell($value) { // Void: Creates a cell with string value $length = strlen($value); $this->fileDATA .= pack("v*", 0x0204, 8 + $length, $this->pos['row'], $this->pos['col'], 0x00, $length); $this->fileDATA .= $value; $this->nextCell(); } function intCell($value) { // Void: Creates a cell with integer value $value = (int) $value; $this->fileDATA .= pack("vvvvv", 0x0203, 14, $this->pos['row'], $this->pos['col'], 0x00); $this->fileDATA .= pack("d", $value); $this->nextCell(); } function nextCell() { // Void: Set the marker to next cell $this->pos['col']++; } function newRow() { // Void: Set the marker to the first cell in next row $this->pos['col'] = 0; $this->pos['row']++; } function setPos($row, $col) { // Void: Changes the class marker position $this->pos['col'] = (int) $col; $this->pos['row'] = (int) $row; }
function getBinary() { // String: return the binary data of the file to any use return $this->fileDATA; } } ?>
מישהו מוכן לנסות אותה על Office 2003? יכול להיות שהבעיה זה השימוש ב- Office 2007?
_____________________________________
|