KKL Michael
KKL Michael

Reputation: 795

Box/Spout questions

This is my first time using Box/Spout library. I am using WAMP server.
My question is the following:

require_once('./spout-master/src/Spout/Autoloader/autoload.php');

use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;

$filePath = 'test.xlsx';
$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($filePath);

[X]

$writer->addRow(['a'], $style);
$writer->close();

(1)
When I am running above code, I get the following error message:

Warning: rmdir(C:\WINDOWS\TEMP/xlsx560f58d588ceb): Permission denied in        
C:\wamp\www\1300.revenue.com.my\public_html\spoutmaster\src\Spout\Common\Helper\FileSystemHelper.php on line 113

What is the errors means and how should I modify it to prevent this error message appeared?

(2) I want to make expected output like below:

enter image description here

But I didn't know how to write it on [X] part. How to write it in order to get the expected output?

Upvotes: 2

Views: 7471

Answers (1)

Adrien
Adrien

Reputation: 1947

It looks like the default temp folder used to generate the XLSX file cannot be deleted. You can verify it by checking the permissions on C:\WINDOWS\TEMP/xlsx560f58d588ceb.

To solve this issue, you can either manually fix the permissions on the temp folder (C:\WINDOWS\TEMP) or use another temporary folder, as specified here: https://github.com/box/spout#using-custom-temporary-folder

Regarding 2), there is no straightforward way to do this whith Spout. Spout does not support merging cells. The only thing you can do is:

| 1 | 2 |   | 3 |   |
|---|---|---|---|---|
|   | A | B | A | B |
|---|---|---|---|---|

Or alternatively (if that makes more sense):

| 1 | 2 | 2 | 3 | 3 |
|---|---|---|---|---|
| 1 | A | B | A | B |
|---|---|---|---|---|

Either way, you'll have to format the rows as shown above: [[1,2,'',3',''], ['', 'A','B','A','B']] or [[1,2,2,3,3], [1, 'A','B','A','B']]

Upvotes: 2

Related Questions