Git Product home page Git Product logo

minxl's Introduction

MinXL - Extending Excel for Mac with C++


Introduction

Excel for Windows has good support for interoperability with C++/C#; unfortunately the same cannot be said about Excel for Mac. MinXL aims to bridge that gap by allowing you to write functions in C++ and call them from VBA with a very intuitive API.

Although not header-only, MinXL is very simple to integrate. If you already have your project set up, just clone the repository into your dependencies folder and add it to your CMakeLists.txt file.



Usage

On C++

#include <MinXL/MinXL.hpp>

// Extern C is not mandatory, but it makes importing functions on VBA much easier
extern "C"
{
    // We recommend receiving data using xl::Variant&
    // Primitive numeric types are ok, but be aware that on the VBA side a 
    // Long has 4 bytes (int32_t) and an Integer has 2 bytes (int16_t).
    xl::Variant IncrementArrayBy(xl::Variant& arg, double value)
    {
        try
        {
            // MinXL will automatically check if this conversion is valid
            xl::Array<xl::Variant> array = std::move(arg);

            // xl::Variant comes with very convenient operator overloads
            for (auto& i : array)
                i += value;

            // Implicitly converts back to xl::Variant
            return std::move(array);
        }
        catch (xl::Exception& e)
        {
            // If the conversion fails, you can return the error message to Excel
            return xl::String{e.what()};
        }
    }
}

On VBA

Private Declare PtrSafe Function IncrementArrayBy _
Lib "/Library/Application Support/Microsoft/libexample.dylib" _
(ByRef v as Variant, ByVal d as Double) As Variant      ' Always pass Variants ByRef

Public Function CallLibFunction(r as Range) as Variant
    CallLibFunction = IncrementArrayBy(r.Value, 2.5)    ' Extract the Range's values first!!!
End Function

On Excel

And not a single copy was performed :D



Contribution, Questions and Feedback

Contributions are welcome! Prefer pull requests and, please, stick to the code style.

This is still an early version and its limitations will be addressed over time.

If you have any trouble using MinXL, feel free to open an issue or message me directly at [email protected].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.