|
 mehmet - 2011-01-11 16:08:09
Very nice work.
But i have an issue with xlsx date cells.
xlsx cell data = 25/5/2010 wiew 40323
 Sergey Shuchkin - 2011-01-29 10:30:19 - In reply to message 1 from mehmet
$ts = ($r[0] - 25569)*86400;
echo date('Y-m-d', $ts);
 Sergey Shuchkin - 2011-01-29 14:32:57 - In reply to message 1 from mehmet
excel time to string
//$r[1] = 0.767361111111
$h = floor($r[1] * 24);
$m = (($r[1] * 24) - $h) * 60;
if (!$m) $m = '00';
$time = $h.':'.$m; // 18:25
 Sergey Shuchkin - 2011-01-31 11:30:06 - In reply to message 1 from mehmet
plz download 0.4 version where $xlsx->unixstamp( $excelDateTime ) added
 mehmet - 2011-02-02 11:37:30 - In reply to message 4 from Sergey Shuchkin
Tanks-Tanks-Tanks
Tank You
 hameed - 2012-10-05 06:06:54 - In reply to message 3 from Sergey Shuchkin
thanks Dude... Its really works .. thanks again for saving my time
 tinhyeuphonui - 2012-12-01 21:30:12 - In reply to message 2 from Sergey Shuchkin
you can demo use date in function unixstamp, please
 Sergey Shuchkin - 2012-12-02 07:12:34 - In reply to message 7 from tinhyeuphonui
foreach( $xlsx->rows() as $r)
echo date('Y-M-D', $xlsx->unixstamp( $r[2] ) ).'<br/>';
 tinhyeuphonui - 2012-12-02 10:41:56 - In reply to message 8 from Sergey Shuchkin
code of me.
<?php
/*
*Nguyễn Xuân Nam
*IPT-SPT
*/
include('SimpleXLSX.php');
// khai báo 1 mảng lưu giá trị đọc từ file .xlsx lên
$data = array();
// Hàm đọc từng ḍng vào mảng
function add_hocvien( $fullname, $email, $diem, $namhoc ){
global $data;
if( !empty($fullname) && !is_null($fullname) ){
$data []= array('fullname' => $fullname, 'email' => $email, 'diem' =>$diem, 'NamHoc' => $namhoc);
}else
if(empty($fullname) && !is_null($fullname)){
$data []=array('fullname'=>$fullname, 'email' => $email, 'diem' =>$diem, 'NamHoc' => $namhoc);
}
}
// Import data lấy từ mảng vào database table
function import_db_table($data){
if( empty($data) || is_null($data) ) return false;
// connect MySQL
$link = mysql_connect('localhost', 'root', 'root');
if (!$link) {
die('Khong the ket noi toi MySQL: ' . mysql_error());
}
// Chọn tên database có chứa table chúng ta cần import
$db_selected = mysql_select_db('student', $link);
mysql_query("SET NAMES 'utf8'");
if (!$db_selected) {
die ('Không thể sử dụng database này : ' . mysql_error());
}
$sql = "INSERT INTO tblhocvien(fullname, email,diem, NamHoc) VALUES";
foreach($data as $row){
$sql .= "('". addslashes($row['fullname'])."','".addslashes($row['email'])."','". addslashes($row['diem'])."','". addslashes($row['NamHoc'])."'),";
}
$sql = substr($sql, 0, -1);
$status = mysql_query($sql);
mysql_close($link);
if($status) return true;
return false;
}
// Đọc và xừ lư data từ file .xlsx upload lên đưa vào mảng
if ( $_FILES['file']['tmp_name'] ){
$xlsx = new SimpleXLSX($_FILES['file']['tmp_name']);
list($num_cols, $num_rows) = $xlsx->dimension();
//echo "<pre>"; print_r($xlsx->rows());
//exit;
// Lấy từ row thứ 2 bởi row 1 là title
$i = 0;
foreach( $xlsx->rows() as $row ) {
if($i>0) add_hocvien( $row[0], $row[1],$row[2], $row[3]);
$i++;
}
// Sau khi đọc xong nội dung file .xlsx chúng ta gọi hàm import
$importstatus = import_db_table($data);
if($importstatus) {
echo "Import thành công bạn kiểm tra table sẽ có data như bên dưới !";
}else{
echo "Import không thành công !";
}
}
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Import Excel file .xlsx vào MySQL table</title>
<body>
<table border="1">
<tr>
<th align="left">fullname</th>
<th align="left">email</th>
<th align="left">diem</th>
<th align="left">năm học</th>
</tr>
<?php foreach( $data as $row ) { ?>
<tr>
<td><?php echo( $row['fullname'] ); ?></td>
<td><?php echo( $row['email'] ); ?></td>
<td><?php echo( $row['diem'] ); ?></td>
<td><?php echo( $row['NamHoc'] ); ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
 beba - 2012-12-07 19:57:14 - In reply to message 8 from Sergey Shuchkin
Hi, Sergey..
Sorry for my English, i'm from Belarus..
Have a one problem with your class with date. I'm modify function for convert Excel date to timestamp from PHPExcel project. But, how I can init column type "datetime" ?
Download v 0.6.2. In changelog you write, that, quote "rowsEx() returns type and formulas now". But when I make $obj->rowsEx($_sheet_value) I get only srting type with value "s". Datetime type not init your class after parse. :(
P.s. Thanks for script, .. When load 35 000 rows and 5 cols your class parse file at 10 sec, but phpExcel parse 1 minute!!! and usage 512 Mb memory!!
|