Calc Modify Cell Borders
Overview
Calc has a dialog, as seen in Fig. 417, that sets cell borders for a style. Here we will only look at how to apply borders to a style. For more details refer to Calc Direct Cell Borders that has many examples of setting cell borders directly and the various options.
The ooodev.format.calc.modify.cell.borders.Borders class is used to set the border values.
Fig. 417 Calc dialog style Borders default
Setup
General function used to run these examples:
import uno
from ooodev.format.calc.modify.cell.borders import Borders, Padding, Side, StyleCellKind
from ooodev.office.calc import Calc
from ooodev.utils.color import CommonColor
from ooodev.gui import GUI
from ooodev.loader.lo import Lo
def main() -> int:
with Lo.Loader(Lo.ConnectSocket()):
doc = Calc.create_doc()
GUI.set_visible(True, doc)
Lo.delay(300)
Calc.zoom_value(doc, 130)
borders = Borders(
border_side=Side(color=CommonColor.BLUE),
padding=Padding(all=1.5),
style_name=StyleCellKind.DEFAULT,
)
borders.apply(doc)
style_obj = Borders.from_style(doc, style_name=StyleCellKind.DEFAULT)
assert style_obj is not None
Lo.delay(1_000)
Lo.close_doc(doc)
return 0
if __name__ == "__main__":
SystemExit(main())
Setting Style Borders
borders = Borders(
border_side=Side(color=CommonColor.BLUE),
padding=Padding(all=1.5),
style_name=StyleCellKind.DEFAULT,
)
borders.apply(doc)
Modifying Style Borders as shown in the code above results in the following:
Fig. 418 Calc dialog style Borders modified
Getting Borders from style
style_obj = Borders.from_style(doc, style_name=StyleCellKind.DEFAULT)
assert style_obj is not None