reports: Add BaseODS.set_open_sheet() method.
This commit is contained in:
parent
8d3a0dbe4c
commit
2c61f2b9f2
2 changed files with 33 additions and 0 deletions
|
@ -952,6 +952,21 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
|
|||
self.set_config(config_map, 'VerticalSplitMode', 2, 'short')
|
||||
self.set_config(config_map, 'VerticalSplitPosition', 1, 'short')
|
||||
|
||||
def set_open_sheet(self, sheet: Union[str, odf.table.Table, None]=None) -> None:
|
||||
"""Set which sheet is open in the document
|
||||
|
||||
When the user first opens the spreadsheet, their view will be on this
|
||||
sheet. You can provide a sheet name string or sheet object. With no
|
||||
argument, defaults to ``self.sheet``.
|
||||
"""
|
||||
if sheet is None:
|
||||
sheet = self.sheet
|
||||
if not isinstance(sheet, str):
|
||||
sheet = sheet.getAttribute('name')
|
||||
if not isinstance(sheet, str):
|
||||
raise ValueError("sheet argument has no name for setting")
|
||||
self.set_config(self.view, 'ActiveTable', sheet, 'string')
|
||||
|
||||
def use_sheet(self, name: str) -> odf.table.Table:
|
||||
"""Switch the active sheet ``self.sheet`` to the one with the given name
|
||||
|
||||
|
|
|
@ -479,6 +479,24 @@ def test_ods_lock_first_cells(ods_writer, method_name, split_name, side_name):
|
|||
assert child.getAttribute('type') == ctype
|
||||
assert child.firstChild.data == value
|
||||
|
||||
@pytest.mark.parametrize('arg', [
|
||||
None,
|
||||
'Target Sheet',
|
||||
odf.table.Table(name='Target Sheet'),
|
||||
])
|
||||
def test_ods_set_open_sheet(ods_writer, arg):
|
||||
ods_writer.use_sheet('Start Sheet' if arg else 'Target Sheet')
|
||||
ods_writer.set_open_sheet(arg)
|
||||
view_settings = get_child(
|
||||
ods_writer.document.settings,
|
||||
odf.config.ConfigItemSet,
|
||||
name='ooo:view-settings',
|
||||
)
|
||||
views = get_child(view_settings, odf.config.ConfigItemMapIndexed, name='Views')
|
||||
view1 = get_child(views, odf.config.ConfigItemMapEntry, index=0)
|
||||
actual = get_child(view1, odf.config.ConfigItem, name='ActiveTable')
|
||||
assert actual.text == 'Target Sheet'
|
||||
|
||||
@pytest.mark.parametrize('style_name', XML_NAMES_LIST)
|
||||
def test_ods_writer_add_row(ods_writer, style_name):
|
||||
cell1 = ods_writer.string_cell('one')
|
||||
|
|
Loading…
Reference in a new issue