Giter Club home page Giter Club logo

xladd's Introduction

xladd

A library to assist with the development of addins to Excel using the Excel4 and Excel12 APIs.

The Microsoft APIs

The Excel4 API was added to Excel version 4 and is still largely supported in all subsequent versions of Excel that run on the Windows platform. (Sadly, Apple users have to make do with VBA.) In Excel 2007, an additional API was added to give support for spreadsheets with more than 256 columns and strings longer than 254 characters. The API is no longer supported in its entirety: for example, the menu modification functions no longer work. However, Microsoft have signalled strong support for the API moving forward, for example this is the only API that allows multi-threaded async operation for addins.

The API performs essentially two roles. It allows addins to control the behaviour of Excel, doing things like capturing keystrokes and forcibly writing into cells. And it allows addins to register their own functions, which can be called from Excel cells and constructed by the function wizard, just like Excel's intrinsic functions.

The roles of xladd

xladd is a library written entirely in Rust. It is intended to greatly simplify the writing of Excel addins, with the following features:

  • Wrap the functions in the Excel4 and Excel12 APIs so they can be called directly from Rust.

  • Wrap the XLOPER struct that is used for communication with Excel to make it leak safe and to allow read-write access to it from safe Rust code.

  • Use Rust macros to auto-derive the registration code to allow Excel to call functions written in Rust.

  • Support a map-based cache to allow Rust structs to be returned from addin functions, and subsequently passed to other addin functions. XLOPER supports only basic types such as strings, numbers and arrays of strings and numbers, but a cache allows non-trivial data to be keyed by a string or number, which can thus be passed through Excel's own calculation logic.

  • Allow communication between different addins, with a shared cache of structs supporting the 'any' interface.

XLOPER and the low-level API

An XLOPER is a Microsoft-written struct containing discriminated unions, allowing it to represent the contents of an Excel cell or range of cells. It dates from Excel version 4, which predates VBA. In those days, Excel macros were a range of Excel cells, containing numbers representing calls and control flow. The control flow parts of an XLOPER are redundant now, but the struct is still used to represent the following variant types:

  • Number (floating point, integer and date are all internally the same)
  • String (until Excel 97, strings were limited to 254 ASCII characters, and this is one of the differences between the Excel4 and Excel12 APIs)
  • Error
  • Range of cells, each of which can be any of the other types
  • Empty

When you register a function for Excel to invoke, you must specify the parameters of the function. They can be XLOPERs, allowing you to coerce values or reject them with your own error messages, or you can specify a few built-in types such as integers, floating point numbers or strings, in which case Excel does the coercion or rejection for you before invoking your function. The standard in the industry is to always specify XLOPERs, giving more flexibility, but in this library we give you the choice.

xladd's People

Contributors

marcusrainbow avatar

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.