我使用下面的代码,所有PHPexcel库数据都在下面的图片中。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<!-- I want to change the "data-value" value here (it's a meter gauge lots of JS -->
<div class="gauge" id="guagechanger" data-plugin="gauge" data-value="1" data-min-value="1" data-max-value="10" data-stroke-color="#f978a6">
<div class="gauge-label"></div>
<canvas width="200" height="150"></canvas>
</div>
<!-- my plus and minus buttons -->
<button type="button" class="btn btn-floating btn-danger value-control" data-action="minus" data-target="guagechanger"><i class="icon wb-minus" aria-hidden="true"></i></button>
<button type="button" class="btn btn-floating btn-danger value-control" data-action="plus" data-target="guagechanger"><i class="icon wb-plus" aria-hidden="true"></i></button>
我想阅读NIB.xlsx文件,我已阅读此help link。
但是,当我运行PHP脚本时,收到以下错误:
致命错误:Class&#39; PHPExcel_IOFactory&#39;在untitled-2.php中的phpExcel中找不到
答案 0 :(得分:1)
我想您忘记包含PHPExcel文件了 在代码的开头添加此行
require 'PHPExcel/Classes/PHPExcel.php';
别忘了添加文件夹的路径,将其放在不同的文件夹中
答案 1 :(得分:0)
尝试官方文档中的一些简单示例时,我也收到此错误。我正在使用随Composer安装的PHPOffice。如果在本地安装,则概念应相同。错误基本上是路径问题,即脚本不知道可以在哪里找到IOFactory。这是我找到的完整的工作解决方案。
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$styleArray = [
'font' => [
'bold' => true,
],
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
],
'borders' => [
'top' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
],
],
'fill' => [
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
'color' => [
'argb' => 'FFA0A0A0',
]
],
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$spreadsheet->getActiveSheet()->getStyle('A3:m3')->applyFromArray($styleArray);
// Redirect output to a client's web browser (Xlsx)
header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="webstats.xlsx"');
header('Cache-Control: max-age=0');
$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;
我将在线示例中的这一行更改为
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
对此
$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
并且IO错误已解决