From hjb2 at earthlink.net Wed Jun 10 20:48:16 2015 From: hjb2 at earthlink.net (Hans Becker) Date: Wed, 10 Jun 2015 08:48:16 -1000 Subject: [python-win32] printing landscape in Windows Message-ID: Just about a month ago I started reading Learning Python by Mark Lutz. It's a new paradigm for me. I have a whole bunch of old mainframe files with carriage control characters as the 1st character in each line. Well, a got a very simple script working except I need to be able to print landscape on my pc printer. Does anyone by chance have sample code I could cut and paste to print landscape? I'm running Windows 7 Pro and Python 2.7 #prt1a is a copy of prt11 import os, sys, tempfile import win32api, win32print printer_name = win32print.GetDefaultPrinter () hPrinter = win32print.OpenPrinter (printer_name) hJob = win32print.StartDocPrinter (hPrinter, 1, ('alfie', None, "RAW")) win32print.StartPagePrinter (hPrinter) for line in open('alf1'): cc = line[0] line = line[1:] line = line.rstrip() if cc == '1': line = '\f' + line elif cc == ' ': line = '\n' + line elif cc == '0': line = '\n\n' + line elif cc == '-': line = '\n\n\n' + line line = line + '\r' # takes care of the overprinting win32print.WritePrinter(hPrinter, line) win32print.WritePrinter(hPrinter,"\f") win32print.EndPagePrinter (hPrinter) win32print.EndDocPrinter (hPrinter) win32print.ClosePrinter (hPrinter) my test data 'alf1': 1 QWDDNNNDNDN ++2 /111111111 ++2a XXXXXXXX11 3 ZDDDDNDNDNNN ++4 #/1111111111 ++4a #XXXXXXXXX11 ++4 b #WWWWWWWWWW1 5 MMMMMMNMMMMMMMMNMNNNNMNNNM ++6 IIIIII1IIIIIIII1I1111I111I ++6a IIIIII1IIIIIIII1I1111I111I 7 NNMNNNNNNNNNNNNNNNNNNNNNMM ++8 11I111111111111111111111II 9 .......................... 10 -------------------------- 11 ;;;;;;;; Thanks Hans Becker -------------- next part -------------- An HTML attachment was scrubbed... URL: From toddfiske at gmail.com Thu Jun 11 00:43:40 2015 From: toddfiske at gmail.com (Todd Fiske) Date: Wed, 10 Jun 2015 18:43:40 -0400 Subject: [python-win32] printing landscape in Windows In-Reply-To: References: Message-ID: On Wed, Jun 10, 2015 at 2:48 PM, Hans Becker wrote: > Does anyone by chance have sample code I could cut and paste to print > landscape? > I don't have a cut and paste example on hand, but you might benefit from reading the source of this module, or even using it: MSWinPrint 1.1 : Python Package Index https://pypi.python.org/pypi/MSWinPrint The method they show for setting landscape mode (setting devmode.Orientation) looks like it will blend in with what you have with only a little adjustment. Todd -------------- next part -------------- An HTML attachment was scrubbed... URL: From toddfiske at gmail.com Thu Jun 11 06:20:52 2015 From: toddfiske at gmail.com (Todd Fiske) Date: Thu, 11 Jun 2015 00:20:52 -0400 Subject: [python-win32] printing landscape in Windows In-Reply-To: References: Message-ID: It seems I'm wrong about just needing a little adjustment. When you use WritePrinter, you are sending raw bytes to the printer, thanks to opening the device in "RAW" mode. In this mode, you would need to send the actual printer escape code that sets it to Landscape, in the language of its default driver which may be PCL or XPS, or may be something proprietary. In contrast, MSWinPrint creates a printer device context (dc) and draws to it with GDI commands, which is a more flexible device-independent method. Apologies for the false lead, I should have tested it first. On Wed, Jun 10, 2015 at 6:43 PM, Todd Fiske wrote: > > On Wed, Jun 10, 2015 at 2:48 PM, Hans Becker wrote: > >> Does anyone by chance have sample code I could cut and paste to print >> landscape? >> > > I don't have a cut and paste example on hand, but you might benefit from > reading the source of this module, or even using it: > > MSWinPrint 1.1 : Python Package Index > https://pypi.python.org/pypi/MSWinPrint > > The method they show for setting landscape mode (setting > devmode.Orientation) looks like it will blend in with what you have with > only a little adjustment. > > Todd > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From carl.evans28 at gmail.com Mon Jun 22 16:56:48 2015 From: carl.evans28 at gmail.com (Carl E. Evans) Date: Mon, 22 Jun 2015 08:56:48 -0600 Subject: [python-win32] Issue with refresh of ODBC linked table and submitting credentials in excel using Python Message-ID: I have the following code: import win32com.clientimport os file1= r'C:\\Users\file.xlxm' def refresher(): if os.path.exists(file1): xl = win32com.client.DispatchEx("Excel.Application") xl.Workbooks.Open(Filename=file1,ReadOnly=1) xl.Visible = 1 xl.Workbooks(1).Close(SaveChanges=1) xl.Application.Quit() del xl refresher() Which gets me into the file, but I am unsure of how to refresh a ODBC connected table that requires a simple form submission of user credentials. The current settings dont allow me to save credentials so a script seems to be the only solution. Any suggestions? This will allow me to quickly update my models without have to do it manually in excel. Thanks! -- ----- Carl E. Evans | Economist -------------- next part -------------- An HTML attachment was scrubbed... URL: From vernondcole at gmail.com Mon Jun 22 18:08:25 2015 From: vernondcole at gmail.com (Vernon D. Cole) Date: Mon, 22 Jun 2015 16:08:25 +0000 Subject: [python-win32] Issue with refresh of ODBC linked table and submitting credentials in excel using Python In-Reply-To: References: Message-ID: I think you are saying that you have an Excel spreadsheet which imports data from an ODBC data source, as talked about in Overview of connecting to (importing) data . If that is correct, then my suggestion would be to eliminate Excel from the picture, and manipulate the database directly using Python and SQL. Unfortunately, the version of adodbapi which ships with the present latest version of pywin32 is broken, so you will have to download directly from http://sf.net/projects/adodbapi until the next release. Using ADO you can write SQL commands to manipulate data in any ODBC data source, or in an ACCESS database, or in an Excel spreadsheet. On Mon, Jun 22, 2015 at 2:56 PM, Carl E. Evans wrote: > I have the following code: > > import win32com.clientimport os > > > file1= r'C:\\Users\file.xlxm' > def refresher(): > if os.path.exists(file1): > xl = win32com.client.DispatchEx("Excel.Application") > xl.Workbooks.Open(Filename=file1,ReadOnly=1) > xl.Visible = 1 > > > > xl.Workbooks(1).Close(SaveChanges=1) > xl.Application.Quit() > del xl > refresher() > > Which gets me into the file, but I am unsure of how to refresh a ODBC > connected table that requires a simple form submission of user credentials. > The current settings dont allow me to save credentials so a script seems to > be the only solution. Any suggestions? > > This will allow me to quickly update my models without have to do it > manually in excel. > > Thanks! > > -- > ----- > > Carl E. Evans | Economist > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > https://mail.python.org/mailman/listinfo/python-win32 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: