Amourspirit / python_ooo_dev_tools

Apache License 2.0
21 stars 5 forks source link

AttributeError: 'CalcCellRange' object has no attribute 'StartColumn' #665

Closed JulienPalard closed 6 days ago

JulienPalard commented 6 days ago

I'm trying this code:

        with Lo.Loader(Lo.ConnectSocket(headless=True)) as loader:
            doc = Lo.open_doc(fnm=ods_file, loader=loader)
            calc = CalcDoc(doc)
            sheet = calc.sheets["Catégories"]
            used_cell_rng = sheet.find_used_range()
            array = sheet.get_array(range_obj=used_cell_rng)

with ooo-dev-tools 0.47.17, I'm getting:

Traceback (most recent call last):
  File "test.py", line 1184, in <module>
    main()
  File "test.py", line 1138, in main
    ExpenseTypes.load_from_ods(args.to_ods)
  File "test.py", line 807, in load_from_ods
    array = sheet.get_array(range_obj=used_cell_rng)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/ooodev/calc/calc_sheet.py", line 514, in get_array
    return mCalc.Calc.get_array(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/ooodev/office/calc.py", line 4828, in get_array
    cell_range = cls.get_cell_range(kargs[1], kargs[2])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/ooodev/office/calc.py", line 6523, in get_cell_range
    return cls._get_cell_range_addr(sheet=arg1, addr=arg2)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/ooodev/office/calc.py", line 6277, in _get_cell_range_addr
    start_col=addr.StartColumn,
              ^^^^^^^^^^^^^^^^
AttributeError: 'CalcCellRange' object has no attribute 'StartColumn'

(sorry for the short issue, I only had 2mn to write it :D)

Amourspirit commented 6 days ago

it would be

with Lo.Loader(Lo.ConnectSocket(headless=True)) as loader:
    doc = Lo.open_doc(fnm=ods_file, loader=loader)
    calc = CalcDoc(doc)
    sheet = calc.sheets["Catégories"]
    used_cell_rng = sheet.find_used_range()
    array = sheet.get_array(range_obj=used_cell_rng.range_obj)

Better yet

with Lo.Loader(Lo.ConnectSocket(headless=True)) as loader:
    doc = CalcDoc.open_doc(fnm=ods_file)
    sheet = doc.sheets["Catégories"]
    used_cell_rng = sheet.find_used_range()
    array = used_cell_rng.get_array()
JulienPalard commented 6 days ago

Ohh sorry for the noise and thanks for the nice answer :)