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
FredCailloux
Posts: 52
Joined: Wed Jul 14, 2021 7:37 pm
Location: Canada

openpyxl project investigation - Is is feasible ?

Post by FredCailloux »

I have this idea to link FreeCAD to an EXCEL sheet using the python programming environment and this tool I found on the web:
https://openpyxl.readthedocs.io/en/stable/index.html
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 ?
How would I proceed to install openpyxl via the FreeCAD Python console ? ( if that is the correct approach)
Or, should openpyxl be installed via another method ?
The openpyxl installation instructions seems limited. It is suggested to install from a virtualenv (whatever that is ? )
Install openpyxl using pip. It is advisable to do this in a Python virtualenv without system packages: $ pip install openpyxl
Any tips welcome
Great results only comes with great understanding. Great memory is just an illusion.
User avatar
onekk
Veteran
Posts: 6144
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 ...
Any tips welcome
I doubt that using a commercial software in an opensource project will be a clever move.

Maybe using something from libreoffice, but the underlying question is IMHO:

It is useful to have a full fletged spreadsheet in FreeCAD?

I think that it is not a strict need, as I think you don't need the many statistical and economic functions that a full fletged spreadsheet has.

Improving the import maybe is a more clever move as it is widespread so to use a library that permit importing and exporting "basic" Excel spreadsheet would be good thing.

Same for LibreOffice spreadsheets.

Improving the internal spreadsheet will be a good thing but not to make too much work, probably collecting user needs or suggestion will be a good preliminary work.

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
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: openpyxl project investigation - Is is feasible ?

Post by Roy_043 »

To install openpyxl in V0.21 this works:

Code: Select all

import addonmanager_utilities as utils
import subprocess
import os

python_exe = utils.get_python_exe()
vendor_path = utils.get_pip_target_directory()
if not os.path.exists(vendor_path):
    os.makedirs(vendor_path)

subprocess.run(
    [
        python_exe,
        "-m",
        "pip",
        "install",
        "--disable-pip-version-check",
        "--target",
        vendor_path,
        "openpyxl",
    ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    timeout=60,
    check=True,
)
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: openpyxl project investigation - Is is feasible ?

Post by Roy_043 »

onekk wrote: Tue Jan 10, 2023 7:16 pm I doubt that using a commercial software in an opensource project will be a clever move.
You don't need to have Excel installed to use openpyxl.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: openpyxl project investigation - Is is feasible ?

Post by onekk »

Roy_043 wrote: Tue Jan 10, 2023 8:10 pm
onekk wrote: Tue Jan 10, 2023 7:16 pm I doubt that using a commercial software in an opensource project will be a clever move.
You don't need to have Excel installed to use openpyxl.
I don't know the library, so I've seen the post that say that the library permit to utilize Excel in FreeCAD.

I prefer to avoid to "encourage" the use of some commercial and closed source program if this will slow the development of a decent internal solution.
For what I've expressed my post with IMHO, but probably it's a matter of tastes.

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
FredCailloux
Posts: 52
Joined: Wed Jul 14, 2021 7:37 pm
Location: Canada

Re: openpyxl project investigation - Is is feasible ?

Post by FredCailloux »

onekk wrote: Tue Jan 10, 2023 7:16 pm I doubt that using a commercial software in an opensource project will be a clever move.
Maybe using something from LibreOffice, but the underlying question is IMHO:
It is useful to have a full fledged spreadsheet in FreeCAD?
I can clearly see where you are coming from and, in a sense, I agree. Though, I think the FreeCAD spreadsheet cannot be qualified as a Full Fledged spreadsheet. "Basic" would appear to be a better qualifier. But that's really a question of opinion.
Just to clarify, my basic motivation for such an endeavor is that the EXCEL IDE is quite sophisticated, quick and full of editing features that render an avid spreadsheet user to enjoy the editing much more than the spreadsheet in FreeCAD. Now, I'm not bashing on the FreeCAD spreadsheet. I think it is a great feature of FreeCAD, its just that it is not as elegant and convenient to utilize as EXCEL.
I regularly utilize both and in many occasions I wish I had all those EXCEL editing capabilities available in FreeCAD. One of them being that in EXCEL if you change one value, all other values are immediately calculated in such a short time that one do not even realize the delay. Where, in FreeCAD, in a moderately complex CAD, changing one value in the spreadsheet require sometime several minutes before FreeCAD terminate the recalculation. If the spreadsheet were to happen in EXCEL, calculations would be done in a snap and then only once would FreeCAD take a long shot to update the CAD.
So, IMO I think it would be great if I could keep my EXCEL spreadsheet on screen#2 and my FreeCAD window on screen#1. This way I could edit my CAD and do modifications in real-time and when done, order an update to FreeCAD. I think it would be a cool feature.
Now, of course, EXCEL here would not be required to compute complex accounting or database queries. just a plain spreadsheet would already be a great feature.

I'm not too familiar with LibreOffice but it sure is a good idea to take a look at that possibility. I'll have to investigate how the programming environment works on LibreOffice, but, sure, its an avenue to take a look at.

Thanks for your comments
Great results only comes with great understanding. Great memory is just an illusion.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: openpyxl project investigation - Is is feasible ?

Post by GeneFC »

FredCailloux wrote: Sat Jan 21, 2023 11:57 pm One of them being that in EXCEL if you change one value, all other values are immediately calculated in such a short time that one do not even realize the delay. Where, in FreeCAD, in a moderately complex CAD, changing one value in the spreadsheet require sometime several minutes before FreeCAD terminate the recalculation.
You are comparing two rather different functions.

Excel recomputes all the numbers in the spreadsheet. Nothing else.

FreeCAD recomputes the entire model, which can take a lot longer than just updating the numbers in the spreadsheet.

I use Excel daily, and I agree that some of its features added to the FreeCAD spreadsheet could be useful.

I suspect that any progress would require an interested coder (you????) to create at least a basic demonstration of how this could work.

Gene
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: openpyxl project investigation - Is is feasible ?

Post by onekk »

FredCailloux wrote: Sat Jan 21, 2023 11:57 pm ...
But FreeCAD is working on multiple OS so as example for Linux I doubt that there is an EXCEL version.

For this I have named LibreOffice as it works on many OS and have a Python library.

As said by @GeneFC if you could code something probably show something.

If not the problem is to find a developer that is willing to spend his time on this task.

You have received some reason that explain why internal FreeCAD spreadsheet is behaving, I have not much to add.

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: Sun Jan 22, 2023 7:12 am But FreeCAD is working on multiple OS so as example for Linux I doubt that there is an EXCEL version.
As I understood it this is not integration with actual EXCEL (as in the software) but with xlsx files, this is an open file format that is also supported by libreoffice and there's also onlyoffice which is an opensource alternative for MS office, so I don't see this as a problem. It would be nice if the integration was with native libreoffice files but it is not a big deal at all.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: openpyxl project investigation - Is is feasible ?

Post by GeneFC »

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,
Yes, this got off track with the insertion of comments on the Excel IDE.

That seems pretty unlikely, while R/W of xlsx files could be both realizable and useful.

Gene
Post Reply