phpexcle的导入功能

以下代码为读取excle文件的信息,并将内容读出以供处理的例子


<?php
error_reporting(E_ALL);
set_time_limit(0);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>读取excle测试</title>
</head>
<body>
<h1>读取excle的内容测试</h1>
<?php
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/');
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
$inputFileType = 'Excel5';
$inputFileName = 'test.xls';

/** Create a new Reader of the type defined in $inputFileType **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($inputFileName);
/** Read the document's creator property **/
$creator = $objPHPExcel->getProperties()->getCreator();
echo '<b>文档创建者: </b>',$creator,'<br />';
/** Read the Date when the workbook was created (as a PHP timestamp value) **/
$creationDatestamp = $objPHPExcel->getProperties()->getCreated();
/** Format the date and time using the standard PHP date() function **/
$creationDate = date('l, d<\s\up>S</\s\up> F Y',$creationDatestamp);
$creationTime = date('g:i A',$creationDatestamp);
echo '<b>创建时间: </b>',$creationDate,' at ',$creationTime,'<br />';
/** Read the name of the last person to modify this workbook **/
$modifiedBy = $objPHPExcel->getProperties()->getLastModifiedBy();
echo '<b>最后修改者: </b>',$modifiedBy,'<br />';
/** Read the Date when the workbook was last modified (as a PHP timestamp value) **/
$modifiedDatestamp = $objPHPExcel->getProperties()->getModified();
/** Format the date and time using the standard PHP date() function **/
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y',$modifiedDatestamp);
$modifiedTime = date('g:i A',$modifiedDatestamp);
echo '<b>最后修改时间: </b>',$modifiedDate,' at ',$modifiedTime,'<br />';
/** Read the workbook title property **/
$workbookTitle = $objPHPExcel->getProperties()->getTitle();
echo '<b>标题: </b>',$workbookTitle,'<br />';
/** Read the workbook description property **/
$description = $objPHPExcel->getProperties()->getDescription();
echo '<b>描述: </b>',$description,'<br />';
/** Read the workbook subject property **/
$subject = $objPHPExcel->getProperties()->getSubject();
echo '<b>主题: </b>',$subject,'<br />';
/** Read the workbook keywords property **/
$keywords = $objPHPExcel->getProperties()->getKeywords();
echo '<b>关键字: </b>',$keywords,'<br />';
/** Read the workbook category property **/
$category = $objPHPExcel->getProperties()->getCategory();
echo '<b>类别: </b>',$category,'<br />';
/** Read the workbook company property **/
$company = $objPHPExcel->getProperties()->getCompany();
echo '<b>公司: </b>',$company,'<br />';
/** Read the workbook manager property **/
$manager = $objPHPExcel->getProperties()->getManager();
echo '<b>管理者: </b>',$manager,'<br />';
echo '<hr />';
echo '文件内工作表的数量:';
/** Use the PHPExcel object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
$sheetCount = $objPHPExcel->getSheetCount();
echo $sheetCount.'<br />';
echo '工作表的内容:<br />';
/** Use the PHPExcel object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
$sheetNames = $objPHPExcel->getSheetNames();
foreach($sheetNames as $sheetIndex => $sheetName) {
echo $sheetIndex,'#工作表的名称为 "',$sheetName,'"<br />';
$objPHPExcel->setActiveSheetIndex($sheetIndex);//设置活动表格
//$sheet = $objPHPExcel->getSheet($sheetIndex);
$sheet = $objPHPExcel->getActiveSheet();
$highestRow = $sheet->getHighestRow(); //取得总行数
$highestColumn = $sheet->getHighestColumn(); //取得总列数
echo '该工作表共有',$highestRow.'行,最大的列号是'.$highestColumn.'</br>';
echo '<table border="1" cellspacing="0">';
for($Row=2;$Row<=$highestRow;$Row++) //从第二行开始读取数据
{
echo '<tr>';
for($Col='A';$Col<=$highestColumn;$Col++) //从A列读取数据
{
//读取单元格
//echo '<th>'.$objPHPExcel->getSheet($sheetIndex)->getCell("$Col$Row")->getValue()."</th>";
echo '<th>'.$objPHPExcel->getActiveSheet()->getCell("$Col$Row")->getValue()."</th>";
}
echo '</tr>';
}
echo '</table></br>';
}
?>
<body>
</html>

此条目发表在待分类分类目录。将固定链接加入收藏夹。