很早的时候,用php生成execl都是件麻烦的事,我一般都会用csv来替代,现在这类工具就很多了,并且比较成熟了。不光有excel的,word,pdf。
1,php excelreader操作excel的php类,生成,读取excel等。功能很强大。
下载地址:http://sourceforge.net/projects/phpexcelreader/
解压后,里面有很多例子,调用方法简单。
例1
代码如下 | 复制代码 | ||||||||
/** * * @copyright 2007-2012 Xiaoqiang. * @author Xiaoqiang.Wu * @version 1.01 */ error_reporting(E_ALL); date_default_timezone_set('Asia/ShangHai'); /** PHPExcel_IOFactory */ require_once '../Classes/PHPExcel/IOFactory.php'; // Check prerequisites if (!file_exists("31excel5.xls")) { exit("not found 31excel5.xls.n"); } $reader = PHPExcel_IOFactory::createReader('Excel5'); //设置以Excel5格式(Excel97-2003工作簿) $PHPExcel = $reader->load("31excel5.xls"); // 载入excel文件 $sheet = $PHPExcel->getSheet(0); // 读取第一??工作表 $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumm = $sheet->getHighestColumn(); // 取得总列数 $highestColumm= PHPExcel_Cell::columnIndexFromString($colsNum); //字母列转换为数字列 如:AA变为27 /** 循环读取每个单元格的数据 */ for ($row = 1; $row <= $highestRow; $row ){//行数是以第1行开始 for ($column = 0; $column < $highestColumm; $column ) {//列数是以第0列开始 $columnName = PHPExcel_Cell::stringFromColumnIndex($column); echo $columnName.$row.":".$sheet->getCellByColumnAndRow($column, $row)->getValue()." } } ?> 例2
|