Get Macro Information from an Excel File in PHP

Cloudmersive
1 min readMar 25, 2021

Excel files frequently have macros built into their framework to assist in better managing and manipulating data. If you have any concerns about the VBA code that may be present in a particular document, we have an API that can help with that. In the following tutorial, we will cover how to use an API in PHP to obtain information about the macros in a single XLSX spreadsheet or worksheet.

Let’s begin by installing the package:

composer require cloudmersive/cloudmersive_document_convert_api_client

Now we can move on to configuring the API key and calling the get macros function:

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\EditDocumentApi(


new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->editDocumentXlsxGetMacroInformation($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditDocumentApi->editDocumentXlsxGetMacroInformation: ', $e->getMessage(), PHP_EOL;
}
?>

Done! Macro information from the file will be returned instantly.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.