openpyxl project investigation - Is is feasible ?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: openpyxl project investigation - Is is feasible ?

Post by onekk »

adrianinsaval wrote: Sun Jan 22, 2023 9:40 pm ...
As I understood it this is not integration with actual EXCEL (as in the software) but with xlsx files,
...
Not exactly as the OP speaks about "link to excel" and when detailing his use in a post it says to have oprn FreeCAD in Window and Excel in another window.

Good to read or utilize even an external spreadsheet file directly in another format, like you do when modifying a Python Script with an external IDE but the way actuslly FC works is different as @GeneFC has noted so probably it is not only to deal with "importing a file" but even to change the way data are used, as now as soon as you modify a data the 3d model is recalculated, so at least a "delayed recomputing" maybe triggered by a button or something else has to be integrated in FC, a part cited library.

Regards.

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: openpyxl project investigation - Is is feasible ?

Post by adrianinsaval »

onekk wrote: Mon Jan 23, 2023 6:22 am and when detailing his use in a post it says to have oprn FreeCAD in Window and Excel in another window.
Where? Besides, the link is through the file, actual excel software does not need to interact with freecad, note that the python library mentioned just reads and writes to xlsx files, it doesn't actually interact with excel AFAIK.
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: openpyxl project investigation - Is is feasible ?

Post by onekk »

FredCailloux wrote: Mon Jan 09, 2023 6:40 pm I have this idea to link FreeCAD to an EXCEL sheet using the python programming environment
...
The basic idea would be to utilize EXCEL instead of the FreeCAD Spreadsheet workbench.

Has anyone utilized openpyxl and can tell me if it is possible to link an EXCEL sheet to FreeCAD ?
...
From the very first post.

He speaks about linking, and then havinig opened an istance of Excel and one of FreeCAD, but I could have misunderstood, as it is not unusual these times for me. :oops:
Last edited by onekk on Tue Jan 24, 2023 6:53 am, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
ebrahim raeyat
Posts: 619
Joined: Sun Sep 09, 2018 7:00 pm
Location: Iran
Contact:

Re: openpyxl project investigation - Is is feasible ?

Post by ebrahim raeyat »

Openpyxl is an open source software. Pandas uses it for exporting to excel, I use it for export to excel in my osafe workbench:

https://github.com/ebrahimraeyat/OSAFE/ ... rt.py#L114

for installation you can go to the bin folder of your freecad installation and run:

Code: Select all

python -m pip install openpyxl
or:

Code: Select all

pip install --target=G:\Program Files\FreeCAD 0.19\bin\Lib\site-packages openpyxl
User avatar
FredCailloux
Posts: 52
Joined: Wed Jul 14, 2021 7:37 pm
Location: Canada

Re: openpyxl project investigation - Is is feasible ?

Post by FredCailloux »

The whole idea started with this description found on the Openpyxl website page:
openpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.
Of course, the LibreOffice option could be just as valid if the interaction with Python is available, for automation purposes.
My first idea was with EXCEL simply because of the existence of Openpyxl, but the foundation of the idea would be to offer a more feature rich spreadsheet option to FreeCAD that would be facilitated with tools that already exist, be it LibreOffice or EXCEL or OnlyOffice or any other available tools out there.
The main criteria being: compatible and interactive via Python.
At first, EXCEL and Openpyxl seemed to offer a great start.

Here is a very crude presentation of how I see it working:
A user would build whatever is needed for his needs, utilizing math and cell names and formatting his worksheet as he see fit.
A VBA macro could save the Workbook in real-time after each cell modification (which is very quick in EXCEL, even with substantially big spreadsheet).
After some lengthy work within EXCEL, the user could go back to FreeCAD and run a Python macro that would read the EXCEL Workbook and target all properly named variables to update dimensions in the FreeCAD design.
The user would appreciate the result, and if modifications are needed, simply go back to the EXCEL spreadsheet and edit values.
Then rerun the Python macro for a subsequent CAD update.

Furthermore, I can see great potential to refine the "EXCEL import" Python macro. It could even become another workbench.
Such tool, i suspect, would spark new ideas by users who like EXCEL (or any other environments, so far as these are compatible with a Python interface)
Great results only comes with great understanding. Great memory is just an illusion.
User avatar
FredCailloux
Posts: 52
Joined: Wed Jul 14, 2021 7:37 pm
Location: Canada

Re: openpyxl project investigation - Is is feasible ?

Post by FredCailloux »

ebrahim raeyat wrote: Mon Jan 23, 2023 6:09 pm for installation you can go to the bin folder of your freecad installation and run:
python -m pip install openpyxl
Are your command lines functional within Windows , Linux ... ?

Looks like a good start.
Great results only comes with great understanding. Great memory is just an illusion.
Post Reply