Python Forum
Is this possible in Python? Auto-Send-to-printer on script run?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is this possible in Python? Auto-Send-to-printer on script run?
#1
Hello,

Is this possible in Python?

I'm completing a project and as a last step for some non-technical coworkers, I want to automatically send to a printers to print when the script is run.

I've got an 11-page .xlsx spreadsheet separated onto 11 different worksheets. Can I use Python to go through all 11 worksheets and send each to our local network printer when the Python script is run? (Cloud printing is not an option = tight work network)

Thanks,
phil

Okay, I seem to have the code to auto-print to the default printer.
import os
os.startfile('C:/Python36x64/testFile.txt', 'print') 
What I'm missing is how to select all worksheets in the Excel-.xlsx file I am printing.
Anyone know how to (ideally use Openpyxl) select all worksheets in a spreadsheet using Python?
Reply
#2
If you have libreoffice, you can try to convert an xlxs document to pdf from the command line using the soffice command
Output:
soffice -env:UserInstallation=file:///tmp/test --headless --convert-to pdf:calc_pdf_Export --outdir ./tmp fubar.xlsx
You need to adapt the paths to the directories and the xlsx file to your system (this is a linux command). This command creates a file ./tmp/fubar.pdf. Then you only need to send the pdf file to the printer (there are tools in windows for this such as pdftoprinter or gsprint).

If you can do it from the command line, you can do it from python by using subprocess.call() for example.

Another strategy that I see is to write an ironpython script that can interact with Microsoft Office's API, but I have never done this.
Reply
#3
check these SO
https://stackoverflow.com/a/12725233/4046632
https://stackoverflow.com/a/22550163/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Hi Buran,

I read through those two SO posts before posting here. Thanks though for them. That's how I learned about the OS-print method.

Unfortunately LibreOffice isn't an option. I making this for the lowest common denominator co-worker and I basically need this Python script to be an icon on the desktop, double-click, and print to the default printer. That's the ideal I'm after anyway.

I have the SS complete, 11 worksheets within one SS file.
If I have the SS open, I can click the left-most worksheet, hold the shift key down, and click the right-most SS, thereby selecting all worksheets.
Then by printing (Ctrl-P & Enter), I will print all worksheets in the SS.

It is possible to do this by implementing a coded software solution?

Thanks,
Phil
Reply
#5
OS? If you are on Linux you could use cups and subprocess.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
We're all on Win10 (some still on 7), mostly 64 bit (mine is 64-haven't checked everyone)

I'm working for a pretty tight and secure company (UHG) so installing third-party, or any other software, is a big event. Getting Python installed on computers isn't difficult as it's already approved in our internal appstore.

FYI: I'm trying to bring some automation and management time-savings into this archaic dep't I'm in, bolster my Python knowledge and practical project completions, and work myself into a full-time developer position that pays well enough to support my family (as I am now). I'm also working nights (CST-USA) over long weekends so I'm in and out of here as the week goes on.

Thanks,
phil

Also, on my own developer laptop, I have it set to dual boot into Win10 or Linux Mint. I can't do this with my co-workers though. Just to let you know I have some experience with Linux.

Phil
Reply
#7
You can try something from this list with subprocess module
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
Hi,

Printing is not my roadblock with Python right now, it's selecting all worksheets.
Quote:I have the SS complete, 11 worksheets within one SS file.
If I have the SS open, I can click the left-most worksheet, hold the shift key down, and click the right-most SS, thereby selecting all worksheets.
Then by printing (Ctrl-P & Enter), I will print all worksheets in the SS.

It is possible to do this by implementing a coded software solution?

Phil
Reply
#9
(Nov-06-2018, 06:30 AM)pcsailor Wrote: Printing is not my roadblock with Python right now, it's selecting all worksheets.

If printing is not a roadblock then can't you iterate over sheets and print them one by one (sheetnames)?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,162 Jun-29-2023, 11:57 AM
Last Post: gologica
  Trying to send file to printer with no results. chob_thomas 2 3,355 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
  How do you marshal the default printer setup to print? hammer 0 1,274 May-29-2022, 02:54 PM
Last Post: hammer
  Can you print a string variable to printer hammer 2 1,928 Apr-30-2022, 11:48 PM
Last Post: hammer
  Need Outlook send email code using python srikanthpython 3 8,186 Feb-28-2021, 01:53 PM
Last Post: asyswow64
  Auto re-pair / re-sync Controller via Script? User3000 2 2,305 Nov-30-2020, 11:42 AM
Last Post: User3000
  Printing to a printer connected to pi 4 alan 2 2,420 Oct-04-2020, 10:08 PM
Last Post: alan
  How to send email using python? Gigux 2 2,833 Jul-04-2020, 07:53 AM
Last Post: Gigux
  I am trying to send an email with python nick235 9 5,273 Jun-29-2020, 06:40 PM
Last Post: nick235
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,861 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020