diff --git a/conservancy_beancount/reports/core.py b/conservancy_beancount/reports/core.py index 53ca39bec2e40e522899aee786173e1aa37a26a4..a7a80af867f5083dff946a3ace98c2f39bc43477 100644 --- a/conservancy_beancount/reports/core.py +++ b/conservancy_beancount/reports/core.py @@ -920,6 +920,22 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta): ### Sheets + def lock_first_column(self, sheet: Optional[odf.table.Table]=None) -> None: + """Lock the first column of cells under the given sheet + + This method sets all the appropriate settings to "lock" the first column + of cells in a sheet, so it stays in view even as the viewer scrolls + across the sheet. If a sheet is not given, works on ``self.sheet``. + """ + if sheet is None: + sheet = self.sheet + config_map = self.ensure_config_map_entry( + self.view, 'Tables', sheet.getAttribute('name'), + ) + self.set_config(config_map, 'PositionRight', 1, 'int') + self.set_config(config_map, 'HorizontalSplitMode', 2, 'short') + self.set_config(config_map, 'HorizontalSplitPosition', 1, 'short') + def lock_first_row(self, sheet: Optional[odf.table.Table]=None) -> None: """Lock the first row of cells under the given sheet diff --git a/tests/test_reports_spreadsheet.py b/tests/test_reports_spreadsheet.py index 2fd46c770da7506a913e31e8b771a6dcb6e00f63..a34bfde13b6a099d8149b0adb310b081af6f52fc 100644 --- a/tests/test_reports_spreadsheet.py +++ b/tests/test_reports_spreadsheet.py @@ -454,8 +454,12 @@ def test_ods_writer_date_style(ods_writer): assert day.qname[1] == 'day' assert day.getAttribute('style') == 'long' -def test_ods_lock_first_row(ods_writer): - ods_writer.lock_first_row() +@pytest.mark.parametrize('method_name,split_name,side_name', [ + ('lock_first_row', 'Vertical', 'Bottom'), + ('lock_first_column', 'Horizontal', 'Right'), +]) +def test_ods_lock_first_cells(ods_writer, method_name, split_name, side_name): + getattr(ods_writer, method_name)() view_settings = get_child( ods_writer.document.settings, odf.config.ConfigItemSet, @@ -467,9 +471,9 @@ def test_ods_lock_first_row(ods_writer): sheet_name = ods_writer.sheet.getAttribute('name') config_entry = get_child(config_map, odf.config.ConfigItemMapEntry, name=sheet_name) for name, ctype, value in [ - ('PositionBottom', 'int', '1'), - ('VerticalSplitMode', 'short', '2'), - ('VerticalSplitPosition', 'short', '1'), + (f'Position{side_name}', 'int', '1'), + (f'{split_name}SplitMode', 'short', '2'), + (f'{split_name}SplitPosition', 'short', '1'), ]: child = get_child(config_entry, odf.config.ConfigItem, name=name) assert child.getAttribute('type') == ctype