Je travaille sur la staff attendance
. L'user peut download une feuille de présence et mon système donnera à l'user la vue de la feuille d'aide à l'arrivée et ensuite il peut l'save dans la database. Les valeurs de la sauvegarde d'une feuille Excel sauvegardées avec succès dans la database.
Le problème est que l'user peut append un logging dans les colonnes de la feuille Excel dans n'importe quel format, mais lorsque j'arrive en PHP, le format de la date va mal.
par exemple, lorsque l'user ajoute la date de la présence dans la colonne, le format de la colonne est la date
et quand il peut save en dehors du time, il peut s'agir du format de numéro et lorsque l'user télécharge cette feuille Excel, l'aperçu de la date est passé dans l' unix time stamp
.
Voici des exemples d'images
- (SOLVED) Le nom de file C: \ xampp \ tmp \ php4632.tmp n'est pas lisible dans datatables de téléchargement excel avec codeigniter to mysql
- Upload Excel Codeigniter Erreur double key primaire
- Importer des données excel dans la database dans le code-identifiant
- Comment personnaliser datatables Excel avec deux feuilles en un excel avec php?
- Codeigniter data to csv character encoding issue with Arabic
Date en feuille Excel
Temps d'input et de sortie dans la feuille Excel
Lorsque l'user accède au site et téléchargez cette feuille Excel
Ensuite, une window contextuelle s'ouvrira
Ensuite, l'user parcourt la feuille Excel et puis je montre la vue feuille excel, que l'affichage est incorrect
Vous pouvez voir dans l'image ci-dessus que la date est convertie en horodatage Unix et l'heure entre et en dehors dans le numérique.
Je veux cette vue lorsqu'un user peut download une feuille Excel.
J'espère donc que vous comprenez mon problème et ce que je veux.
Voici mon code de feuille de chargement et de visualisation:
$excel_file = $_FILES['file']['name']; $target = SERVERPATH . 'assets/attendance_excel/'; $ext = pathinfo($excel_file, PATHINFO_EXTENSION); $filename = rand() . date("YmdHis"); move_uploaded_file($_FILES['file']['tmp_name'], $target . $filename . '.' . $ext); include(EXCEL_CLASS); $inputFileName = $target . $filename . '.' . $ext; // chmod($inputFileName,0777); try { $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } $objWorksheet = $objPHPExcel->getActiveSheet(); // $objWorksheet->getStyle('A1:E433')->getNumberFormat()->setFormatCode('Text'); $highestRow = $objWorksheet->getHighestRow(); // eg 10 $highestColumn = $objWorksheet->getHighestDataRow(); $highestColumn = $objWorksheet->getHighestColumn(); // eg 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromSsortingng($highestColumn); // eg 5 $td_data = ''; $row_no = 0; for ($row = 1; $row <= $highestRow; ++$row) { $check_empty_column = 0; for ($col = 0; $col <= $highestColumnIndex; ++$col) { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() == null) { $check_empty_column++; } } if ($check_empty_column < $highestColumnIndex) { for ($col = 0; $col < $highestColumnIndex; ++$col) { $td_data .= '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>'; } } $tr_data[$row_no] = $td_data; $td_data = ''; $row_no++; } $data_all = array( 'data' => $tr_data, 't_col' => $highestColumnIndex, 'name' => $filename . '.' . $ext ); echo json_encode($data_all);
.$excel_file = $_FILES['file']['name']; $target = SERVERPATH . 'assets/attendance_excel/'; $ext = pathinfo($excel_file, PATHINFO_EXTENSION); $filename = rand() . date("YmdHis"); move_uploaded_file($_FILES['file']['tmp_name'], $target . $filename . '.' . $ext); include(EXCEL_CLASS); $inputFileName = $target . $filename . '.' . $ext; // chmod($inputFileName,0777); try { $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } $objWorksheet = $objPHPExcel->getActiveSheet(); // $objWorksheet->getStyle('A1:E433')->getNumberFormat()->setFormatCode('Text'); $highestRow = $objWorksheet->getHighestRow(); // eg 10 $highestColumn = $objWorksheet->getHighestDataRow(); $highestColumn = $objWorksheet->getHighestColumn(); // eg 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromSsortingng($highestColumn); // eg 5 $td_data = ''; $row_no = 0; for ($row = 1; $row <= $highestRow; ++$row) { $check_empty_column = 0; for ($col = 0; $col <= $highestColumnIndex; ++$col) { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() == null) { $check_empty_column++; } } if ($check_empty_column < $highestColumnIndex) { for ($col = 0; $col < $highestColumnIndex; ++$col) { $td_data .= '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>'; } } $tr_data[$row_no] = $td_data; $td_data = ''; $row_no++; } $data_all = array( 'data' => $tr_data, 't_col' => $highestColumnIndex, 'name' => $filename . '.' . $ext ); echo json_encode($data_all);
.$excel_file = $_FILES['file']['name']; $target = SERVERPATH . 'assets/attendance_excel/'; $ext = pathinfo($excel_file, PATHINFO_EXTENSION); $filename = rand() . date("YmdHis"); move_uploaded_file($_FILES['file']['tmp_name'], $target . $filename . '.' . $ext); include(EXCEL_CLASS); $inputFileName = $target . $filename . '.' . $ext; // chmod($inputFileName,0777); try { $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } $objWorksheet = $objPHPExcel->getActiveSheet(); // $objWorksheet->getStyle('A1:E433')->getNumberFormat()->setFormatCode('Text'); $highestRow = $objWorksheet->getHighestRow(); // eg 10 $highestColumn = $objWorksheet->getHighestDataRow(); $highestColumn = $objWorksheet->getHighestColumn(); // eg 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromSsortingng($highestColumn); // eg 5 $td_data = ''; $row_no = 0; for ($row = 1; $row <= $highestRow; ++$row) { $check_empty_column = 0; for ($col = 0; $col <= $highestColumnIndex; ++$col) { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() == null) { $check_empty_column++; } } if ($check_empty_column < $highestColumnIndex) { for ($col = 0; $col < $highestColumnIndex; ++$col) { $td_data .= '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>'; } } $tr_data[$row_no] = $td_data; $td_data = ''; $row_no++; } $data_all = array( 'data' => $tr_data, 't_col' => $highestColumnIndex, 'name' => $filename . '.' . $ext ); echo json_encode($data_all);
);$excel_file = $_FILES['file']['name']; $target = SERVERPATH . 'assets/attendance_excel/'; $ext = pathinfo($excel_file, PATHINFO_EXTENSION); $filename = rand() . date("YmdHis"); move_uploaded_file($_FILES['file']['tmp_name'], $target . $filename . '.' . $ext); include(EXCEL_CLASS); $inputFileName = $target . $filename . '.' . $ext; // chmod($inputFileName,0777); try { $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); } catch (Exception $e) { die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); } $objWorksheet = $objPHPExcel->getActiveSheet(); // $objWorksheet->getStyle('A1:E433')->getNumberFormat()->setFormatCode('Text'); $highestRow = $objWorksheet->getHighestRow(); // eg 10 $highestColumn = $objWorksheet->getHighestDataRow(); $highestColumn = $objWorksheet->getHighestColumn(); // eg 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromSsortingng($highestColumn); // eg 5 $td_data = ''; $row_no = 0; for ($row = 1; $row <= $highestRow; ++$row) { $check_empty_column = 0; for ($col = 0; $col <= $highestColumnIndex; ++$col) { if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() == null) { $check_empty_column++; } } if ($check_empty_column < $highestColumnIndex) { for ($col = 0; $col < $highestColumnIndex; ++$col) { $td_data .= '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>'; } } $tr_data[$row_no] = $td_data; $td_data = ''; $row_no++; } $data_all = array( 'data' => $tr_data, 't_col' => $highestColumnIndex, 'name' => $filename . '.' . $ext ); echo json_encode($data_all);
J'ai également cherché beaucoup à ce sujet et j'ai trouvé quelque chose comme cela setFormatCode
, PHPExcel_Style_NumberFormat::FORMAT_GENERAL
etc, mais PHPExcel_Style_NumberFormat::FORMAT_GENERAL
ne fonctionne pas pour moi. Je fais de mon mieux.
Donc, donnez-moi une solution pour ce problème.
Remarque: Je ne peux pas restreindre un user qu'il convertit les colonnes et que l'ajout de données.
J'espère que vous comprenez ma question
MS Excel stocke les dates en tant que valeur flottante, un horodatage sérialisé, le nombre de jours entre le 1er janvier 1900 (ou le 1er janvier 1904 si le file utilise le calendar Mac), et c'est le masque de format numérique pour la cellule qui l'affiche une date formatée.
PHPExcel fournit une série de methods pour convertir entre cet horodatage sérialisé MS Exce et les horodatages Unix ou les objects PHP DateTime
$unixTimestamp = PHPExcel_Shared_Date::ExcelToPHP($excelTimestampValue);
convertir l'horodatage de MS Excel en un timestamp Unix
$phpDateTimeObject = PHPExcel_Shared_Date::ExcelToPHPObject($excelTimestampValue);
convertir l'horodatage MS Excel vers un object PHP DateTime
Et vous pouvez ensuite utiliser la fonction de date()
standard date()
PHP ou la méthode de format date()
l'object DateTime pour formater cette valeur comme vous le souhaitez.
$excelTimestamp = PHPExcel_Shared_Date::ExcelToPHPObject($phpDateTimeObject); $excelTimestamp = PHPExcel_Shared_Date::ExcelToPHPObject($unixTimestamp);
va convertir soit un timestamp Unix ou un object PHPP DateTime en une valeur d'horodatage sérialisée MS Excel
Si vous souhaitez modifier la manière dont un timestamp sérigraphié MS Excel est affiché dans une feuille de calcul, vous devez utiliser un masque de format Excel qui correspond également à un masque de date / heure …. PHPExcel_Style_NumberFormat :: FORMAT_GENERAL n'est pas un masque de format pour dates / heures