ribojhin/excelmacro

Edit an Excel file that contains macros

0.1.4 2025-01-12 16:42 UTC

This package is not auto-updated.

Last update: 2025-06-02 10:56:59 UTC


README

This PHP library allows you to modify an Excel file that contains macros without disabling them. For most PHP projects, the library (https://github.com/PHPOffice/PhpSpreadsheet) allows you to manipulate Excel files. However, when you modify an Excel file with macro (xlsm), the macros no longer work. This PHP library will allow you to modify XLSM files without disabling macros. The library only applies to Excel files with macros

Requirements

Installation

You can use Composer or simply Download the Release

Composer

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

  composer require ribojhin/excelmacro

Finally, be sure to include the autoloader:

<?php
  require_once '/path/to/your-project/vendor/autoload.php';

Quickstart

The example below will load data into an excel file that contains macros:

<?php
  require_once 'autoload.php';                                      // Comment this line if you use Composer to install the package
  use \Ribojhin\Excelmacro;

  $excelMacro = new Excelmacro("_FILE_PATH_SRC_XLSM_");              // Set excel file path you want to edit
  $excelMacro->setSheet(0);                                         // Set sheet by index
  $excelMacro->setCellValue($excelMacro->getSheet(), "_KEY_", '_VALUE_'); // Set cell
  $excelMacro->save("_FILE_PATH_DEST_XLSM_");                        // Set destination file path