因此,我得以在外壳表上显示其数据,但这种数据可插入我的表格。 我看不出这个部分,这里是我迄今所看到的:
$path = $_GET[ file ];
include("../class/sql.php");
require ../class/PHPExcel.php ;
require_once ../class/PHPExcel/IOFactory.php ;
$objPHPExcel = PHPExcel_IOFactory::load($path);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g F
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
echo <br>Data: <table width="100%" cellpadding="3" cellspacing="0"><tr> ;
for ($row = 1; $row <= $highestRow; ++ $row) {
echo <tr> ;
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
if($row === 1)
echo <td style="background:#000; color:#fff;"> . $val . </td> ;
else
echo <td> . $val . </td> ;
}
echo </tr> ;
}
echo </table> ;
}
b 以前的PHPExcel是一件很麻烦的事,我没有时间通过它来读,以充分理解: 我不得不在午宴上这样做。 预 收
Edit:这是它应该做的思想,价值观部分是我所不知的。
$sql = "insert into tablename (col1, col2, col3) values(...)";
//start at row 2 so headers are not inserted
for ($row = 2; $row <= $highestRow; ++ $row) {
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
//here s my prob..
echo $val;
}
$result = mysql_query($sql);
}