How to Extract Macro Details from an Excel File in C#

Cloudmersive
2 min readMar 23, 2021

--

Extracting information from an Excel file in C# can be a bit tricky; there are many different elements that make up a spreadsheet, and they can make navigation difficult. In today’s tutorial, we will discuss how to use an API in C# to get information about the macros defined in an Excel spreadsheet.

Our first step is to install the package; we have .NET Framework and .NET Core available, but I will be using .NET Framework for this example.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2

With the installation out of the way, we are ready to call the function with the following code:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;
namespace Example
{
public class EditDocumentXlsxGetMacroInformationExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new EditDocumentApi();
var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.
try
{
// Get macro information from a Excel XLSX/XLSM spreadsheet, worksheet
GetMacrosResponse result = apiInstance.EditDocumentXlsxGetMacroInformation(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling EditDocumentApi.EditDocumentXlsxGetMacroInformation: " + e.Message );
}
}
}
}

The response will be returned in seconds and will indicate if VBA macros are present in your document.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet