{"id":175,"date":"2016-04-05T08:46:08","date_gmt":"2016-04-05T08:46:08","guid":{"rendered":"https:\/\/www.pyxll.com\/blog\/?p=175"},"modified":"2023-01-05T10:05:22","modified_gmt":"2023-01-05T10:05:22","slug":"introducing-pyxll-3","status":"publish","type":"post","link":"https:\/\/www.pyxll.com\/blog\/introducing-pyxll-3\/","title":{"rendered":"Introducing PyXLL 3"},"content":{"rendered":"<p>Since the beginning, PyXLL development\u00a0focused on the things that really matter for creating useful real-world spreadsheets; worksheet functions and macro functions. Without these all you can do is just drive Excel by poking numbers in and reading numbers out. At the time the first version of PyXLL was released, that was already possibly using COM, and so providing yet another API to do the same was seen as little value add. On the other hand, being able to write functions and macros in Python opens up possibilities that previously were only available in VBA or writing complicated Excel Addins in C++ or C#.<\/p>\n<p>With the release of PyXLL 3 integrating your Python code into Excel has become more enjoyable than ever. Many things have been simplified to get you up and running faster, and there are some major new features to explore.<\/p>\n<p>If you are new to PyXLL have a look at the\u00a0<a href=\"https:\/\/www.pyxll.com\/docs\/introduction.html\" target=\"_blank\" rel=\"noopener noreferrer\">Getting Started<\/a>\u00a0section of the documentation.<\/p>\n<p>All the features of PyXLL, including these new ones, can be found in the\u00a0<a href=\"https:\/\/www.pyxll.com\/docs\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">Documentation<\/a><\/p>\n<h2>Customising the Ribbon<\/h2>\n<p><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12.png\" rel=\"attachment wp-att-179\"><img decoding=\"async\" data-attachment-id=\"179\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/introducing-pyxll-3\/screen-shot-2016-02-29-at-15-57-12\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12.png\" data-orig-size=\"475,151\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screen Shot 2016-02-29 at 15.57.12\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12-300x95.png\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12.png\" class=\"alignnone size-full wp-image-179\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12.png\" alt=\"Screen Shot 2016-02-29 at 15.57.12\" width=\"475\" height=\"151\" srcset=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12.png 475w, https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/Screen-Shot-2016-02-29-at-15.57.12-300x95.png 300w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/a><\/p>\n<p>Ever wanted to write an addin that uses the Excel ribbon interface? Previously the only way to do\u00a0this was to write a COM addin, which requires a lot of knowledge, skill and perseverance! Now\u00a0you can do it with PyXLL by defining your ribbon as an XML document and adding it to your PyXLL\u00a0config. All the callbacks between Excel and your Python code are handled for you.<\/p>\n<p>See the\u00a0<a href=\"https:\/\/www.pyxll.com\/docs\/userguide\/ribbon.html\" target=\"_blank\" rel=\"noopener noreferrer\">Customising the Ribbon<\/a>\u00a0for more detailed information or try the example included in the download.<\/p>\n<p>&nbsp;<\/p>\n<h2>RTD (Real Time Data) Functions<\/h2>\n<p><a href=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/rtd.gif\" rel=\"attachment wp-att-183\"><img decoding=\"async\" data-attachment-id=\"183\" data-permalink=\"https:\/\/www.pyxll.com\/blog\/introducing-pyxll-3\/rtd\/\" data-orig-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/rtd.gif\" data-orig-size=\"610,389\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"rtd\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/rtd.gif\" data-large-file=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/rtd.gif\" class=\"alignnone size-full wp-image-183\" src=\"https:\/\/www.pyxll.com\/blog\/wp-content\/uploads\/2016\/02\/rtd.gif\" alt=\"rtd\" width=\"610\" height=\"389\" \/><\/a><\/p>\n<p>PyXLL can stream live data into your spreadsheet without you having to write any extra services\u00a0or register any COM controls. Any Python function exposed to Excel through PyXLL can return a\u00a0new RTD type that acts as a ticking data source; Excel updates whenever the returned\u00a0RTD publishes new data.<\/p>\n<p>See <a href=\"https:\/\/www.pyxll.com\/docs\/userguide\/rtd.html\" target=\"_blank\" rel=\"noopener noreferrer\">Real Time Data<\/a>\u00a0for more detailed information or try the example included in the download.<\/p>\n<h2>Function Signatures and Type Annotation<\/h2>\n<p>xl_func\u00a0and xl_macro need to know the argument and return types to be<br \/>\nable to tell Excel how they should be called. In previous versions that was always done by\u00a0passing a &#8216;signature&#8217; string to these decorators.<\/p>\n<p>Now in PyXLL 3 the signature is entirely optional. If a signature is not supplied PyXLL will inspect\u00a0the function and determine the signature for you.<\/p>\n<p>If you use Python type annotations when declaring the function, PyXLL will use those when determining\u00a0the function signature. Otherwise all arguments and the return type will be assumed to be <code>var<\/code>.<\/p>\n<h2>Default Keyword Arguments<\/h2>\n<p>Python functions with default keyword arguments now preserve their default value when called from<br \/>\nExcel with missing arguments. This means that a function like the one below<br \/>\nwhen called from Excel with b or c missing will be invoked with the correct default values for b and c.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n@xl_func\r\ndef func_with_kwargs(a, b=1, c=2):\r\n    return a + b + c\r\n<\/pre>\n<h2>Easier Setup for Anaconda and Virtualenvs<\/h2>\n<p>Many problems with installing PyXLL come down to the fact that Python isn&#8217;t installed as the default\u00a0Python installation on the PC. This means that PyXLL can&#8217;t find the Python dll or the Python packages<br \/>\nas their locations are not set globally.<\/p>\n<p>This affects any distribution that doesn&#8217;t set itself up as the\u00a0default Python install (most notably Anaconda, PortablePython and any virtualenv).<\/p>\n<p>There were ways to get around this and make it work, but it always should have been easier. Now it is!<\/p>\n<p>To set which Python to use with PyXLL now all you have to do is set it up in your pyxll.cfg file<\/p>\n<pre>[PYTHON]\nexecutable = &lt;your python.exe&gt;<\/pre>\n<p>When this is set PyXLL will try to find the right Python DLL to load and try to locate where the\u00a0Python libraries are installed. If it still can&#8217;t find either of those you can tell it by setting\u00a0dll and\/or pythonhome in the same section of the config.<\/p>\n<h2>Deep Reloading<\/h2>\n<p>If you&#8217;ve used PyXLL for a while you will have noticed that when you reload PyXLL only the modules\u00a0listed in your pyxll.cfg file get reloaded. If you are working on a project that has multiple modules\u00a0and not all of them are added to the config those won&#8217;t get reloaded, even if modules that are listed\u00a0in the config file import them.<\/p>\n<p>PyXLL can now track all the imports made by each module listed in the config file, and when you\u00a0reload PyXLL all of those modules will be reloaded in the right order.<\/p>\n<p>This feature is enabled in the config file by setting<\/p>\n<pre>[PYXLL]\ndeep_reload = 1<\/pre>\n<h2>Error Caching<\/h2>\n<p>Sometimes it&#8217;s not convenient to have to pick through the log file to determine why a particular\u00a0cell is failing to calculate.<\/p>\n<p>The new function get_last_error takes an XLCell or a COM Range and\u00a0returns the last exception (and traceback) to have occurred in that cell.<\/p>\n<p>This can be used in menu functions or other worksheet functions to give end users better feedback\u00a0about any errors in the worksheet.<\/p>\n<h2>Python Functions for Reload and Rebind<\/h2>\n<p>PyXLL can now be reloaded or it can rebind its Excel functions using the new Python functions reload\u00a0and rebind.<\/p>\n<h2>Better win32com and comtypes Support<\/h2>\n<p>PyXLL has always had some integration with the pythoncom module, but it required some user code to make it\u00a0really useful. It didn&#8217;t have any direct integration with the higher level win32com package or the<br \/>\ncomtypes package.<\/p>\n<p>The new function xl_app returns the current Excel Application instance either as a pythoncom\u00a0PyIDispatch instance, a win32com.client.Dispatch instance or a wrapped comtypes POINTER(IUnknown) instance.<\/p>\n<p>You may specify which COM library you want to use with PyXLL in the pyxll.cfg file<\/p>\n<pre>[PYXLL]\ncom_package = &lt;win32com, comtypes or pythoncom&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Since PyXLL was first released back in 2010 it has grown hugely in popularity and is used by businesses in many different sectors.<\/p>\n<p>The original motivation for PyXLL was to be able to use all the best bits of Excel combined with a modern programming language for scientific computing, in a way that fits naturally and works seamlessly.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-pyxll"],"acf":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7l3LP-2P","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/comments?post=175"}],"version-history":[{"count":3,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions"}],"predecessor-version":[{"id":1675,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions\/1675"}],"wp:attachment":[{"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pyxll.com\/blog\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}