Advertisement
AmourSpirit

Calc Style Header Properties Fix

Jun 4th, 2023
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | Source Code | 0 0
  1. # See: https://ask.libreoffice.org/t/macro-calc-in-page-style-shows-attribute-error-class-attributeerror-firstisshared/92209/2
  2. from __future__ import annotations
  3. import uno
  4. from ooodev.office.calc import Calc
  5. from ooodev.utils.gui import GUI
  6. from ooodev.utils.kind.zoom_kind import ZoomKind
  7. from ooodev.utils.lo import Lo
  8.  
  9.  
  10. def main() -> int:
  11.     with Lo.Loader(connector=Lo.ConnectPipe()):
  12.         doc = Calc.create_doc()
  13.         GUI.set_visible(True, doc)
  14.         Lo.delay(500)
  15.         Calc.zoom(doc, ZoomKind.ZOOM_100_PERCENT)
  16.  
  17.         test_header()
  18.         Lo.delay(1_000)
  19.         Lo.close_doc(doc)
  20.     return 0
  21.  
  22.  
  23. def test_header(*args):
  24.     doc = Lo.XSCRIPTCONTEXT.getDocument()
  25.     sheets = doc.Sheets
  26.     main_sheet = sheets[0]
  27.  
  28.     # Create new Page Style
  29.     pg_styles = doc.StyleFamilies["PageStyles"]
  30.     if pg_styles.hasByName("Custom") == False:
  31.         page_style = doc.createInstance("com.sun.star.style.PageStyle")
  32.         pg_styles.insertByName("Custom", page_style)
  33.  
  34.     # Apply Page Style
  35.     main_sheet.PageStyle = "Custom"
  36.  
  37.     # Modify Page Style
  38.     custom_pg_style = pg_styles[main_sheet.PageStyle]
  39.     custom_pg_style.HeaderOn = True  # it works
  40.     custom_pg_style.HeaderIsShared = True  # it works
  41.  
  42.     # https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1style_1_1PageProperties.html#a7381f863bce3a1e7a0ba3838a2636364
  43.     custom_pg_style.FirstPageHeaderIsShared = True
  44.     assert custom_pg_style.FirstPageHeaderIsShared == True
  45.  
  46.  
  47. if __name__ == "__main__":
  48.     SystemExit(main())
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement