【问题标题】:How to use new PhpSpreadsheet with ZF1如何在 ZF1 中使用新的 PhpSpreadsheet
【发布时间】:2023-02-13 20:12:57
【问题描述】:

在 PHP 7 之前,我使用 PHPEXcel。 现在,我使用 PHP 7.4,并且我必须在我的 Zend Framework 1 Web 应用程序中使用 PhpSpreadsheet。

意思是,恕我直言,不使用作曲家,所以我的问题很简单:如何?

尝试在我的项目中使用示例,但无法正常工作

【问题讨论】:

    标签: php phpspreadsheet


    【解决方案1】:

    如果您没有在 Zend Framework 1 Web 应用程序中使用 Composer,您仍然可以通过在项目中包含其依赖项和库本身来使用 PHPOffice/PhpSpreadsheet。这是一个分步指南:

    1.下载PHPOffice/PhpSpreadsheet及其依赖。您可以在 GitHub 上找到最新版本的 PhpSpreadsheet:https://github.com/PHPOffice/PhpSpreadsheet

    2.将下载的存档解压缩到项目的库文件夹中。例如,如果您的库文件夹位于/path/to/your/project/library,请将 PhpSpreadsheet 提取到/path/to/your/project/library/PhpSpreadsheet。

    3.在您的项目中包含 PhpSpreadsheet 自动加载器。您可以通过将以下代码行添加到您的引导程序文件或您的控制器来执行此操作:

    require_once '/path/to/your/project/library/PhpSpreadsheet/vendor/autoload.php';

    4.你现在可以在你的项目中使用PhpSpreadsheet了。以下是如何读取 Excel 文件的示例:

    use PhpOfficePhpSpreadsheetIOFactory;
    
    $spreadsheet = IOFactory::load('/path/to/your/file.xlsx');
    $sheet = $spreadsheet->getActiveSheet();
    
    // Read data from the first row
    $row = 1;
    $cellValue = $sheet->getCellByColumnAndRow(0, $row)->getValue();
    
    // Read data from a range of cells
    $highestRow = $sheet->getHighestRow();
    $highestColumn = $sheet->getHighestColumn();
    $data = $sheet->rangeToArray(
        'A1:' . $highestColumn . $highestRow,
        NULL,
        TRUE,
        FALSE
    );
    
    

    这是一个让您开始在 Zend Framework 1 Web 应用程序中使用 PhpSpreadsheet 的基本示例。您可以在官方文档中找到更多信息和示例:https://phpspreadsheet.readthedocs.io/en/develop/。

    【讨论】:

      猜你喜欢
      • 2020-02-01
      • 1970-01-01
      • 2019-07-30
      • 2019-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      相关资源
      最近更新 更多