世界,您好!

欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!

PHPExcel读取excel文件示例

PHPExcel是一个非常方便生成Excel格式文件的类,官方下载包中带有大量如何生成各种样式excel文件的示例,但没有一个读取Excel文件的完整例子.Xiaoqiang根据网上的资料,整理了一份简单读取Excel文件的例子.
传统方法:

/**
 *
 * @copyright 2007-2012 Xiaoqiang.
 * @authorXiaoqiang.Wu <jamblues@gmail.com>
 * @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()."<br />";
    }
}
 


精简方法:

/**
 *
 * @copyright 2007-2012 Xiaoqiang.
 * @author Xiaoqiang.Wu <jamblues@gmail.com>
 * @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(); // 取得总列数
 
/** 循环读取每个单元格的数据 */
for ($row = 1; $row <= $highestRow; $row++){//行数是以第1行开始
    for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始
        $dataset[] = $sheet->getCell($column.$row)->getValue();
        echo $column.$row.":".$sheet->getCell($column.$row)->getValue()."<br />";
    }
}

这边文章是转过来的 原文地址http://www.imhdr.com/1332/
字母列转换为数字列这个方法就是我当时遇到的问题。

磁盘inode使用达到100% ,/var/spool/postfix/maildrop/ 目录有大量小文件

最近使用腾讯云服务器,排查问题时遇到一个磁盘告警,硬盘分区/ 只读, 出错信息:No space left on device,上服务器看了一下

df-h

df-li

inode满了, 使用 find . ! -type l 查找这个目录下小文件占满导致

 /var/spool/postfix/maildrop/
清理掉就行了。
原因是什么的呢?网上找了一下 http://blog.chinaunix.net/uid-26364035-id-3163574.html。照着这个方法修改一下计划任务就可以了。

Discuz! X论坛上传附件到100%自动取消上传的原因及解决方案

最近接到一些站长的反馈,说论坛上传附件,到100%的时候自己取消上传了。经查是附件索引表pre_forum_attachment表的aid字段自增值出现了问题,导致程序逻辑返回的aid值实际为一个MySQL 1062 报错:
来自网页的消息
—————————
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”><html><head> <title>10.144.49.99 – Database Error</title> <meta http-equiv=”Content-Type” content=”text/html; charset=gbk” /> <meta name=”ROBOTS” content=”NOINDEX,NOFOLLOW,NOARCHIVE” /> <style type=”text/css”> <!– body { background-color: white; color: black; font: 9pt/11pt verdana, arial, sans-serif;} #container { width: 1024px; } #message { width: 1024px; color: black; } .red {color: red;} a:link { font: 9pt/11pt verdana, arial, sans-serif; color: red; } a:visited { font: 9pt/11pt verdana, arial, sans-serif; color: #4e4e4e; } h1 { color: #FF0000; font: 18pt “Verdana”; margin-bottom: 0.5em;} .bg1{ background-color: #FFFFCC;} .bg2{ background-color: #EEEEEE;} .table {background: #AAAAAA; font: 11pt Menlo,Consolas,”Lucida Console”} .info { background: none repeat scroll 0 0 #F3F3F3; border: 0px solid #aaaaaa; border-radius: 10px 10px 10px 10px; color: #000000; font-size: 11pt; line-height: 160%; margin-bottom: 1em; padding: 1em; } .help { background: #F3F3F3; border-radius: 10px 10px 10px 10px; font: 12px verdana, arial, sans-serif; text-align: center; line-height: 160%; padding: 1em; } .sql { background: none repeat scroll 0 0 #FFFFCC; border: 1px solid #aaaaaa; color: #000000; font: arial, sans-serif; font-size: 9pt; line-height: 160%; margin-top: 1em; padding: 4px; } –> </style></head><body><div id=”container”><h1>Discuz! Database Error</h1><div class=’info’>(1062) Duplicate entry ‘107697’ for key 1<div class=”sql”>INSERT INTO forum_attachment SET `tid`=’0′ , `pid`=’0′ , `uid`=’1′ , `tableid`=’127′</div></div><div class=”info”><p><strong>PHP Debug</strong></p><table cellpadding=”5″ cellspacing=”1″ width=”100%” class=”table”><tr class=”…
—————————
确定
我们看到实际上是一段html代码(其实如果站长关注后台的运行记录,也会有这个报错的,只不过我是先排查代码,才发现的),也就是Discuz! X的MySQL报错信息页面,这里最重要的信息就是MySQL的报错了,Discuz! Database Erro (1062) Duplicate entry ‘107697’ for key 1 INSERT INTO forum_attachment SET `tid`=’0′ , `pid`=’0′ , `uid`=’1′ , `tableid`=’127′ 。知道了aid 1062 报错,即插入了重复的值,那么就好办了,去pre_forum_attachment 修改自增值就可以了,自增值修改成什么呢,当然要看一下aid当前的最大值多少,然后加1就是要修改的自增值了。可以在MySQL命令行执行:alter table pre_forum_attachment auto_increment = aid最大值+1 ,如果有phpMyAdmin的话,更好操作了了,这里就不多说了。至于为什么自增值会出问题,还没详细研究,不过收集的几个情况包括重启服务器,数据库迁移等操作。

