Calc Modify Page Style
Overview
Allows you to define page layouts for single and multiple-page documents, as well as a numbering and paper formats.
The ooodev.format.calc.modify.page.page.PaperFormat
, ooodev.format.calc.modify.page.page.Margins
, and ooodev.format.calc.modify.page.page.LayoutSettings
classes are used to modify the page style values seen in Fig. 433.
Default Page Style Dialog
Setup
General function used to run these examples.
import uno
from ooodev.office.calc import Calc
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
from ooodev.format.calc.modify.page.page import PaperFormat, PaperFormatKind, CalcStylePageKind
def main() -> int:
with Lo.Loader(connector=Lo.ConnectSocket()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(500)
Calc.zoom_value(doc, 100)
style = PaperFormat.from_preset(
preset=PaperFormatKind.A3, landscape=False, style_name=CalcStylePageKind.DEFAULT
)
style.apply(doc)
style_obj = PaperFormat.from_style(doc=doc, style_name=CalcStylePageKind.DEFAULT)
assert style_obj.prop_style_name == str(CalcStylePageKind.DEFAULT)
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Paper Format
Select from a list of predefined paper sizes, or define a custom paper format.
Setting Paper Format
A preset can be used to set the paper format via PaperFormatKind
class.
From a preset
from ooodev.format.calc.modify.page.page import PaperFormat, PaperFormatKind, CalcStylePageKind
# ... other code
style = PaperFormat.from_preset(
preset=PaperFormatKind.A3, landscape=False, style_name=CalcStylePageKind.DEFAULT
)
style.apply(doc)
Style results of preset can be seen in Fig. 434.
Using SizeMM
Custom size can be set using SizeMM
class.
If the height is greater than the width, the page will be set to portrait mode; Otherwise, it will be set to landscape mode.
from ooodev.format.calc.modify.page.page import PaperFormat, CalcStylePageKind
from ooodev.format.calc.modify.page.page import SizeMM
# ... other code
style = PaperFormat(
size=SizeMM(width=200.0, height=100.0),
style_name=CalcStylePageKind.DEFAULT,
)
style.apply(doc)
Style results can be seen in Fig. 435.
Set size in other units
The SizeMM
class can also take other units as parameters.
Any unit that supports Class UnitT can used to set the size.
Setting the size using inches.
In this example the size is set to 8.5
inches by 14
inches.
from ooodev.format.calc.modify.page.page import PaperFormat, CalcStylePageKind
from ooodev.format.calc.modify.page.page import SizeMM
from ooodev.units import UnitInch
# ... other code
style = PaperFormat(
size=SizeMM(width=UnitInch(8.5), height=UnitInch(14)),
style_name=CalcStylePageKind.DEFAULT,
)
style.apply(doc)
Style results can be seen in Fig. 436.
Getting Paper Format from a style
# ... other code
style_obj = PaperFormat.from_style(doc=doc, style_name=CalcStylePageKind.DEFAULT)
assert style_obj.prop_style_name == str(CalcStylePageKind.DEFAULT)
Margins
Specify the amount of space to leave between the edges of the page and the document text.
Setting Margins
Set margins in millimeters
The default margin values are in millimeters.
from ooodev.format.calc.modify.page.page import Margins, CalcStylePageKind
# ... other code
style = Margins(left=10, right=10, top=18, bottom=18, style_name=CalcStylePageKind.DEFAULT)
style.apply(doc)
Style results.
Set margins in other units
The margins can also take other units as parameters. Any unit that supports Class UnitT can used to set the margin value.
In the following example the margins are set to 1
inch on the left and right, 1.2
inches on the top, and 0.75
inches on the bottom.
from ooodev.format.calc.modify.page.page import Margins, CalcStylePageKind
from ooodev.units import UnitInch
# ... other code
style = Margins(
left=UnitInch(1.0),
right=UnitInch(1.0),
top=UnitInch(1.2),
bottom=UnitInch(0.75),
style_name=CalcStylePageKind.DEFAULT,
)
style.apply(doc)
Style results.
Getting Margins from a style
# ... other code
style_obj = Margins.from_style(doc=doc, style_name=CalcStylePageKind.DEFAULT)
assert style_obj.prop_style_name == str(CalcStylePageKind.DEFAULT)
Layout Settings
Setting Layout
from ooodev.format.calc.modify.page.page import LayoutSettings, PageStyleLayout
from ooodev.format.calc.modify.page.page import NumberingTypeEnum, CalcStylePageKind
# ... other code
style = LayoutSettings(
layout=PageStyleLayout.MIRRORED,
numbers=NumberingTypeEnum.CHARS_UPPER_LETTER,
align_hori=True,
align_vert=True,
)
style.apply(doc)
Style results.
Getting Layout Settings from a style
We can get the border shadow from the document.
# ... other code
style_obj = LayoutSettings.from_style(doc=doc, style_name=CalcStylePageKind.DEFAULT)
assert style_obj.prop_style_name == str(CalcStylePageKind.DEFAULT)