我已经有了这个可以从excel读取数据的代码,但问题是使用PHPMyAdmin将数据保存到数据库中,我可以将数据保存到数据库但问题是,我只能保存第一行不是来自excel的全部数据。
<?php
include ('connection.php');
include('Classes/PHPExcel.php');
$tmpfname = "uploads/test2.xlsx";
$excelReader = PHPExcel_IOFactory::createReaderForFile($tmpfname);
$excelObj = $excelReader->load($tmpfname);
$worksheet = $excelObj->getActiveSheet();
$lastRow = $worksheet->getHighestRow();
//$lastCol = $worksheet->getHighestCol();
$aaa = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
echo "<table border='ridge' id='results'>";
for($row = 1; $row <= $lastRow; $row++){
echo '<tr>';
for($i=0; $i < 26; $i++)
{
$value = $worksheet->getCell($aaa[$i].$row)->getFormattedValue();
$color = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFill()->getStartColor()->getRGB();
$border = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getBorders()->getTop()->getBorderStyle();
$fontstyle1 = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFont()->getBold();
$fontstyle2 = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFont()->getItalic();
$fontstyle3 = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFont()->getUnderline();
$fontsize = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFont()->getSize();
$fontname = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFont()->getName();
$alignment = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getAlignment()->getHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$fontcolor = $worksheet->getCell($aaa[$i].$row)->getStyle($aaa[$i].$row)->getFont()->getColor()->getRGB();
$fontcolorall = $fontstyle1.$fontstyle2.$fontstyle3;
$hello = mysqli_query($conn, "insert into tags_xml(value, color, border, fontstyle, fontsize, fontname, alignment, fontcolor)
values('$value','$color','$border','$fontcolorall','$fontsize','$fontname','$alignment','$fontcolor');");
echo '<td><span id="value">'. $value.' </span>|
<span id="color">'.$color.'</span> |
<span id="border">'.$border.' </span> |
<span id="fontstyle">'.$fontstyle1.'
'.$fontstyle2.'
'.$fontstyle3.'</span> |
<span id="fontsize">'.$fontsize.' </span> |
<span id="fontname">'.$fontname.' </span> |
<span id="alignment">'.$alignment.' </span> |
<span id="fontcolor">'.$fontcolor.'</span> |
</td>';
}
echo '</tr>';
}
echo "</table>";
/* $background_color = $cell->getStyle()->getFill()->getStartColor()->getRGB();
$fore_color = $cell->getStyle()->getFont()->getColor()->getRGB();
$font_bold = $cell->getStyle()->getFont()->getBold();
$font_italic = $cell->getStyle()->getFont()->getItalic();
$bordo = $cell->getStyle()->getBorders()->getTop()->getBorderStyle(); */
echo "</table>";
?>