标签: phpspreadsheet

使用PHPExcel设置电子表格单元格的宽度

我正在尝试使用PHPExcel生成的Excel文档中设置单元格的宽度:

$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn('C')->setWidth('10');
$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn('C')->setAutoSize(false);
Run Code Online (Sandbox Code Playgroud)

但那不起作用.

我需要在这里打电话的方法是什么?

php phpexcel phpspreadsheet

65
推荐指数
6
解决办法
13万
查看次数

PHPExcel和PhpSpreadsheet之间的主要区别是什么?

PHPOffice的项目中,有两个与电子表格文件格式相关的项目:

PHPExcel

PHPExcel是一个用纯PHP编写的库,它提供了一组类,允许您写入和读取不同的电子表格文件格式,如Excel(BIFF).xls,Excel 2007(OfficeOpenXML).xlsx,CSV,Libre/OpenOffice Calc .ods,Gnumeric,PDF,HTML,...这个项目是围绕微软的OpenXML标准和PHP构建的.

PhpSpreadsheets

PhpSpreadsheet是一个用纯PHP编写的库,它提供了一组类,允许您读取和写入不同的电子表格文件格式,如Excel和LibreOffice Calc.

它们之间的主要区别是什么?

php phpexcel phpoffice phpspreadsheet

18
推荐指数
2
解决办法
2万
查看次数

如何在没有安装的情况下使用PhpSpreadsheet(如PHPExcel)

根据PhpSpreadsheet Doc,使用composer安装它是必要的.在我的情况下,我只有一个没有终端但没有Plesk的网站空间.难道反正可以使用PhpSpreadsheet,就像它与PHPExcel,你只需要将文件放置在任何位置?我该怎么办才能让它运行?我发现没有进一步的信息如何只使用FTP webserver访问.

php phpexcel phpspreadsheet

15
推荐指数
2
解决办法
3万
查看次数

PHPSpreadsheet - 如何将链接中的图像放入我的 excel 文件中?

我想在我的 excel 文件中的单元格 a1 中放置一个图像。

我从 phpspreadsheet 网站尝试了不同的东西,但都没有成功。就像他们的这个例子不起作用。:

$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Paid');
$drawing->setDescription('Paid');
$drawing->setPath('https://pngimage.net/wp-content/uploads/2018/06/rfhnbyrb-png-6.png');
$drawing->setCoordinates('B15');
$drawing->setOffsetX(110);
$drawing->setRotation(25);
$drawing->getShadow()->setVisible(true);
$drawing->getShadow()->setDirection(45);
Run Code Online (Sandbox Code Playgroud)

如果我创建一个带有文本的黑条,它可以使用以下代码。:

$gdImage = @imagecreatetruecolor(2000, 20) or die('Cannot Initialize new GD image stream');
$textColor = imagecolorallocate($gdImage, 255, 255, 5);
imagestring($gdImage, 1, 5, 5, date("F Y"), $textColor);

//  Add the In-Memory image to a worksheet
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
$drawing->setName('In-Memory image 1');
$drawing->setDescription('In-Memory image 1');
$drawing->setCoordinates('A1');
$drawing->setImageResource($gdImage);
$drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setHeight(36);
$drawing->setWorksheet($spreadsheet->getActiveSheet());
Run Code Online (Sandbox Code Playgroud)

我的尝试在我的 excel 文件中没有得到图像,请谁愿意帮助我。

php phpspreadsheet

12
推荐指数
2
解决办法
2万
查看次数

带文本的数字单元格格式

我想使用 phpspreadsheet 将数据导出到 Excel,但我的数据是 12 个字符的数字。所以我需要显示所有字符(121212121212)而不是(1.21212E+11)。

我尝试过使用格式

PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT
Run Code Online (Sandbox Code Playgroud)

PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER
Run Code Online (Sandbox Code Playgroud)

这不起作用。

这是我的单元格格式化代码:

$spreadsheet->getActiveSheet()->getStyle('B')->getNumberFormat()
    ->setFormatCode(PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT);
Run Code Online (Sandbox Code Playgroud)

这是我的值插入代码:

$sheet->setCellValue('A'.$i, $i-1);
        $sheet->setCellValue('B'.$i, $useric);
Run Code Online (Sandbox Code Playgroud)

如果我使用 FORMAT_TEXT 结果是这样的:

