Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

cakephp - How to use PhpSpreadsheet in cakephp2

I Tried Many Thing To Implement PhpSpreadsheet in CakePHP 2.x , In CakePHP 4 It Worked For Me.

Finally I Tried things mentioned in given link blog

http://abakalidis.blogspot.com/2018/08/how-to-use-latest-phpofficespreadsheet.html

It solve all issue but it generating Xlsx file. For XLS it worked.

After putting PHPSpreadsheet SOrce TO Vender In App Folder.

I Use Following Code

<?php
use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);
$spreadsheet->createSheet();
$writer->save('hello world.xlsx');
?>

For XLS I Replace 3 lines as below

<?php

use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXls;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xls($spreadsheet);
$spreadsheet->createSheet();
$writer->save('hello world.xls');
?>

This Code Worked , But For Xlsx It IS giving Error


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...