Calc Style Header Properties Fix
AmourSpirit |
PRO |
06/04/23 11:57:48 PM UTC |
0 ⭐ |
2001 👁️ |
Never ⏰ |
[libreoffice, OooDev, LibreOfficeAsk]
# See: https://ask.libreoffice.org/t/macro-calc-in-page-style-shows-attribute-error-class-attributeerror-firstisshared/92209/2
from __future__ import annotations
import uno
from ooodev.office.calc import Calc
from ooodev.utils.gui import GUI
from ooodev.utils.kind.zoom_kind import ZoomKind
from ooodev.utils.lo import Lo
def main() -> int:
with Lo.Loader(connector=Lo.ConnectPipe()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom(doc, ZoomKind.ZOOM_100_PERCENT)
test_header()
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
def test_header(*args):
doc = Lo.XSCRIPTCONTEXT.getDocument()
sheets = doc.Sheets
main_sheet = sheets[0]
# Create new Page Style
pg_styles = doc.StyleFamilies["PageStyles"]
if pg_styles.hasByName("Custom") == False:
page_style = doc.createInstance("com.sun.star.style.PageStyle")
pg_styles.insertByName("Custom", page_style)
# Apply Page Style
main_sheet.PageStyle = "Custom"
# Modify Page Style
custom_pg_style = pg_styles[main_sheet.PageStyle]
custom_pg_style.HeaderOn = True # it works
custom_pg_style.HeaderIsShared = True # it works
# https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1style_1_1PageProperties.html#a7381f863bce3a1e7a0ba3838a2636364
custom_pg_style.FirstPageHeaderIsShared = True
assert custom_pg_style.FirstPageHeaderIsShared == True
if __name__ == "__main__":
SystemExit(main())
Comments
0 B
|👍
/👎