![result](https://i.imgur.com/6xxKDkv.png)
Run Code Online (Sandbox Code Playgroud)

php phpspreadsheet

11
推荐指数
2
解决办法
2万
查看次数

使用PHPSpreadsheet构建非常大的电子表格

我正在测试PHPSpreadsheet如何与大型Excel电子表格配合使用.初步测试表明,对于大型电子表格,会很快耗尽内存.

有没有办法逐步编写电子表格?

我有一段旧代码,我已经用了很长时间来创建PHP的电子表格.它使用了一个非常古老的标准,并且是一个更新.但是我的旧代码的一个优点是我可以写入文件而不是在内存中构建整个文件,因此可以轻松应对非常大的电子表格而不会超出内存限制.

在PHPSpreadsheet中可以做类似的事情吗?我已经尝试阅读文档,搜索各种论坛,但大多数回复似乎只是"增加可用内存".

php memory excel phpspreadsheet

10
推荐指数
2
解决办法
7718
查看次数

在 PhpSpreadsheet 中读取 Xlsx 文件

我想读取xlsx在 Microsoft Excel 中创建的文件,但是当我运行以下代码时...

$Source_File = "test.xlsx";
$Spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($Source_File);
Run Code Online (Sandbox Code Playgroud)

...我收到以下错误:

Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Reader\Exception: Unable to identify a reader for this file in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php:163
Stack trace:
  #0 /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php(93): PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile('file:///home/ar...')
  #1 /var/www/html/Function_Spreadsheet.php(480): PhpOffice\PhpSpreadsheet\IOFactory::load('file:///home/ar...')
  #2 /var/www/html/Function_Home.php(3747): Spreadsheet_Reader_1('/var/www/html/F...', 3745, Array, Array)
  #3 {main} thrown in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php on line 163
Run Code Online (Sandbox Code Playgroud)

如果我改为使用,我会得到同样的错误 $Spreadsheet = IOFactory::load($Source_File);

如果我改为使用,我会收到以下错误 $Spreadsheet = $reader->load($Source_File);

Warning: ZipArchive::getFromName(): Invalid or uninitialized Zip object in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 311

Warning: ZipArchive::getFromName(): Invalid or uninitialized Zip object in /var/www/html/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line …
Run Code Online (Sandbox Code Playgroud)

php excel xlsx ziparchive phpspreadsheet

10
推荐指数
1
解决办法
2万
查看次数

Composer需要phpoffice/phpspreadsheet不起作用

我想使用包Phpspreadsheet编写脚本.我不是PHP的经验.我试图通过sudo composer需要phpoffice/phpspreadsheet添加对我的脚本的引用.但它不起作用.我收到错误:在stallation失败,删除composer.json ....如果不知道为什么它不工作.任何的想法?

详细错误:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for phpoffice/phpspreadsheet ^1.0 -> satisfiable by phpoffice/phpspreadsheet[1.0.0].
- phpoffice/phpspreadsheet 1.0.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.

To enable extensions, verify that they are enabled in those .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- …
Run Code Online (Sandbox Code Playgroud)

php excel phpspreadsheet

9
推荐指数
3
解决办法
2万
查看次数

PhpSpreadsheet - 下载文件而不是保存文件

我需要生成一个excel文件(xls)并在生成后触发下载。我在文档中找到了这个例子。

<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

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

$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
Run Code Online (Sandbox Code Playgroud)

它展示了如何创建一个 excel 文件并将其保存在服务器上。我如何才能将结果提供给客户端并“强制”他下载它?我需要以$writer某种方式获取数据。

我目前正在解决它而没有 PhpSpreadsheet:

// Excel Export 
    $filename = 'export_'.date('d-m-y').'.xls';
    $filename = $validator->removeWhitespace($filename);

    header('Content-type: application/ms-excel');
    header('Content-Disposition: attachment; filename='.$filename);
    exit($response["output"]);  // <-- contains excel file content
Run Code Online (Sandbox Code Playgroud)

但它不适用于我的分隔符(分号)。分号没有得到解释,所有内容都被写入一列。

在此处输入图片说明

If I export it as .csv, then it works. But I need it as .xls or .xlsx

php phpspreadsheet

9
推荐指数
4
解决办法
2万
查看次数

下载PhpSpreadsheet文件而不保存

我正在使用PhpSpreadsheet在Symfony 4中生成一个Excel文件.我的代码是:

$spreadsheet = $this->generateExcel($content);

$writer = new Xlsx($spreadsheet);
$filename = "myFile.xlsx";
$writer->save($filename); // LINE I WANT TO AVOID
$response = new BinaryFileResponse($filename);
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->setContentDisposition(
    ResponseHeaderBag::DISPOSITION_ATTACHMENT,
    $filename
);
Run Code Online (Sandbox Code Playgroud)

但我不想保存文件,然后读取它以返回给用户.我想直接下载Excel内容.有办法吗?

我已经搜索了如何生成内容流(正如这个答案所说),但我没有成功.

提前致谢,对不起我的英语

php-7 phpspreadsheet symfony4

8
推荐指数
1
解决办法
9679
查看次数

标签 统计

phpspreadsheet ×10

php ×9

excel ×3

phpexcel ×3

memory ×1

php-7 ×1

phpoffice ×1

symfony4 ×1

xlsx ×1

ziparchive ×1