时间:2021-07-01 10:21:17 帮助过:4人阅读
读取中文的xls、csv文件会有问题,网上找了下资料,发现PHPExcel类库好用,官网地址:http://phpexcel.codeplex.com/
1、读取xls文件内容
代码如下 | |
//向xls文件写入内容 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
2、向xls文件写内容
代码如下 | |
//获取数据库数据(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...
http://www.bkjia.com/PHPjc/878340.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/878340.htmlTechArticlephp中使用PHPExcel操作excel(xls)文件, 读取中文的xls、csv文件会有问题,网上找了下资料,发现PHPExcel类库好用,官网地址:http://phpexcel.codep...