{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-guides/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["img"]},"type":"markdown"},"seo":{"title":"Working with Excel","description":"Accelerate E&P application development and protect your innovation by consuming our Data and Domain APIs / Platform APIs.","lang":"en-US","meta":[{"name":"robots","content":"noindex"}],"llmstxt":{"hide":true,"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"className":"body","role":"main"},"children":[{"$$mdtype":"Tag","name":"div","attributes":{"id":"working-with-excel","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"working-with-excel","__idx":0},"children":["Working with Excel"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Python has many libraries for working with Excel. Pipesim Python Toolkit uses"," ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"http://xlwings.org","className":"reference external"},"children":["xlwings"]}," that makes reading and writing Escel worksheet easy. Scripts can read and write data, format sheets,"," ","and be assigned to VBA features such as buttons."]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"interacting-with-excel","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"interacting-with-excel","__idx":1},"children":["Interacting with Excel"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Reading and writing Excel ranges is done through the xlwings Python module,"," ","often abbreviated to xw. The following examples are provided for information"," ","with many more methods and features available in xlwings. See the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"http://docs.xlwings.org/en/stable/quickstart.html","className":"reference external"},"children":["xlwings documentation"]}," ","for more help."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Reading and writing tabulated data formats are subject to the following considerations:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pandas DataFrames can be written to Excel."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Lists of lists or dictionaries cannot be written to Excel (as of xlwings 0.17.1)."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To read tabulated data formats from Excel you must use the utility functions"," ","provided in the Pipesim Python Toolkit (see section below) for converting the"," ","lists of lists into DataFrames and dictionaries."]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Pipesim Python Toolkit allows scripts to be called from"," ","workbooks, but any script can interact with Excel workbooks. The interactive"," ","Python command line is typically the easiest way to try out code."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Open a new workbook:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> import xlwings as xw\n    >>> app = xw.App()\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Current workbook and worksheet:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> bk = xw.books.active\n    >>> sht = bk.sheets.active\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Activate a worksheet:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> bk.sheets('Sheet1').activate()\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Writing to a cell:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> xw.Range('A1').value = 'Hello world'\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Reading from a cell:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> value = xw.Range('A1').value\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Writing a DataFrame to a cell"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> xw.Range('B4').value = geometry_df\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Reading a range and converting to DataFrame"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    #Automatically determine the table from the top left cell\n    values = xw.Range('B4').expand().value\n    #Or specify the top left and bottom right cells\n    values = xw.Range('B4', 'G7').value\n    from sixgill.utilities import range_to_dataframe\n    df = range_to_dataframe(values)\n"},"children":[]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"call-python-scripts-from-excel","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"call-python-scripts-from-excel","__idx":2},"children":["Call Python Scripts from Excel"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can call Python scripts from Excel workbooks and assign python methods to"," ","VBA features like a button."]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"client-server-architecture","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"client-server-architecture","__idx":3},"children":["Client-server architecture"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The new way of communication between Excel and Python Toolkit based on client-server"," ","architecture and includes at least 4 elements:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Excel document: user interface or data store during data exchange with Pipesim model."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Logic.py: script implements logic of data exchange with Pipesim model."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Server.py: sever script. Listen port and process message from it."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Client.py: client script. Connect to server and send message (command)."]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Excel document calls logic.py script to connect with Python Toolkit and sends command to server using"," ","client.py script by user request."," ","Logic.py runs server.py script and processes client requests."]},{"$$mdtype":"Tag","name":"Image","attributes":{"src":"/assets/client_server.61d1c0495d86c694020e68c179aebdf9dcf5552de0e01fb38525a0e93e526f78.ffb4f23a.png","alt":"_images/Client_server.png","withLightbox":true,"width":"","height":""},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Client and server uses any available port which is identified automatically."," ","By default, all scripts must be placed in one folder with Excel document."," ","They also may be stored in separate folder _CommonScripts one level up (see"," ","folders structure in Case Studies)"]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"excel-document","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"excel-document","__idx":4},"children":["Excel document"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Excel document includes several VBA functions in module ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Module_Functions"]}," which allow to"," ","establish connection with Python script and send command:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ExecuteServerScript: connects to python script. Run logic script which starts server."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ExecuteCommand: send command to python script."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["PopulatePythonDirectory: receive paths of existing python installation and fill python folder dropdown list."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Other python directory related functions"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["User must select Pipesim PTK path in dropdown list to execute script correctly. All functions use named ranges"," ","for navigation."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Excel document must contain at least 2 sheets:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Introduction: sheet contains named ranges"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["PortNumber: port number"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["InstalledPython: list of python installations"]}]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Model: sheet contains named ranges"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["PythonFolder: drop down list of python installations"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ModelFolder: place of store Pipesim model and python scripts (logis.py, server.py, client.py)"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ModelFile: name of Pipesim model"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Excel document must contain at least 2 form controls (button):"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Connect with python script"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Command"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Since Python Toolkit may be installed in any folder, the python installation path may be different."," ","When Excel document is transferred between computers, the python installation path must be updated"," ","accordingly. To simplify path selection/update, the automatic process is implemented in the"," ","Workbook_Open() method of ThisWorkbook object."]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"call-python-script-from-excel","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"call-python-script-from-excel","__idx":5},"children":["Call python script from Excel"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Execute following steps to create a link between Excel and python script"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use Excel Template from Case StudiesPython Toolkit"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add new button in Excel and assign new function to it"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use following VBA code sending command Function_1 to script"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add your code in logic.py script as a my_code() method"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Edit handlerMessage method in logic.py script"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Rename message get_test to function_1"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Replace get_test() method to my_code()"]}]}]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    def handleMessage(message):\n        if message == 'get_info':\n            get_info()\n            print(\"\")\n            print('Information received')\n            return True\n\n        elif message == 'get_test':\n            get_test()\n            print(\"\")\n            print('Test finished')\n            return True\n\n        return False\n"},"children":[]}]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"utility-functions","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"utility-functions","__idx":6},"children":["Utility Functions"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Pipesim Python Toolkit includes utility functions for working with Excel."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":""},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Method"]}]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":""},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["Description"]}]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["active_sheet()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Return the currently active Excel worksheet"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["current_folder()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Return the folder (path) to the currently open Excel workbook."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["get_model_session()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Get the model associated with the workbook, opening it if necessary"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["range_to_dataframe()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Convert an Excel range to a Pandas DataFrame"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["range_to_dictionary()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Convert an Excel range to a dictionary"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["worksheet_last_row()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Return the last row of the worksheet"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["worksheet_last_column()"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Return the last column of the worksheet"]}]}]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"returning-the-currently-active-excel-worksheet","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"returning-the-currently-active-excel-worksheet","__idx":7},"children":["Returning the currently active Excel worksheet"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To return the currently active sheet object, follow this example:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> from sixgill.utilities import active_sheet\n    >>> sht = active_sheet()\n"},"children":[]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"returning-the-excel-workbook-folder","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"returning-the-excel-workbook-folder","__idx":8},"children":["Returning the Excel workbook folder"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Python variable __file__ returns the script location, but this is not"," ","the same as the Excel workbook folder. The current_folder()"," ","method returns the folder of the Excel workbook."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> from sixgill.utilities import current_folder()\n    >>> workbook_folder = current_folder()\n"},"children":[]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"get-the-model-associated-with-the-workbook","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get-the-model-associated-with-the-workbook","__idx":9},"children":["Get the model associated with the workbook"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Where spreadsheets have several functions that operate on models, the"," ","get_model_session() method can handle connections to the required models."," ","It will open the model, if necessary, or simply pass back the"," ","model object if it is already open."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In the following example, a user can"," ","run readparameters(), writeparameters() and savemodel() and the opening"," ","of the model is handled automatically:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    from sixgill.utilities import get_active_session\n    model_filename = 'C:/temp/mymodel.pips'\n\n    def readparameters():\n        model = get_model_session(model_filename)\n        print(model.get_values(\"Well\"))\n\n    def writeparameters():\n        model = get_model_session(model_filename)\n        new_param = range_to_dictionary(xw.Range('B4').expand().value)\n        model.set_values(new_param)\n\n    def savemodel():\n        model = get_model_session(model_filename)\n        model.save()\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Further examples for get_model_session() can be found in the Pipesim"," ","Python Toolkit Case Studies."]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"convert-an-excel-range-to-a-pandas-dataframe","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"convert-an-excel-range-to-a-pandas-dataframe","__idx":10},"children":["Convert an Excel range to a Pandas DataFrame"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use this for passing Pipesim tabulated data such as"," ","trajectories, geometries, and such."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To convert the list of lists read in from an Excel range into a Pandas"," ","DataFrame, follow this example:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> from sixgill.utilities import range_to_dataframe\n    >>> geometry = xw.Range('B4').expand().value\n    >>> df = range_to_dataframe(geometry)\n"},"children":[]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"convert-an-excel-range-to-a-dictionary","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"convert-an-excel-range-to-a-dictionary","__idx":11},"children":["Convert an Excel range to a dictionary"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Use this for handling tabulated data such a boundary conditions."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To convert the list of lists read in from an Excel range into a Python"," ","dictionary, follow this example:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> from sixgill.utilities import range_to_dictionary\n    >>> bc = xw.Range('B4').expand().value\n    >>> df = range_to_dictionary(bc)\n"},"children":[]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"id":"get-the-address-of-the-last-cell-of-the-worksheet","className":"section"},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get-the-address-of-the-last-cell-of-the-worksheet","__idx":12},"children":["Get the address of the last cell of the worksheet"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The worksheet_last_row() returns the last row with data in it. Likewise,"," ","worksheet_last_column() returns the last column with data."]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> from sixgill.utilities import worksheet_last_row, worksheet_last_column\n    >>> last_row = worksheet_last_row()\n    >>> last_column = worksheet_last_column()\n"},"children":[]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["They optionally take a specified worksheet name:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"doctest highlight-default notranslate"},"children":[{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"    >>> last_row = worksheet_last_row(\"ModelData\")\n    >>> last_column = worksheet_last_column(\"ModelData\")\n"},"children":[]}]}]}]}]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"clearer"},"children":[]}]}]},"headings":[{"value":"Working with Excel","id":"working-with-excel","depth":1},{"value":"Interacting with Excel","id":"interacting-with-excel","depth":2},{"value":"Call Python Scripts from Excel","id":"call-python-scripts-from-excel","depth":2},{"value":"Client-server architecture","id":"client-server-architecture","depth":3},{"value":"Excel document","id":"excel-document","depth":3},{"value":"Call python script from Excel","id":"call-python-script-from-excel","depth":3},{"value":"Utility Functions","id":"utility-functions","depth":2},{"value":"Returning the currently active Excel worksheet","id":"returning-the-currently-active-excel-worksheet","depth":3},{"value":"Returning the Excel workbook folder","id":"returning-the-excel-workbook-folder","depth":3},{"value":"Get the model associated with the workbook","id":"get-the-model-associated-with-the-workbook","depth":3},{"value":"Convert an Excel range to a Pandas DataFrame","id":"convert-an-excel-range-to-a-pandas-dataframe","depth":3},{"value":"Convert an Excel range to a dictionary","id":"convert-an-excel-range-to-a-dictionary","depth":3},{"value":"Get the address of the last cell of the worksheet","id":"get-the-address-of-the-last-cell-of-the-worksheet","depth":3}],"frontmatter":{"seo":{"title":"Working with Excel"}},"lastModified":"2025-06-16T17:01:43.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/solutions/pipesim/excel","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}