|
| 1 | +# https://github.com/jmcnamara/libxlsxwriter/blob/main/examples/panes.c |
| 2 | + |
| 3 | +using LibXLSXWriter: workbook_new, workbook_add_worksheet, workbook_add_format, format_set_align, LXW_ALIGN_CENTER, LXW_ALIGN_VERTICAL_CENTER, format_set_fg_color, format_set_bold, format_set_border, LXW_BORDER_THIN, worksheet_freeze_panes, worksheet_set_column, worksheet_set_row, worksheet_set_selection, worksheet_write_string, worksheet_split_panes, worksheet_write_number, workbook_close |
| 4 | + |
| 5 | +# Create a new workbook and add some worksheets. |
| 6 | +workbook = workbook_new("panes.xlsx") |
| 7 | + |
| 8 | +worksheet1 = workbook_add_worksheet(workbook, "Panes 1") |
| 9 | +worksheet2 = workbook_add_worksheet(workbook, "Panes 2") |
| 10 | +worksheet3 = workbook_add_worksheet(workbook, "Panes 3") |
| 11 | +worksheet4 = workbook_add_worksheet(workbook, "Panes 4") |
| 12 | + |
| 13 | + |
| 14 | +# Set up some formatting and text to highlight the panes. |
| 15 | +header = workbook_add_format(workbook) |
| 16 | +format_set_align(header, LXW_ALIGN_CENTER) |
| 17 | +format_set_align(header, LXW_ALIGN_VERTICAL_CENTER) |
| 18 | +format_set_fg_color(header, 0xD7E4BC) |
| 19 | +format_set_bold(header) |
| 20 | +format_set_border(header, LXW_BORDER_THIN) |
| 21 | + |
| 22 | +center = workbook_add_format(workbook) |
| 23 | +format_set_align(center, LXW_ALIGN_CENTER) |
| 24 | + |
| 25 | + |
| 26 | +## Example 1. Freeze pane on the top row. |
| 27 | + |
| 28 | +worksheet_freeze_panes(worksheet1, 1, 0) |
| 29 | + |
| 30 | +# Some sheet formatting. |
| 31 | +worksheet_set_column(worksheet1, 0, 8, 16, C_NULL) |
| 32 | +worksheet_set_row(worksheet1, 0, 20, C_NULL) |
| 33 | +worksheet_set_selection(worksheet1, 4, 3, 4, 3) |
| 34 | + |
| 35 | +# Some worksheet text to demonstrate scrolling. |
| 36 | +for col in 0:8 |
| 37 | + worksheet_write_string(worksheet1, 0, col, "Scroll down", header) |
| 38 | +end |
| 39 | + |
| 40 | +for row in 1:99, col in 0:8 |
| 41 | + worksheet_write_number(worksheet1, row, col, row + 1, center) |
| 42 | +end |
| 43 | + |
| 44 | +## Example 2. Freeze pane on the left column. |
| 45 | + |
| 46 | +worksheet_freeze_panes(worksheet2, 0, 1) |
| 47 | + |
| 48 | +# Some sheet formatting. |
| 49 | +worksheet_set_column(worksheet2, 0, 0, 16, C_NULL) |
| 50 | +worksheet_set_selection(worksheet2, 4, 3, 4, 3) |
| 51 | + |
| 52 | +# Some worksheet text to demonstrate scrolling. |
| 53 | +for row in 0:49 |
| 54 | + worksheet_write_string(worksheet2, row, 0, "Scroll right", header) |
| 55 | + for col in 1:25 |
| 56 | + worksheet_write_number(worksheet2, row, col, col, center) |
| 57 | + end |
| 58 | +end |
| 59 | + |
| 60 | +## Example 3. Freeze pane on the top row and left column. |
| 61 | + |
| 62 | +worksheet_freeze_panes(worksheet3, 1, 1) |
| 63 | + |
| 64 | + |
| 65 | +# Some sheet formatting. |
| 66 | +worksheet_set_column(worksheet3, 0, 25, 16, C_NULL) |
| 67 | +worksheet_set_row(worksheet3, 0, 20, C_NULL) |
| 68 | +worksheet_write_string(worksheet3, 0, 0, "", header) |
| 69 | +worksheet_set_selection(worksheet3, 4, 3, 4, 3) |
| 70 | + |
| 71 | + |
| 72 | +# Some worksheet text to demonstrate scrolling. |
| 73 | +for col in 1:25 |
| 74 | + worksheet_write_string(worksheet3, 0, col, "Scroll down", header) |
| 75 | +end |
| 76 | + |
| 77 | +for row in 1:49 |
| 78 | + worksheet_write_string(worksheet3, row, 0, "Scroll right", header) |
| 79 | + for col in 1:25 |
| 80 | + worksheet_write_number(worksheet3, row, col, col, center) |
| 81 | + end |
| 82 | +end |
| 83 | + |
| 84 | + |
| 85 | +## Example 4. Split pane on the top row and left column. |
| 86 | +# The divisions must be specified in terms of row and column dimensions. |
| 87 | +# The default row height is 15 and the default column width is 8.43 |
| 88 | + |
| 89 | +worksheet_split_panes(worksheet4, 15, 8.43) |
| 90 | + |
| 91 | +# Some sheet formatting. |
| 92 | +# Some worksheet text to demonstrate scrolling. |
| 93 | +for col in 1:25 |
| 94 | + worksheet_write_string(worksheet4, 0, col, "Scroll", center) |
| 95 | +end |
| 96 | + |
| 97 | +for row in 1:49 |
| 98 | + worksheet_write_string(worksheet4, row, 0, "Scroll", center) |
| 99 | + for col in 1:25 |
| 100 | + worksheet_write_number(worksheet4, row, col, col, center) |
| 101 | + end |
| 102 | +end |
| 103 | + |
| 104 | +workbook_close(workbook) |
0 commit comments