我无法在kohana 3.2中使用 spout 库将大型Excel文件导入mysql。这些是我采取的安装步骤:
在门户文件index.php中,我添加了以下代码:
reader
这是我的public static function reader($filename){
$result = array();
$reader = ReaderFactory::create(Type::XLSX);
$reader->open($filename);
while ($reader->hasNextRow()) {
$row = $reader->nextRow();
$code = $row[1];
$result[] = $code;
}
return $result;
}
方法:
ERROR: ErrorException [ 1 ]: Class 'ReaderFactory' not found ~ APPPATH/classes/kohana/spoutexcel.php [ 70 ]
2015-09-25 14:29:10 --- STRACE: ErrorException [ 1 ]: Class 'ReaderFactory' not found ~ APPPATH/classes/kohana/spoutexcel.php [ 70 ]
当我尝试调用该方法时,会显示以下错误消息:
$username = $_REQUEST['myusername'];
$password = $_REQUEST['mypassword'];
$qry = mysql_query("select * from table_users where username = '$username' and password = '$password' ");
if($qry && mysql_num_rows($qry) == 1)
{
header('location: dashborad.php');
}
else
{
$_SESSION['msg'] = 'something went wrong';
header('location: index.html');
}
我做错了什么?
Spout可以在这里找到:https://github.com/box/spout
答案 0 :(得分:1)
你是如何安装Spout的?如果您使用了Composer,则在安装Spout时,您需要包含(require_once
)作曲家生成的autoload.php
文件。
如果您没有使用Composer,可以按照此处的说明进行操作:https://github.com/box/spout#manual-installation。它解释了您需要包含哪个文件来自动加载Spout类。
正如@mrBrown所提到的,不要忘记使用use Box\Spout\Reader\ReaderFactory;
答案 1 :(得分:0)
您是否定义了命名空间?
use Box\Spout\Reader\ReaderFactory;