无法使用 PHPExcel 加载文件
Can not load file using PHPExcel
我目前正在使用 PHPExcel 库读取我的 excel 文件,该文件将由用户上传。但是我无法加载上传的文件。
我正在使用这段代码,目前我无法获得正确的文件路径,如果有人可以告诉我,在加载部分写什么 => $objPHPExcel = PHPExcel_IOFactory::load();
上传的文件正在传输到名为 "upload" 的文件夹中。
<?php
$storagename = $_FILES["file"]["name"];
$new_file_name=$storagename.'.xlsx';
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $new_file_name);
include ("PHPExcel/IOFactory.php");
$html="<table border='1'>";
$objPHPExcel = PHPExcel_IOFactory::load('"../upload/" . $new_file_name');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row=2; $row<=$highestRow; $row++)
{
$html.="<tr>";
$site_name = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
$solution_type = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
$html.= '<td>'.$site_name.'</td>';
$html .= '<td>'.$solution_type.'</td>';
$html .= "</tr>";
}
}
$html .= '</table>';
echo $html;
?>
正在使用 PHPExcel 加载文件。
<?php
$storagename = $_FILES["file"]["name"];
$new_file_name=$storagename.'.xlsx';
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" .$new_file_name);
$upload_file = "../upload/" . $new_file_name;
include ("PHPExcel/IOFactory.php");
$html="<table border='1'>";
$objPHPExcel = PHPExcel_IOFactory::load($upload_file);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row=2; $row<=$highestRow; $row++)
{
$html.="<tr>";
$site_name = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
$solution_type = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
$html.= '<td>'.$site_name.'</td>';
$html .= '<td>'.$solution_type.'</td>';
$html .= "</tr>";
}
}
$html .= '</table>';
echo $html;
?>
我目前正在使用 PHPExcel 库读取我的 excel 文件,该文件将由用户上传。但是我无法加载上传的文件。
我正在使用这段代码,目前我无法获得正确的文件路径,如果有人可以告诉我,在加载部分写什么 => $objPHPExcel = PHPExcel_IOFactory::load();
上传的文件正在传输到名为 "upload" 的文件夹中。
<?php
$storagename = $_FILES["file"]["name"];
$new_file_name=$storagename.'.xlsx';
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $new_file_name);
include ("PHPExcel/IOFactory.php");
$html="<table border='1'>";
$objPHPExcel = PHPExcel_IOFactory::load('"../upload/" . $new_file_name');
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row=2; $row<=$highestRow; $row++)
{
$html.="<tr>";
$site_name = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
$solution_type = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
$html.= '<td>'.$site_name.'</td>';
$html .= '<td>'.$solution_type.'</td>';
$html .= "</tr>";
}
}
$html .= '</table>';
echo $html;
?>
正在使用 PHPExcel 加载文件。
<?php
$storagename = $_FILES["file"]["name"];
$new_file_name=$storagename.'.xlsx';
move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" .$new_file_name);
$upload_file = "../upload/" . $new_file_name;
include ("PHPExcel/IOFactory.php");
$html="<table border='1'>";
$objPHPExcel = PHPExcel_IOFactory::load($upload_file);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row=2; $row<=$highestRow; $row++)
{
$html.="<tr>";
$site_name = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(0, $row)->getValue());
$solution_type = mysqli_real_escape_string($conn, $worksheet->getCellByColumnAndRow(1, $row)->getValue());
$html.= '<td>'.$site_name.'</td>';
$html .= '<td>'.$solution_type.'</td>';
$html .= "</tr>";
}
}
$html .= '</table>';
echo $html;
?>