Grouping strings with XlsxWriter

I am writing an Excel file with Python and XlsxWriter in which I would like to group elements at 2 levels. Several “boards” contain items grouped by “list”. I would like to group all the elements of the same “list” and all the elements of the “board” together.

After many attempts, I could not get the following result:

Excel Expected Result Example

Can someone help me understand how the following function works:

worksheet.set_row(1, None, None, {'level': 1})

I followed the example specified in the documentation, but I don’t know what level for each row should be set 2 levels of grouping, working as expected.

+4
source share
1 answer

, .

import xlsxwriter

workbook = xlsxwriter.Workbook('outline.xlsx')
worksheet = workbook.add_worksheet()

worksheet.set_row(1, None, None, {'level': 2})
worksheet.set_row(2, None, None, {'level': 1})
worksheet.set_row(3, None, None, {'level': 2})
worksheet.set_row(4, None, None, {'level': 2})
worksheet.set_row(5, None, None, {'level': 2})
worksheet.set_row(6, None, None, {'level': 1})

worksheet.set_row(8, None, None, {'level': 2})
worksheet.set_row(9, None, None, {'level': 1})

worksheet.set_row(12, None, None, {'level': 2})
worksheet.set_row(13, None, None, {'level': 2})
worksheet.set_row(14, None, None, {'level': 2})
worksheet.set_row(15, None, None, {'level': 2})
worksheet.set_row(16, None, None, {'level': 1})
worksheet.set_row(17, None, None, {'level': 1})
worksheet.set_row(18, None, None, {'level': 2})
worksheet.set_row(19, None, None, {'level': 2})
worksheet.set_row(20, None, None, {'level': 2})
worksheet.set_row(21, None, None, {'level': 1})

workbook.close()

:

enter image description here

, 1, . , 1-6, 8-9 12-21 ( ).

: ​​ 12-23 . .

+1

Source: https://habr.com/ru/post/1693917/


All Articles