LibreOffice UNO API: Column Page Breaks Not Resetting, Unlike Row Breaks

I’m using the LibreOffice UNO API with Python to programmatically apply row and column page breaks in a Calc spreadsheet. I’ve encountered a discrepancy in how row and column breaks are handled.

When I apply new row breaks using rows.getByIndex(row_break_id).IsStartOfNewPage = True, existing row breaks are correctly reset or overwritten. However, when I apply column breaks using cols.getByIndex(col_break_id).IsStartOfNewPage = True, while the new breaks are applied, the initial column breaks in the document are not removed.

I’ve attempted to reset the initial column breaks by iterating through the columns and setting IsStartOfNewPage = False:

for i in range(min(cols.getCount(), 100)):
    if cols.getByIndex(i).IsStartOfNewPage:
        print("page break at:", i)
        cols.getByIndex(i).IsStartOfNewPage = False

However, this code doesn’t seem to have any effect. The IsStartOfNewPage property remains True for the initial column breaks, even after executing this loop.

Here’s the code I’m using to apply the row and column breaks:

if row_break_id > 0:
    rows.getByIndex(row_break_id).IsStartOfNewPage = True

if col_break_id > 0:
    cols.getByIndex(col_break_id).IsStartOfNewPage = True
    print("applying col break at:", col_break_id)

Note:
i have tested this on a simple table with 17 columns and 3 rows created on a blank sheet.i can assure that its not a document issue as this issue persist on all the document i tested.
I am using windows 11 and LibreOffice 25.2.1

My Questions:

  1. Why are column breaks behaving differently from row breaks in this context?
  2. How can I reliably reset or remove the initial column breaks using the UNO API?
  3. Are there any LibreOffice settings or document properties that might be interfering with the column break behavior?
  4. Is there any way to force libreoffice to recalculate the page breaks after setting the IsStartOfNewPage to False?
  5. Are there alternative methods to achieve the desired column break behavior using the UNO API or other approaches?

Any insights or solutions would be greatly appreciated.

In LO Calc (as in Excel) there are two different types of column (page) breaks: column breaks set by the user (manual) and those set automatically. The break type can be found out by the (undocumented) column property IsManualPageBreak (see also ManualBreak).
When adding/deleting a manual break, as well as when changing the column width, etc., all automatic breaks are recalculated.
Please upload the problematic file and describe the actions that lead to the problem.

Steps to Reproduce

:one: Starting LibreOffice in Socket Listening Mode

I start LibreOffice with the following command:

C:\Program Files\LibreOffice\program> start soffice -accept=socket,host=localhost,port=2002;urp;

:two: Connecting to LibreOffice and Accessing the Sheet

context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
document = desktop.loadComponentFromURL(ods_file_url, "_blank", 0, ())

sheets = document.getSheets()
sheet = sheets.getByIndex(0)

cols = sheet.getColumns()
rows = sheet.getRows()

:three: Attempting to Remove Existing Column Page Breaks

Before applying new page breaks, I try to reset all existing column breaks:

for i in range(min(cols.getCount(), 100)):  # Prevent index error if cols.getCount() < 100
    if cols.getByIndex(i).IsStartOfNewPage:
        print("Page break at column:", i)
        cols.getByIndex(i).IsStartOfNewPage = False

:four: Verifying If Column Breaks Were Removed

for i in range(min(cols.getCount(), 100)):
    if cols.getByIndex(i).IsStartOfNewPage:
        print("Page break still exists at column:", i)

:bulb: Observation: The Automatic column page breaks remain True, even after explicitly setting them to False but the manual applied column break is reflected. However, the same approach works correctly for row page breaks that is automatic row breaks get recalculated.

Note:
I can assure you that its not a document or OS issue as i have checked on various documents and systems.LibreOffive Version used 25.2.1

test2.ods (11.5 KB)

Thank you for the example and description!
When you delete, for example, the first vertical automatic page break, the page breaks are recalculated for the new layout and preparation of the document for printing. Accordingly, the automatic page break will be set again in the same place.
You can adjust the page breaks by adding and removing manual page breaks. Alternatively, change the column width, print area, scale, print margin size, etc.

1 Like

Thank You so much for the great insights.its working now like u mentioned i have changed print are to force it to recalculate and its working now.

1 Like

maybe com.sun.star.sheet.XSheetPageBreak
as in LibreOffice Developer's Guide: Chapter 8 - Spreadsheet Documents - The Document Foundation Wiki #Page_Breaks

used sheet.removeAllManualPageBreaks() still the same issue.

How to Report Bugs in LibreOffice - The Document Foundation Wiki