Rows and columns can be collapsed by setting the hidden flag for the hidden rows/columns and setting the collapsed flag for the row/column that has the collapsed '+' symbol.
xlsxwriter documentation
Let's take a simple example adapted from here :
Create the worksheet
import xlsxwriter
# Create a new workbook and add some worksheets
workbook = xlsxwriter.Workbook('outline_collapsed.xlsx')
worksheet = workbook.add_worksheet('Collapsed Columns')
# Add a general format
bold = workbook.add_format({'bold': 1})
data = [
['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total'],
['North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)'],
['South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)'],
['East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)'],
['West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G5)']]
# Write the data and a formula.
for row, data_row in enumerate(data):
worksheet.write_row(row, 0, data_row)
worksheet.set_row(0, None, bold)

To collapse columns B to G
- Set the hidden flag for columns B-G
- Set the collapsed flag for the column H which will have the collapsed '+' symbol.
# Collapsing
worksheet.set_column('B:G', 5, None, {'level': 1, 'hidden': True})
worksheet.set_column('H:H', 10, None, {'collapsed': True})

