
17-06-2007, 16:39
|
|
|
|
חבר מתאריך: 23.04.05
הודעות: 378
|
|
|
עזרה ביצירת קובץ EXCEL אקסל
1.
שלום,
יש לי מסד נתונים MYSQL
ואני רוצה לייצא טבלה ממנו (בעזרת PHP כמובן) לאקסל EXCEL,
שוטטתי ומצאתי את הסקריפט הזה:
קוד PHP:
<?php //Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell //pear excel package has support for fonts and formulas etc.. more complicated //this is good for quick table dumps (deliverables) include('DB_connection.php'); $result = mysql_query('select * from excel_test', $linkID); $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"); echo $header."\n".$data; ?>
(נלקח מתוך http://www.stargeek.com/scripts.php?script=2&cat=sql כל הזכויות שמורות)
הסקריפט מעולה, אך הוא עושה לי בעיה כי הקובץ אקסל שמתקבל מציג לי את הנתונים שבעברית בצורת ג'יבריש...
*המסד נתונים שלי הוא UTF-8
איך אני מתקן את זה? כלומר שהקובץ אקסל יציג את הנתונים בעברית ולא בג'יבריש..
תודה 
=============================
2.
אם למישהו יש סקריפט מוכן או משהו שאני יכול להיעזר בו(אני יודע PHP...) בכדי לבנות מערכת קטנה שממירה קובצי אקסל ל MYSQL אני אשמח
נערך לאחרונה ע"י Thetwo בתאריך 17-06-2007 בשעה 16:47.
|