我正在尝试在wordpress中使用库PHPExcel。
我创建了一个解析csv文件的类,但只是调用该方法来读取文件PHPExcel_IOFactory::load($file)
,甚至可以识别文件,分页符。
问题是我没有得到任何结果,只有空白页面。
甚至没有出现apache日志错误。
课程是这样的:
require('vendor/PHPExcel/Classes/PHPExcel/IOFactory.php');
class parseCsv {
protected $file;
protected $fileType;
public function __construct($file)
{
$this->file = $file;
$this->fileType = PHPExcel_IOFactory::identify($this->file);
}
public function parseCsv()
{
$objReader = PHPExcel_IOFactory::createReader($this->fileType);
$objPHPExcel = $objReader->load($this->file);
$objWorksheet = $objPHPExcel->getActiveSheet();
foreach ($objWorksheet->getRowIterator() as $row) {
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
$cell_value = $cell->getValue();
var_dump($cell_value);
}
}
}
}
绝对错了,但我无法弄清楚在哪里。
修改
以这种方式在wp-content/themes/myproject
中的functions.php文件中实例化类名:
function exec_at_init()
{
...
require('helpers/parse/parse.php');
}
function create_regcontabilita()
{
$parse = new parse('helpers/parse/matrice.csv');
$parse->parseCsv();
}
答案 0 :(得分:0)
如果页面中断可能是错误500
请在刷新页面后检查响应状态(检查chrome中的元素,网络选项卡)。
如果状态为500则可能是php脚本错误。 如果是这种情况,页面是空白的,因为php.ini error_reporting配置可能设置为隐藏一些错误。
将其添加到脚本的开头并尝试。
error_reporting(E_ALL);
答案 1 :(得分:0)
这听起来非常像路径问题。
根据建议,如果添加
error_reporting(E_ALL);
错误将显示在apache错误日志中。