标签: phpoffice

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万
查看次数

如何使用PHP从word文档中提取文本内容?

我想用PHP从word文档中提取文本内容.

我在Microsoft Word for Mac 2011中创建了一个新的word文档.编辑:还通过在Windows 7下的Microsoft Word中创建相同的文档进行了测试.

该文件的内容是

The quick brown fox jumps over the lazy dog
Run Code Online (Sandbox Code Playgroud)

我已将其作为Word 97-2004文档(.doc)保存到磁盘.

我正在使用phpoffice/phpword和此代码来提取文本:

<?php

$source = "word.doc";

$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'MsDoc');

$text = '';

$sections = $phpWord->getSections();

foreach ($sections as $s) {
    $els = $s->getElements();
    foreach ($els as $e) {
        if (get_class($e) === 'PhpOffice\PhpWord\Element\Text') {
            $text .= $e->getText();
        } elseif (get_class($e) === 'PhpOffice\PhpWord\Section\TextBreak') {
            $text .= " \n";
        } else {
            throw new Exception('Unknown class type ' . get_class($e));
        } …
Run Code Online (Sandbox Code Playgroud)

php phpoffice

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

phpspreadsheet中的动态单元格合并

我的问题是关于在 codeigniter 中生成 Excel 表。Excel 工作表子标题不是固定的,它们是根据数据确定的,这就是我无法合并单元格的原因。有什么解决办法吗?例如:-这里的子标题不是固定的。

codeigniter-3 phpoffice phpspreadsheet

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

如何在php phpspreadsheet中使用excel求和公式?

我正在使用 PhpSpreasdheet php 库。我已经完成了几乎所有我想要对特定列进行求和并想要显示该列的总计的操作。请参阅下面的我的输出:- 在此输入图像描述

我的预期输出如下:- 在此输入图像描述

我尝试过下面的代码:-

$spreadsheet = new Spreadsheet();
$Excel_writer = new Xlsx($spreadsheet);
$spreadsheet->setActiveSheetIndex(0);
$activeSheet = $spreadsheet->getActiveSheet();

$activeSheet->setCellValue('A1', 'Location');
$activeSheet->setCellValue('B1', 'Media Vehicle');
$activeSheet->setCellValue('C1', 'Dimension');
$activeSheet->setCellValue('D1', 'Amount');

$spreadsheet->getActiveSheet()->setAutoFilter('A1:D1');
    $locations = DB::table('locations')->get();
    $locations = json_decode(json_encode($locations),true);
    $i = 2;
    foreach($locations as $location){
        $activeSheet->setCellValue('A'.$i , $location['location']);
        $activeSheet->setCellValue('B'.$i , $location['media_vehicle']);
        $activeSheet->setCellValue('C'.$i , $location['dimension']);
        $activeSheet->setCellValue('D'.$i , $location['amount']);
        $i++;
    }

    $samplepath = storage_path('/excels/sampleExcel'.str_random(5).'.xlsx');
    $Excel_writer->save($samplepath);
    echo 'saved'; die;
Run Code Online (Sandbox Code Playgroud)

我想要金额列的总计。我想要动态化。如果将来它是 10 行,那么它将计算 10 行的金额列计数。

php excel phpoffice phpspreadsheet

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

ZipArchive :: close():无法创建临时文件:权限被拒绝的nginx

我很乐意建议如何解决以下问题。对于平台,我必须创建php word文档,并且碰巧在Apache开发环境中,该代码可以完美执行。但是在nginx平台上,如主题所示,我继续收到错误:

ZipArchive::close(): Failure to create temporary file: Permission denied
Run Code Online (Sandbox Code Playgroud)

建立起来非常简单:

$phpWord = new \PhpOffice\PhpWord\PhpWord();

//code block as in the documentation

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord,'Word2007');

$objWriter->save('doorverwijzing_patient_xxxxxxxxxx.docx');
Run Code Online (Sandbox Code Playgroud)

在哪里可以更改nginx文件夹结构中的这些权限以创建这些文档?

phpword phpoffice

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

将DOCX转换为PDF时没有样式

我正在尝试使用PHPWord将DOCX文件转换为PDF.当我执行脚本时,看起来似乎没有转换某些样式元素.在DOCX文件中,我有一个图像,两个带边框1px和隐藏边框的表,我正在使用Tabs.

当我执行脚本时,我得到一个没有图像的PDF文件,所有的Tab都被替换为Space,所有的表都有一个3px的边框.

有人知道我为什么错过这些款式吗?

这是我的脚本:

while ($data2 = mysql_fetch_array($rsSql)){
  $countLines=$countLines+1;
  $templateProcessor->setValue('quantity#'.$countLines, $data2['quantity']);
  $templateProcessor->setValue('name#'.$countLines, $data2['name']);
  $templateProcessor->setValue('price#'.$countLines, "€ " .$data2['price'] ."");
}

\PhpOffice\PhpWord\Settings::setPdfRenderer('./dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererPath('./dompdf');
\PhpOffice\PhpWord\Settings::setPdfRendererName('DOMPDF');

$temp_file = tempnam(sys_get_temp_dir(), 'Word');
\$templateProcessor->saveAS($temp_file);

$phpWord = \PhpOffice\PhpWord\IOFactory::load($temp_file); 

$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord , 'PDF');
$xmlWriter->save('result.pdf');  

header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='result.pdf'");
readfile("result.pdf");
Run Code Online (Sandbox Code Playgroud)

php dompdf phpword phpoffice

7
推荐指数
1
解决办法
1239
查看次数

使用 PHPSpreadsheet 打开受密码保护的 XLSX 文件

我正在尝试使用PHPSpreadsheet文档)打开受密码保护的 Excel 文件 (.xlsx )。我知道密码,但我找不到打开它的方法。

