使用PHPExcel读取excel文档并打印

来源:互联网 发布:写小说的网站 知乎 编辑:程序博客网 时间:2024/05/16 17:05

Excel文档内容:

1yangyu136123asdg@12.com2hercules12412412@12.com3northwood123124yan@bai.cn


<?phprequire_once './Classes/PHPExcel.php';require_once './Classes/PHPExcel/IOFactory.php';require_once './Classes/PHPExcel/Reader/Excel5.php';$objReader = PHPExcel_IOFactory::createReader('Excel2007');//use excel2007 for 2007 format $objPHPExcel = $objReader->load('./test.xlsx'); $sheet = $objPHPExcel->getSheet(0);$highestRow = $sheet->getHighestRow();        //取得总行数 $highestColumn = $sheet->getHighestColumn(); //取得总列数//$cellValue = $objPHPExcel->getActiveSheet()->getCell('B1')->getValue();for($j=1;$j<=$highestRow;$j++)                        //从第一行开始读取数据{ for($k='A';$k<=$highestColumn;$k++)            //从A列读取数据{ echo $objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue().'|';//读取单元格}echo '<br>';}$dataArray = $objPHPExcel->getActiveSheet()    ->rangeToArray(        'A1:D3',     // The worksheet range that we want to retrieve        NULL,        // Value that should be returned for empty cells        TRUE,        // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell)        TRUE,        // Should values be formatted (the equivalent of getFormattedValue() for each cell)        TRUE         // Should the array be indexed by cell row and cell column);echo '<pre>';print_r ($dataArray);echo '</pre>';exit;   //debug-------------------


0 0
原创粉丝点击