拡張機能

xlwingsアドインを拡張し、UDFやRunPythonマクロのようなコードを簡単に自分で追加することができます。そして、拡張したアドインを配布すれば、エンドユーザーはUDFのインポートや自分で関数を書くことなく使えるようになります。アドインの拡張は、追加的なコードをVBAモジュールに記述しxlwingsアドインに追加するだけでできます。

UDFの拡張機能はVBAの参照設定をすることなく全てのワークブックで使えるようになります。

Excel用SQL

xlwingsアドインには、拡張機能Excel用SQLシンタックス(sqlite dialect)が組み込まれています:

=sql(SQL Statement, [alias a], table a, [alias b], table b, ...)
_images/sql.png

If there are no aliases provided, tables are aliased automatically as a, b, c, etc. as the screenshot shows. Since v0.33.5 you can, however, provide your own alias/table name like so:

=sql(
    "SELECT customers.name, o.product, o.amount
    FROM customers
    INNER JOIN b ON customers.customer_id = o.customer_id",
    "customers", A1:D4,
    "o", Orders[#All]
)

This is, you need to provide the table name/alias first before providing the range reference as the next argument, similar to how the =LET formula works in Excel.

As this extension uses UDFs, it's only available on Windows right now. This formula can be used on macOS and Excel on the web though via xlwings Server.