
21-03-2008, 12:24
|
|
|
|
חבר מתאריך: 01.12.07
הודעות: 112
|
|
ציטוט:
|
במקור נכתב על ידי YuviAS
לא הבנתי מילה על זה, ובגלל זה ביקשתי מדריך...
מצאתי המון אבל יש בהם בעיות, אני רוצה שהכל יקרה אוטומטית.
בלי הגדרה של השדות, ובנוסף מתי שאני פותח שלא יהיה לי הודעת שגיאה "תוכן הקובץ אינו תומך את התבנית שלו, האם ברצונך לפתוח את הקובץ בכל זאת?"
אלו הבעיות..
כי ככה כבר הצלחתי לעשות את זה (ידנית, כי צריך להגדיר כל שורה, וכשעוברים שדה עושים \t וכשעוברים שורה עושים \N
ואני רוצה שהוא פשוט ישלוף את השדות, וייצא לEXCEL,
אשמח למדריך...
|
הצלחתי, אבל יש לי בעיה, הנה הקוד שלי:
קוד PHP:
<?php //pear excel package has support for fonts and formulas etc.. more complicated //this is good for quick table dumps (deliverables) $DB_Server = "localhost"; //your MySQL Server $DB_Username = "testDB"; //your MySQL User Name $DB_Password = "123456"; //your MySQL Password $DB_DBName = "testDB"; //your MySQL Database Name $DB_TBLName = "testTABLE"; //your MySQL Table Name $linkID = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno()); //select database $linkID = @mysql_select_db($DB_DBName, $linkID) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); //execute query $result = mysql_query('select * from users'); $count = mysql_num_fields($result); for ($i = 0; $i < $count; $i++){ $header .= mysql_field_name($result, $i)."\t"; } 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"; } # 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("Content-Disposition: attachment; filename=excelfile.xls"); // header("Pragma: no-cache"); // header("Expires: 0"); if (isset($w) && ($w==1)) { $file_type = "msword"; $file_ending = "doc"; }else { $file_type = "vnd.ms-excel"; $file_ending = "xls"; } //header info for browser: determines file type ('.doc' or '.xls') header("Content-Type: application/$file_type"); header("Content-Disposition: attachment; filename=database_dump.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); echo $header."\n".$data; ?>
</FONT>
הוא מציג לי את שורת הקובץ, הבעיה היא עכשיו, שהוא לא נותן את הקובץ להורדה, ואני השתמשתי בHEADERS על מנת לבצע זאת.
אשמח אם תעזרו לי,
יובל.
|