Discuz! 上传附件出现500错误的解决方法

有用户反馈,上传附件会提示500错误,经过排查,是服务器指定的临时目录满了,或者临时文件太多,导致读取临时上传文件失败,解决方法是清空临时目录,或者新建一个指定好文件名的临时文件夹。

pw90数据字典

pw90数据字典

html版下载

pw_acloud_apis
字段名 数据类型 默认值 允许非空 自动递增 备注
id int(10) unsigned NO 是
name varchar(255) NO
template text YES
argument varchar(255) NO
argument_type varchar(255) NO
fields varchar(255) NO
status tinyint(3) 0 NO
category tinyint(3) 0 NO
created_time int(10) unsigned 0 NO
modified_time int(10) unsigned 0 NO

Read the rest of this entry »

升级至Discuz! X2.5后,导致楼层错乱的快速解决办法

Discuz! X2.5的帖子表(post)新增position字段,通过执行updata.php执行升级,如果post表数据过大,会有一定概率导致position自增值不准,官网有个解决方案,但有些站点出现问题的帖子数实在太多,执行解决方案中的脚本太慢,现在把存MySQL命令给出,速度还不错。如果你执行了update.php,那么需要你去数据库中删除掉联合主键 (tid,position)和position字段,由于position有自增属性,所以需要先去掉自增属性(AUTO_INCREMENT)再进行删除。准备工作做完后,就可以执行下面的命令了,

ALTER TABLE pre_forum_post ADD `position` INT(8) UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY(`tid`, `position`);

注意,我这里写的pre_是表前缀,依据你的站点数据库配置进行调整。操作之前一定要备份post表

Discuz! 找回密码提示“账户资料不匹配,不能使用取回密码功能”问题

最近处理问题,遇到站长反馈,有部分用户出现找回密码提示“抱歉,您填写的账户资料不匹配,不能使用取回密码功能,如有疑问请与管理员联系”,出现这个问题的原因大概是因为早前有过其它应用,当时对邮件地址大小写不做限制,现在填写邮箱及用户名找回密码的时候,程序里会把用户输入的邮箱处理成小写,那么就与UCenter中保存的用户邮箱匹配不上了,最后导致了这个错误。解决方法就是把从UCenter读出来的邮箱也处理为小写的字符串,要改哪里呢?看代码:
source/module/member/lostpassword.php文件,

	if($_GET['username']) {
		list($tmp['uid'], , $tmp['email']) = uc_get_user(addslashes($_GET['username']));
		if($_GET['email'] != strtolower($tmp['email']) { //这里加上strtolower小写函数处理就可以了。
			showmessage('getpasswd_account_notmatch');//这里就是报错提示
		}
		$member = getuserbyuid($tmp['uid'], 1);
	}

Discuz! X2.5群组简介html标签问题

在前台群组设置简介,后台再次更新简介时,会造成html标签解析错乱;
解决方法:
找到\source\admincp\admincp_group.php,搜索:
$group = C::t(‘forum_forum’)->fetch_info_by_fid($fid);
在下面加上如下代码:
require_once libfile(‘function/editor’);
$group[‘description’] = html2bbcode($group[‘description’]);
复制代码

$_GET[‘descriptionnew’] = discuzcode(dhtmlspecialchars(censor(trim($_GET[‘descriptionnew’]))), 0, 0, 0, 0, 1, 1, 0, 0, 1);

在上面加上以下代码:
require_once libfile(‘function/discuzcode’);

Discuz! X2.5QQ登录流程修改方法

本文档介绍如何优化注册、完善资料流程,请注意,本文档仅适合Discuz! X2.5版本。
应用场景:Discuz! X2.5对QQ登录流程进行了修改,默认为QQ游客组,如果QQ初次登录后进行发帖或使用漫游应用时,提示权限有限,需完善资料,致使部分以QQ登录用户为主的站点用户流失严重。

主要修改思路:修改QQ首次登录后的跳转到完善资料页,并在跳转之前增加一段随机生成电子邮件地址代码,邮件地址后缀取的是网站的域名;完善资料页调用系统模版的register.htm文件,对是否为QQ首次登录做出判断,接到$_GET的电子邮件地址并隐藏显示,无需用户填写,用户名自动获取。 Read the rest of this entry »