Documents for Excel .NET Edition | GCDocuments
File Operations / Import and Export Macros
In This Topic
    Import and Export Macros
    In This Topic

    This section summarizes how GcExcel.NET handles the import and export of Excel files containing macros. Using GcExcel.NET, users can load and save Excel files containing macros (.xlsm files) without any hassles. Please note that GcExcel will not execute these macros.

    Typically, this feature has been introduced in order to allow users to load and save macro-enabled spreadsheets. Macros help automate repetitive tasks and hence, reduce significant amount of time while working with spreadsheets. Now, users can load such spreadsheets in GcExcel directly as Xlsm files, modify them easily and quickly and then save them back.

    During the execution of import and export operations on the Excel files, all the macros will also be preserved concurrently along with the data. While opening and saving the Excel workbooks or Excel macro-enabled workbooks, macros will always be imported and exported respectively. The form controls and ActiveX controls are also supported during the import and export operations.

    When the OpenFileFormat is Xlsm, macros will be imported. When the SaveFileFormat is Xlsm, macros will be exported.

    Note: While preserving the macros on import or export of Excel files, GcExcel will not execute these macros.

    Refer to the following example code in order to import and export macros in spreadsheet documents.

    Copy Code
    // Open a .xlsm file with file name
    var workbook = new Workbook();
    // Save workbook as Excel macro-enabled workbook file
    var workbook = new Workbook();
    // Save workbook as Excel macro enabled workbook into stream
    var workbook = new Workbook();
    var request = WebRequest.CreateHttp("https://path/to/excel/file/upload");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    var workbookContent = new MemoryStream();
    workbook.Save(workbookContent, SaveFileFormat.Xlsm);
    workbookContent.Seek(0, SeekOrigin.Begin);
    request.ContentLength = workbookContent.Length;
    using (var reqStream = request.GetRequestStream())