到https://github.com/PHPOffice/PHPExcel下载PHPExcel
date_default_timezone_set(‘UTC’);
require_once ‘PHPExcel-1.8/Classes/PHPExcel.php’;
require_once ‘PHPExcel-1.8/Classes/PHPExcel/IOFactory.php’;
//打开
$objPHPExcel = PHPExcel_IOFactory::load(“test1.xlsx”);
// 确定要读取的sheet
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
//$highestColumn = $sheet->getHighestColumn();
// 读写数据数据
for ($row = 2; $row <= $highestRow; $row++){
echo $sheet->getCell(‘B’.$row)->getValue();
echo $sheet->getCell(‘C’.$row)->getValue();
$sheet->setCellValue(‘B’.$row, “hello”);
$sheet->setCellValue(‘C’.$row, “world”);
}
//保存
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007’);
$objWriter->save(“test1.xlsx”);