我正在阅读一个xlsx文件并且字段在DateStamd中我想将它们转换为日期数据我在这里留下我的进展
Excel A1 = 43160 转换日期= 01/03/2018
enter code here
需要'../PHPExcel-1.8/Classes/PHPExcel/IOFactory.php';
要求'../ cnx / conection.php';
$objPHPExcel = PHPExcel_IOFactory::load('../../date.xlsx');
$objPHPExcel->setActiveSheetIndex(0);
$numRows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
for ($i = 2; $i <= $numRows; $i++) {
$pm = $objPHPExcel->getActiveSheet()->getCell('A'.$i)->getValue();
echo $pm;
$sql = "INSERT INTO regfecha (reg_fecha) VALUES('$pm')";
$result = $mysqli->query($sql);
}
` 这里我有另一个例子,我不知道如何应用它
`
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
include 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$worksheet = $objPHPExcel->getActiveSheet();
// Add some data
$testDates = array( '26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
'2012-Oct-31', '5th November', 'January 1st', 'April 2012',
'17-03', '03-2012', '29 Feb 2011', '03-05-07',
'03-MAY-07', '03-13-07',
);
$testDateCount = count($testDates);
for($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('A'.$row, $testDates[$row-1]);
$worksheet->setCellValue('B'.$row, '=DATEVALUE(A'.$row.')');
$worksheet->setCellValue('C'.$row, '=B'.$row);
}
$worksheet->getStyle('C1:C'.$testDateCount)
->getNumberFormat()
->setFormatCode('yyyy-mmm-dd');
echo '<hr />';
// Test the formulae
?>
<p><strong>Warning: </strong>The PHPExcel DATEVALUE() function accepts a wider range of date formats than MS Excel's DATEFORMAT() function.</p>
<table border="1" cellspacing="0">
<tr>
<th>Date String</th>
<th>Formula</th>
<th>Excel DateStamp</th>
<th>Formatted DateStamp</th>
</tr>
<?php
for ($row = 1; $row <= $testDateCount; ++$row) {
echo '<tr>';
echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
echo '<td>' , $worksheet->getCell('B'.$row)->getValue() , '</td>';
echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
echo '</tr>';
}
?>