masaccio / numbers-parser

Python module for parsing Apple Numbers .numbers files
MIT License
201 stars 14 forks source link

set_cell_border errors #84

Closed GerdHoeren closed 2 weeks ago

GerdHoeren commented 3 weeks ago

Describe the bug Can't get table.set_cell_border() to work.

To Reproduce The examples on your documentation page have mismatched parenthesis. https://masaccio.github.io/numbers-parser/api/border.html

With parens fixed: border_style = Border(8.0, RGB(29, 177, 0)) table2.set_cell_border("A1", "right", border_style, "dashes")

Errors out with: File "/Users/gerd/Documents/Arduino/Scripts/Python Scripts/ParseGlobals/Spreadsheet.py", line 165, in WriteSpreadsheetTab table2.set_cell_border("A1", "right", border_style, "dashes") File "/Users/gerd/Documents/Arduino/Scripts/Python Scripts/ParseGlobals/.venv/lib/python3.9/site-packages/numbers_parser/document.py", line 1090, in set_cell_border raise TypeError("border length must be an int") TypeError: border length must be an int

The second example: border_style = Border(8.0, RGB(29, 177, 0)) table2.set_cell_border(0, 0, "left", border_style, "solid", 3)

Errors out with: File "/Users/gerd/Documents/Arduino/Scripts/Python Scripts/ParseGlobals/Spreadsheet.py", line 164, in WriteSpreadsheetTab table2.set_cell_border(0, 0, "left", border_style, "solid", 3) File "/Users/gerd/Documents/Arduino/Scripts/Python Scripts/ParseGlobals/.venv/lib/python3.9/site-packages/numbers_parser/document.py", line 1084, in set_cell_border raise TypeError("invalid number of arguments to border_value()") TypeError: invalid number of arguments to border_value()

Expected behavior 1) Is there an issue with set_cell_border() or am I calling it incorrectly? 2) Please update the examples, so that they run as expected.

Attachments If you can, upload the Numbers spreadsheet or a simple reproducer that triggers the bug.

Additional information

python -m pip list . . . numbers-parser 4.10.5

Add any other context about the problem here. I'd like to remove cell borders.

masaccio commented 3 weeks ago

The line type is part of the Border constructor:

border_style = Border(8.0, RGB(29, 177, 0), "solid")
table.set_cell_border(0, 0, "left", border_style, 3)

Docs are indeed incorrect in the Border class. The Table API docs are right: https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_border.

I'll update the error when I fix your other issues.

masaccio commented 3 weeks ago

Docs published

GerdHoeren commented 3 weeks ago

Thank you for the update. The cell border calls now run, but unexpectedly affect all tables in the sheet.

The attached image shows a sheet with three tables (table0, table1 and table2). "table2" is the date field at the top-right of the image. Notice that the following code has changed the border style of cell 0,0 in all three tables. table2.set_cell_border(0, 0, ["top", "right", "bottom", "left"], Border(5.0, RGB(29, 177, 0), "solid"))

TableBorderIssue

masaccio commented 2 weeks ago

I've done a simple check to verify that a new table doesn't inherit the borders from the first table and that you can set borders independently. Please confirm with v4.11.4.

GerdHoeren commented 2 weeks ago

Thank you Jon. I tested V4.11.4 and I'm able to change the border style of one table without affecting the other two tables in the sheet.