I am a non programmer with experience only in VBA. I took up the challenge to automate some daily tasks in my company, and chose Python 3.4 to do it (not sure if was the best option).
The scripts I need to do are rather simple. They just need to read values from .txt file, perform calculations, and write values in a .xls template.
I read some topics in stackoverflow and got concerned about these two topics:
Is there a feasible way to write data in excel (COM automation, Python 3 packages)?
Will I be able to compile Python 3.4 into an .exe file? Users can't install things in their Desktops.
I am able to do a script like this in VBA, but I need an executable file that can be used by everybody.
You can use the following tools:
XlsWriter https://xlsxwriter.readthedocs.org/
Or Use Py2Exe to convert to a python script to executable http://www.py2exe.org/
Or if your looking to use a '.csv' file, there are built in libraries for that, which are pretty straightforward
Related
I have been working with excel vba for some period of time related with automation. Now I am planning to upgrade to python. I did a little bit of research on how to implement automation using python. All I see people doing coding with PyCharm or Jupiter, to do an automation user has to have knowledge of python. What I want to know is how to create a tool or standalone application with python that does a repetitive task, calculation or report generation in excel. Where the end user doesn't have to worry about python or codes or learning new technology to accomplish the task.
I know this isn't technically and answer, and since I can't comment yet (too low rep), I'm going to point you to automate the boring stuff with python. I'm sure you can find your answer here plus some!
Here is my answer.
https://github.com/TaeYoon2/ExcelAutomation
This project is a sample excel automation program with python.
I used 'openpyxl' library.
welcome to stackoverflow. Here are a few resources that hopefully get you started on your journey to automating excel tasks with python then wrapping your project up for non-python users.
Python libraries that interface with excel (these are for you to write your excel automation projects)
openpyxl docs
pandas docs
pylightxl docs
more at http://www.python-excel.org/
Wrapping up your project for non-programmers
There are a few options here for your non-programmer users.
Have users run your python project on command line where you give them prompts to respond to for your automation (ie. input excel file name, automation task inputs etc). This is probably the simplest task on your end, but it does expect your users to know how to user command line.
Have users run your python project on command line but you create a graphical user interface (GUI) for them to ease the input field options. This requires some up front work on your end to wrap you input with a GUI of your choice; here are a few tkinter, pyqt.
Note that both of these options require your users to have python on their machine with the proper packages ready to go to execute your project. This can be a lot to ask for non-python users. Therefore finally you could use a packaging software like pyinstaller to wrap up your python project into an .exe
Hope that helps! Happy pythoning
Let me start off by saying my python knowledge is beginner-to-intermediate level, and I recently started using the language again after a long time.
The Goal:
This morning I came across a bunch of word documents I wanted to convert and concatenate to PDF files, with 2 .doc files creating one PDF.
seemed like a fairly trivial task, so I figured I'd try to learn how to do it in python.
concatenating PDFs wasn't too bad, I found PyPDF2 and managed to write a script that did just that.
But 7 hours later, after countless scripts with broken dependencies- I still can't find a way to automate the doc-pdf conversion.
The Problem(s):
every script I found either:
uses python-docx (my documents are word 2003 .docs)
uses unoconv bridge (which I installed along with OpenOffice, then searched around for documentation but found none- thus I have no idea how to call from a python script or the shell. I saw one example for this but it keeps throwing errors)
uses win32com or win32com.client or pywin32 or somesuch.
I ran into numerous issues with these- installed one but couldn't import it from code (as happened to the guy here), now I can't even find them with pip. searched for documentation for them (are they modules or classes? I have no idea) and found practically nothing that I could understand, beyond that they're connected to ActivePython. (which is apparantly a superset of Python with more capabilities?).
Uses comtypes, which I installed but was unable to use/import either for some reason (maybe I'm using pip wrong somehow?)
I know my question is hardly focused but honestly by now my brain is fried from information overload. any simplifications for a noob would be more than welcome.
TL;DR:
assuming no knowledge of COM stuff and little experience with any external frameworks:
what would I have to do to convert Word 2003 .doc files to .pdf files? I'm running python3.5.1 32-bit on a Windows 10 64-bit machine.
where can I learn more about accessing other software APIs from python? are there big prerequisites for this stuff like knowing how the OS works on a lower level?
Thanks!
From my experience, converting between the various office formats is best done outside of python. With the subprocess module, you can call the external command
soffice --convert-to pdf file.doc --headless
where soffice is the command that comes with LibreOffice.
So I am creating a program that takes input, processes the data, then puts it in Excel. In order to do this, I am using the "xlwt" package (and possibly xlrd). How do I then give this program to other people without making them download python and the packages associated with my program? I considered utilizing an online python interpreter and giving the username/password to my coworkers, but xlwt isn't on any of the ones I've tried, and they don't offer a way (that I can see) to download new packages.
You would have to compile the code into an exe file. The py2exe library can help you out with this
I'm looking to be able to create an executable with py2exe or something similar that takes information from an excel sheet and returns a word file.
Since my coworkers are technically challenged, I need to create an executable that will take the work out of it for them.
Two questions here:
I have to be able to import something into the python script that represents DataNitro. What module represents DataNitro?
Is this legal? I won't be using a DataNitro license on every machine this exe will run on, besides my own, so if it's even possible, is this a bit shady?
Thank you.
P.S. If I'm not able to do this I will probably have to use xlrd,xlwt,etc.
The best way to give non-technical users access to DataNitro is to copy the VBA interface: hook the script up to an Excel button and have users press that button to run it. (There's no difference between running a Python script with DataNitro and running VBA code from the user's point of view.)
Each person using the script would need a DataNitro license.
There's no way to make DataNitro work with py2exe, unfortunately.
Source: I'm one of the DataNitro developers.
I have written a program. I don't know if it is important how it is written but you can find it here: http://pastebin.com/Z3ZvVPV8 Basically, it asks you to assign values to variables and will perform calculations depending on what variables you chose, and prints the answer.
I would like to know how I can make the program run in a window other than cmd (I am using Windows Vista 32bit). I don't need much at all in terms of GUI, just a window that is a bit more user friendly/easier to look at when they are using the program.
EDIT: To those suggesting using IDLE, while that would work for me, if others want to use the program they would have to download it, so I was hoping for a way for that not to happen.
Python comes with a sort of default GUI package TkInter you can use it.
Also there is a lot of other GUI packages available.
The Python standard library offers a lot of ways to implemt simple (but also rather complex) GUIs. I'd like to point you at the documentation of TK (tool kit for graphical interfaces) http://docs.python.org/library/tk.html where you will find also some useful example of use.
Py2Exe is a viable option if you really don't need a gui. This will make it run and look like a command prompt, but it will be an .exe file. Here is a quick quote from thier page: "py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."
Another alternative is to get Portable Python. Here is a quote from thier webpage: "Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application." After packaging the portable python and your .py or .pyc file then create a .bat file that runs the portable python "Python-Portable.exe" with the correct command line parameters for loading your script. Be sure to use relative paths in the batch file in case they are running it from a flash drive, or something other than the same location as you.
NOTE: This is really not a good way to do this as thier download page states: "Installed size: based on selected packages, between 49MB and 480MB". Also be sure to read the the current Python Software Foundation License, as that is what Portable Python is released under, and it may or may not be legal to package it in a closed source project. I haven't really looked at the license myself to be able to tell you. If you are releasing it as open source, then there would not be an issue though. As a quick side note, if you need that .bat file to be a .exe file then you can use a .bat to .exe converter battoexe.com is one. This is really going the long way about doing the whole thing, but it is an option.
Sources:
Working with Python on and off for 7 years now, a lot that using a portable version on a flash drive, and also dealing with Batch files much longer.