PHP Classes

date problem

Recommend this page to a friend!

      SimpleXLSX  >  All threads  >  date problem  >  (Un) Subscribe thread alerts  
Subject:date problem
Summary:date problem
Messages:15
Author:mehmet
Date:2011-01-11 16:07:59
Update:2014-06-20 09:42:53
 
  1 - 10   11 - 15  

  1. date problem   Reply   Report abuse  
Picture of mehmet 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

  2. Re: date problem   Reply   Report abuse  
Picture of Sergey Shuchkin 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);

  3. Re: date problem   Reply   Report abuse  
Picture of Sergey Shuchkin 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

  4. Re: date problem   Reply   Report abuse  
Picture of Sergey Shuchkin 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

  5. Re: date problem   Reply   Report abuse  
Picture of mehmet mehmet - 2011-02-02 11:37:30 - In reply to message 4 from Sergey Shuchkin
Tanks-Tanks-Tanks
Tank You

  6. Re: date problem   Reply   Report abuse  
Picture of hameed 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

  7. Re: date problem   Reply   Report abuse  
Picture of tinhyeuphonui tinhyeuphonui - 2012-12-01 21:30:12 - In reply to message 2 from Sergey Shuchkin
you can demo use date in function unixstamp, please

  8. Re: date problem   Reply   Report abuse  
Picture of Sergey Shuchkin 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/>';

  9. Re: date problem   Reply   Report abuse  
Picture of tinhyeuphonui tinhyeuphonui - 2012-12-02 10:41:56 - In reply to message 8 from Sergey Shuchkin
code of me.

<?php
/*
*Nguy&#7877;n Xuân Nam
*IPT-SPT
*/
include('SimpleXLSX.php');
// khai báo 1 m&#7843;ng l&#432;u giá tr&#7883; &#273;&#7885;c t&#7915; file .xlsx lên
$data = array();

// Hàm &#273;&#7885;c t&#7915;ng ḍng vào m&#7843;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&#7845;y t&#7915; m&#7843;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&#7885;n tên database có ch&#7913;a table chúng ta c&#7847;n import
$db_selected = mysql_select_db('student', $link);
mysql_query("SET NAMES 'utf8'");
if (!$db_selected) {
die ('Không th&#7875; s&#7917; d&#7909;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;
}

// &#272;&#7885;c và x&#7915; lư data t&#7915; file .xlsx upload lên &#273;&#432;a vào m&#7843;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&#7845;y t&#7915; row th&#7913; 2 b&#7903;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 &#273;&#7885;c xong n&#7897;i dung file .xlsx chúng ta g&#7885;i hàm import
$importstatus = import_db_table($data);
if($importstatus) {
echo "Import thành công b&#7841;n ki&#7875;m tra table s&#7869; có data nh&#432; bên d&#432;&#7899;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&#259;m h&#7885;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>

  10. Re: date problem   Reply   Report abuse  
Picture of beba 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!!

 
  1 - 10   11 - 15