PHPExcel is a plug-in for php. It can read excel files, which are xls files. Let’s take a look. An example of PHPExcel operating excel (xls) file, I hope it can help you.
There will be problems in reading Chinese xls and csv files. I searched for information online and found that the PHPExcel class library is easy to use. 1. Read the content of xls files
The code is as follows | |
//Write content to xls file $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
2. Write content to xls file
代码如下 | |
//获取数据库数据(mysqli预处理学习) $config = array( 'DB_TYPE'=>'mysql', 'DB_HOST'=>'localhost', 'DB_NAME'=>'test', 'DB_USER'=>'root', 'DB_PWD'=>'root', 'DB_PORT'=>'3306', ); function getProductIdByName($name) { global $config; $id = false; $mysqli = new mysqli($config['DB_HOST'], $config['DB_USER'], $config['DB_PWD'], $config['DB_NAME']); if(mysqli_connect_error()) { //兼容 < php5.2.9 OO way:$mysqli->connect_error die("连接失败,错误码:".mysqli_connect_errno()."错误信息:".mysqli_connect_error()); } //设置连接数据库的编码,不要忘了设置 $mysqli->set_charset("gbk"); //中文字符的编码要与数据库一致,若没设置,结果为null $name = iconv("utf-8", "gbk//IGNORE", $name); if($mysqli_stmt = $mysqli->prepare("select id from 137_product where name like ?")) { $mysqli_stmt->bind_param("s", $name); $mysqli_stmt->execute(); $mysqli_stmt->bind_result($id); $mysqli_stmt->fetch(); $mysqli_stmt->close(); } $mysqli->close(); return $id; //得到的是gbk码(同数据库编码) } $id = getProductIdByName('%伊奈卫浴伊奈分体座便器%'); var_dump($id); ?> |
OK...