כן למה לא..
אתה צריך מערכת ליצירת קובץ אקסל ומערכת לשליפה ממנו
חכה שניה יעש לי פה משהו שהכנתי למישהו לפני כמה ימים שמייצא טבלאות במסד נתונים לאקסל:
export_mysql_table_to_xls.php:
PHP קוד:
<?php
// SETTINGS
$filename = "nitsan_" . rand(0, 9999) . ".xls";
$fields = array('CHARACTER_SET_NAME', 'DEFAULT_COLLATE_NAME', 'DESCRIPTION');
$tablename = 'CHARACTER_SETS';
$db = array('host' => 'localhost',
'user' => '',
'pass' => '',
'name' => 'information_schema');
// END OF SETTINGS! DO NOT EDIT BELOW THIS LINE!
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());
//mysql_query("SET NAMES 'utf8'") or die(mysql_error());
register_shutdown_function('mysql_close');
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");;
header("Content-Disposition: attachment;filename=".$filename);
header("Content-Transfer-Encoding: binary");
xlsBOF();
for($i=0; $i < sizeof($fields); $i++)
xlsWriteLabel(0,$i,$fields[$i]);
$query = "SELECT `".implode("`,`", $fields)."` FROM `".$tablename."`";
$query = mysql_query($query);
$j = 1;
while ($a = mysql_fetch_assoc($query))
{
for($i=0; $i < sizeof($fields); $i++)
if (preg_match("/^([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/", $a[$fields[$i]]))
xlsWriteNumber($j, $i, $a[$fields[$i]]);
else
xlsWriteLabel($j, $i, $a[$fields[$i]]);
$j++;
}
xlsEOF();
exit;
// eof
ויש לך את המחלקה הזו שקוראת קבצי XLS:
PHP קוד:
// אין לי פה מקום להביא את כל המחלקה, תחפש בגוגל:
/**
* A class for reading Microsoft Excel Spreadsheets.
*
* Originally developed by Vadim Tkachenko under the name PHPExcelReader.
* (http://sourceforge.net/projects/phpexcelreader)
* Based on the Java version by Andy Khan (http://www.andykhan.com). Now
* maintained by David Sanders. Reads only Biff 7 and Biff 8 formats.
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category Spreadsheet
* @package Spreadsheet_Excel_Reader
* @author Vadim Tkachenko <vt@apachephp.com>
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: reader.php 19 2007-03-13 12:42:41Z shangxiao $
* @link http://pear.php.net/package/Spreadsheet_Excel_Reader
* @see OLE, Spreadsheet_Excel_Writer
*/
השימוש איתה:
PHP קוד:
<?php
require_once 'class.Spreadsheet_Excel_Reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP1255');
echo $data->sheets[0]['cells'][0][0];
כאשר ה0 הראשון מייצג את מספר הSHEET, בדרך כלל יש רק אחד, הCELLS מסמל שבא לך לשלוף תאים, ה0 שאחריו מסמל את מספר הטור ואז ה0 הבא את מספר השורה
מספרי הטורים והשורות הם טבעיים גדולים ממינוס אחד
בהצלחה!