Skip to Content
エクセルのためのPython (Japanese Edition), 2nd Edition
book

エクセルのためのPython (Japanese Edition), 2nd Edition

by Felix Zumstein
May 2026
Intermediate
418 pages
6h 42m
Japanese
O'Reilly Media, Inc.
Content preview from エクセルのためのPython (Japanese Edition), 2nd Edition

第9章 Pythonを活用した Excelツール

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

前章では、Microsoft Excelを自動化するためのPythonスクリプトの書き方を学んだ。これは非常に強力だが、スクリプトを実行するには、ターミナル、VS Code、またはJupyterノートブックのいずれかを快適に扱える必要がある。ビジネスユーザにツールを提供する場合は、そうではない可能性が高い。彼らにとっては、Excelツールが再び通常のマクロ有効ワークブックのように感じられるよう、Pythonの部分を隠しておきたいだろう。 この章では、xlwingsを使ってそれを実現する方法を説明する。まず、ExcelでPythonコードを実行する最も簡単な方法を紹介し、その後、xlwingsツールをデプロイする際の課題について見ていく。これにより、xlwingsが提供する設定についても詳しく確認できる。前章と同様、この章を進めるには、WindowsまたはmacOSにMicrosoft Excelがインストールされている必要がある。

Excelをフロントエンドとして使用する

フロントエンドとは、ユーザーが目にし、やり取りするアプリケーションのな部分のことだ。フロントエンドの他の一般的な呼称には、グラフィカルユーザーインタフェース(GUI)や、単にユーザインタフェース(UI)などがある。xlwingsのユーザに、なぜ最新のWebアプリケーションではなくExcelを選んだのかと尋ねると、答えはたいてい次のようなものだ。「Excelは、ユーザが慣れ親しんだインタフェースだからだ」。 スプレッドシートのセルを利用することで、ユーザは迅速かつ直感的に入力を行えるため、中途半端なWebインタフェースを使用する場合よりも生産性が高くなることが多い。 このセクションでは、xlwingsアドインとxlwings CLI(コマンドラインインタフェース)を紹介した後、quickstartを使って最初のプロジェクトを作成する。最後に、ExcelからPythonコードを呼び出す2つの方法、すなわちアドインの「Run main」ボタンをクリックする方法と、VBARunPython関数を使用する方法を紹介して、このセクションを締めくくる。まずはxlwingsアドインをインストールして始めよう!

xlwings アドイン

でExcelからPythonスクリプトを呼び出すには、Excelアドインをインストールするか、ワークブックをスタンドアロンモードで設定する必要がある。「デプロイ」のセクションでスタンドアロンモードについて紹介するので、このセクションではアドインに焦点を当てる。インストールするには、ターミナルで以下を実行する:

Windows (ターミナル)

cd %userprofile%\python-for-excel-2e
uv run xlwings addin install

macOS (ターミナル)

cd ~/python-for-excel-2e
uv run xlwings addin install

既存の xlwings アドインの再設定

以前のインストールによりExcelにxlwingsアドインが既に存在する場合、第2章で作成したPython環境をアドインが参照するように設定するため、さらに次のコマンドを実行する: uv run xlwings config create ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大規模言語モデル:難しい部分 (Japanese Edition)

大規模言語モデル:難しい部分 (Japanese Edition)

Thársis T. P. Souza, Jonathan K. Regenstein

Publisher Resources

ISBN: 0642572395971