{"id":2242,"date":"2026-08-12T15:41:36","date_gmt":"2026-08-12T07:41:36","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=2242"},"modified":"2026-03-28T11:47:26","modified_gmt":"2026-03-28T11:47:26","slug":"how-to-use-workbookadd-in-the-xlwings-api-way","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-use-workbookadd-in-the-xlwings-api-way\/","title":{"rendered":"How to use Workbook.Add in the xlwings API way"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <strong>Add<\/strong> member of the <strong>Workbook<\/strong> object in the Excel object model is a method used to create a new workbook. In xlwings, which provides a powerful API to interact with Excel from Python, this functionality is accessed through the <code>App<\/code> class rather than directly from a Workbook instance. The <code>App<\/code> represents the Excel application itself, and its <code>add()<\/code> method creates a new workbook, returning a <code>Book<\/code> object (xlwings&#8217; equivalent to a Workbook). This is essential for automating the generation of reports, dashboards, or any task requiring dynamic workbook creation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Functionality:<\/strong><br>The primary function is to launch a new, blank workbook in Excel. This new workbook becomes the active workbook and is added to the <code>App.books<\/code> collection. It provides a foundation for subsequent operations like adding data, creating charts, or applying formatting without needing a pre-existing file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax and Parameters:<\/strong><br>In xlwings, the method is called on an <code>App<\/code> instance. The basic syntax is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new_workbook = xw.App().add()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, it is more common to use an existing application context. When you have an <code>App<\/code> object (e.g., <code>app = xw.App()<\/code> or when using <code>xw.Book<\/code> which creates an app implicitly), you call:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new_workbook = app.add()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>add()<\/code> method does not take any parameters in xlwings. Its behavior is straightforward: it creates one new, empty workbook. This differs slightly from the native Excel VBA object model, where the <code>Add<\/code> method can accept a template parameter. In xlwings, to create a workbook from a template, you would typically use the <code>Book<\/code> constructor with a file path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Examples:<\/strong><br>Here are practical examples demonstrating the <code>add()<\/code> method.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Creating a new workbook in a new Excel instance:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Start a new Excel application\napp = xw.App()\n# Add a new, blank workbook\nnew_book = app.add()\n# Write data to the first cell of the active sheet\nnew_book.sheets&#91;0].range('A1').value = \"New Workbook Data\"\n# Save the workbook\nnew_book.save(r'C:\\Reports\\Report1.xlsx')\n# Close the workbook and quit Excel\nnew_book.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Adding multiple workbooks to an existing application instance:<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\n# Connect to a running instance or start a new one\napp = xw.App(visible=True)\n# Create the first new workbook\nbook1 = app.add()\nbook1.sheets&#91;0].range('A1').value = \"Workbook 1\"\n# Create a second new workbook\nbook2 = app.add()\nbook2.sheets&#91;0].range('A1').value = \"Workbook 2\"\n# At this point, two new workbooks are open in the same Excel application.\n# ... perform other tasks ...\nfor book in app.books:\nbook.close()\napp.quit()<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Using within a context manager (recommended for resource management):<\/strong><\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>import xlwings as xw\n\nwith xw.App() as app:\n# The `add()` method works the same within the context\nnew_book = app.add()\nnew_book.sheets&#91;0].range('A1').value = \"Created in Context\"\nnew_book.save('context_workbook.xlsx')\n# The context manager automatically closes the book and quits the app on exit.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The **Add** member of the **Workbook** object in the Excel object model is a method used to create a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-2242","post","type-post","status-publish","format-standard","hentry","category-xlwings-api-reference"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=2242"}],"version-history":[{"count":1,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2242\/revisions"}],"predecessor-version":[{"id":3425,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/2242\/revisions\/3425"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=2242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=2242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=2242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}