Skip to content

Microsoft Office - Excel

Read and write Microsoft Excel files, and integrate your code with other products from the Microsoft Office suite.

Tip

This plugin doesn't require you to have Microsoft Office or Microsoft Excel installed.

Installation

pip install botcity-excel-plugin

Importing the Plugin

After you installed this package, the next step is to import the package into your code and start using the functions.

from botcity.plugins.excel import BotExcelPlugin

Instantiating the Plugin

To make the example we will instantiate the plugin.

# Instantiate the plugin
bot_excel = BotExcelPlugin()

Manipulating spreadsheet data

Now, let's manipulate some data from our file, adding new data, sorting and writing the result to a new file.

# Read from an Excel File
bot_excel.read('read.xlsx')
# Add a row
bot_excel.add_row([0, 22])
# Sort it by columns A and B in descending order
bot_excel.sort(['A', 'B'], False)

# Print the result
print(bot_excel.as_list())
# Save it to a new file
bot_excel.write('write.xlsx')

Complete code

Let's take a look into the complete code:

from botcity.plugins.excel import BotExcelPlugin

# Instantiate the plugin
bot_excel = BotExcelPlugin()

# Read from an Excel File
bot_excel.read('read.xlsx')
# Add a row
bot_excel.add_row([0, 22])
# Sort it by columns A and B in descending order
bot_excel.sort(['A', 'B'], False)

# Print the result
print(bot_excel.as_list())
# Save it to a new file
bot_excel.write('write.xlsx')

Tip

This plugin allow you to use method chaining so the code above could be written as:

BotExcelPlugin().read('read.xlsx')
    .add_row([0, 22])
    .sort(['A', 'B'], False)
    .write('write.xlsx')