load()方法\PhpOffice\PhpSpreadsheet\Reader\Xlsx不能插入密码,当我尝试加载文件时,它会返回错误(当然)。

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

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load('hello world.xlsx');
$sheet = $spreadsheet->getActiveSheet();
echo $sheet->getCell('A1')->getValue() . "\n";
Run Code Online (Sandbox Code Playgroud)

这是错误

警告:ZipArchive::getFromName():第 311 行 /PHPOffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php 中的 Zip 对象无效或未初始化 警告:ZipArchive::getFromName():无效或未初始化的 Zip 对象在 /PHPOffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php 第 313 行警告:为 /PHPOffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php 中的 foreach() 提供的参数无效第 350 行警告:ZipArchive::getFromName():/PHPOffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php 中的 Zip 对象无效或未初始化,第 311 行警告:ZipArchive::getFromName():无效或313 行 /PHPOffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php 中未初始化的 Zip 对象警告:在 /PHPOffice/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php 第 397 行中为 foreach() 提供的参数无效警告:ZipArchive::getFromName():/PHPOffice/vendor/phpoffice 中的 Zip 对象无效或未初始化/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php on line 311 警告:ZipArchive::getFromName(): Invalid or uninitialized …

php phpoffice phpspreadsheet

6
推荐指数
1
解决办法
2343
查看次数

Laravel 刀片文件到 word 文档

我正在将数据从我的控制器传递到我的刀片文件,然后想将刀片文件导出到 word 文档,到目前为止一切都被控制了,我可以将刀片导出到 word 文档,问题是该文档没有在 Microsoft Word 中打开说“单词在 1.docx 中发现不可读的内容”。下面是我正在使用的代码

$view = View::make('advertisement.advt_template.template_dr')->with('advtData', $advtData->first())->render();
$file_name = strtotime(date('Y-m-d H:i:s')) . '_advertisement_template.docx';
$headers = array(
            "Content-type"=>"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "Content-Disposition"=>"attachment;Filename=$file_name"
        );
return response()->make($view, 200, $headers);
Run Code Online (Sandbox Code Playgroud)
  • 我将数据传递给刀片,然后将所有信息存储在一个变量中
  • 创建文件名以供参考
  • 创建下载文件时使用的标头
  • 使用刀片内容变量和标头信息进行响应

任何帮助将不胜感激

php laravel phpoffice

6
推荐指数
2
解决办法
5927
查看次数

PHPWord addTOC 不显示页码

我正在使用https://github.com/PHPOffice/PHPWord生成一个 word 文档。函数 addTOC 生成带有标题的页面索引,但由于某种原因页码不显示。

// add table of contents
$section->addTOC();
Run Code Online (Sandbox Code Playgroud)

结果是:

目录

如果我在标题存在的页面上回显页码,它们显示得很好。但它们不会显示在 TOC 中。我检查以确认文本不是白色的。

phpword phpoffice

5
推荐指数
1
解决办法
2767
查看次数

我们发现“Spreadsheet.xlsx”中的某些内容存在问题。您希望我们尽力恢复吗?

我有以下基本 PHP 项目(只有一个文件加上 Composer 配置):

作曲家.json

{
    "config": {
        "optimize-autoloader": true,
        "platform": {
            "php": "7.4.9"
        }
    },
    "require": {
        "phpoffice/phpspreadsheet": "1.10.0"
    }
}
Run Code Online (Sandbox Code Playgroud)

索引.php

<?php

require_once __DIR__ . '/vendor/autoload.php';
function errorHandler() {
    return true;
}
set_error_handler('errorHandler');

$sheets = array(
    array('index' => 0, 'title' => 'Graph'),
    array('index' => 1, 'title' => 'Data'),
);

$phpSpreadsheetObject = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

foreach ($sheets as $sheet) {
    $name = $sheet['title'];
    if ($sheet['index']) {
        $worksheet[$name] = $phpSpreadsheetObject->createSheet($sheet['index']);
    } else {
        $worksheet[$name] = $phpSpreadsheetObject->getActiveSheet();
    }
    $phpSpreadsheetObject->setActiveSheetIndex($sheet['index']);
    $worksheet[$name]->setTitle($sheet['title']);
} …
Run Code Online (Sandbox Code Playgroud)

php excel phpoffice phpoffice-phpspreadsheet

5
推荐指数
1
解决办法
1932
查看次数