From James.Holland at horizonhealth.com Tue Oct 8 12:58:09 2019 From: James.Holland at horizonhealth.com (Holland, James) Date: Tue, 8 Oct 2019 16:58:09 +0000 Subject: [python-win32] Word Application saving to PDF Message-ID: <712ecf3853f94ba58af02c2274f7c5fc@CORP-EX13KP201.corp.uhsinc.biz> I'm trying to open some rtf files to Word and then save as PDFs. I'm running Windows 10 65 bit -- Word 2016 is installed on my computer. Python 3.6.0 import os,os.path import img2pdf import win32com.client input_dir = "G:/MHOShare/MHO Staff/James Holland/TempDump/CindyTest/RTFtest" output_dir = "G:/MHOShare/MHO Staff/James Holland/TempDump/CindyTest/RTFtest" os.chdir(input_dir) wdFormatPDF = 17 rtfList = [i for i in os.listdir() if i.endswith(".rtf")] file = rtfList[0] word = win32com.client.Dispatch('Word.Application') word.Visible = False doc = word.Documents.Open(input_dir + '/' + file) doc.SaveAs(output_dir + '/' + 'rtfTest.pdf', FileFormat = wdFormatPDF) doc.close() However, I get this error. Traceback (most recent call last): File "", line 15, in doc.SaveAs2(output_dir + '/' + 'rtfTest.pdf', FileFormat = wdFormatPDF) File "C:\Users\CMTHOL~1\AppData\Local\Temp\gen_py\3.6\00020905-0000-0000-C000-000000000046x0x8x7\_Document.py", line 461, in SaveAs2 , CompatibilityMode) com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command failed', 'wdmain11.chm', 36966, -2146824090), None) Everything I've read about wdamin11.chm seems to be regarding Word 2007. This is my first go around with pywin32 so sorry if this is an older issue (couldn't find a solution on Stackoverflow). ~James James Holland | Data Analyst | Horizon Health Mental Health Outcomes | James.Holland at horizonhealth.com | 800.266.4440 | 1965 Lakepointe Dr Lewisville TX 75057 UHS of Delaware, Inc. Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution of this information is prohibited, and may be punishable by law. If this was sent to you in error, please notify the sender by reply e-mail and destroy all copies of the original message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed Oct 9 02:03:55 2019 From: timr at probo.com (Tim Roberts) Date: Tue, 8 Oct 2019 23:03:55 -0700 Subject: [python-win32] Word Application saving to PDF In-Reply-To: <712ecf3853f94ba58af02c2274f7c5fc@CORP-EX13KP201.corp.uhsinc.biz> References: <712ecf3853f94ba58af02c2274f7c5fc@CORP-EX13KP201.corp.uhsinc.biz> Message-ID: On Oct 8, 2019, at 9:58 AM, Holland, James via python-win32 wrote: > > I?m trying to open some rtf files to Word and then save as PDFs. > ... > Traceback (most recent call last): > > File "", line 15, in > doc.SaveAs2(output_dir + '/' + 'rtfTest.pdf', FileFormat = wdFormatPDF) > File "C:\Users\CMTHOL~1\AppData\Local\Temp\gen_py\3.6\00020905-0000-0000-C000-000000000046x0x8x7\_Document.py", line 461, in SaveAs2 > , CompatibilityMode) > com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Word', 'Command failed', 'wdmain11.chm', 36966, -2146824090), None) Did you do any web searching for this? -2146824090 is 0x80A1066, which is a security issue. Do you have permission to write into that directory? Are you able to do this same action if you do it by hand? ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From capaneus at gmail.com Mon Oct 14 18:27:34 2019 From: capaneus at gmail.com (Peng Chen) Date: Mon, 14 Oct 2019 23:27:34 +0100 Subject: [python-win32] How to set value with PyIPropertyStore Message-ID: Hi, I'm working on a script to shift video media creation time. I used: properties = propsys.SHGetPropertyStoreFromParsingName(file_name) mDate = properties.GetValue(pscon.PKEY_Media_DateEncoded).GetValue() and successfully retrieved media encoded date property. Now I could shift the time and write this value back. I can see there is a function PyIPropertyStore.SetValue(key, value) and PyIPropertyStore.Commit() to write the date back, but I'm not sure how to construct the value because it requires PyPROPVARIANT type. I can't figure out any where to import this type and doesn't know how to construct it. Sorry I'm not familiar with windows programming, would you please help me on this? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Oct 14 20:25:01 2019 From: timr at probo.com (Tim Roberts) Date: Mon, 14 Oct 2019 17:25:01 -0700 Subject: [python-win32] How to set value with PyIPropertyStore In-Reply-To: References: Message-ID: <6f26b744-32a6-ac0c-f9df-de42c5b18f84@probo.com> Peng Chen wrote: > > I'm working on a script to shift video media creation time. > .... > I can see there is a function > PyIPropertyStore.SetValue(key, value) and?PyIPropertyStore.Commit() > to write the date back, but I'm not sure how to construct?the value > because it requires?PyPROPVARIANT type. > I can't figure out any where to import this type and doesn't know how > to construct?it. PyPROPVARIANT is generally a return type.? In a case like this, I would expect that you would simply pass the datetime value, and the interface code would convert it into a variant.? Have you tried that?? Did you get an error? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 3389 bytes Desc: S/MIME Cryptographic Signature URL: From emaimone3721 at gmail.com Wed Oct 23 18:41:05 2019 From: emaimone3721 at gmail.com (Enzo Maimone) Date: Wed, 23 Oct 2019 19:41:05 -0300 Subject: [python-win32] COM server registered from py script works OK, but not when registered from an exe file Message-ID: I have a Python 3.7 module that registers a COM server, exposing one method to the Windows environment. It works well when running from the ,py script (Python 3.7), and the generated COM server also works fine. Now I want to distribute it to users that do not have Python installed in their machines, so I convert the module to an exe file (using https://github.com/albertosottile/py2exe that ports py2exe from Py3.4 to P3.7), The registration of the COM works OK when running from the exe file, but the COM is no longer functional. This workflow used to work well with pywin and py2exe in their old 2.7 versions. The module: #!/usr/bin/python3 # -*- coding: utf-8 -*- import win32com.client import win32traceutil import os, sys, imp import pythoncom import win32api class COM_test: _reg_progid_ = "PythonZ.CondaTest" _reg_clsid_ = '{5937C658-485D-4B22-B17A-DDE89E2157F4}' _reg_desc_ = "COM server Py37" _public_methods_ = ['where_am_i'] def __init__(self): self.dict = {} def where_am_i(self): if (hasattr(sys, "frozen") or imp.is_frozen("__main__")): hi = "COM server called from an EXE (FROZEN)" else: hi = "COM server called from a .PY (UNFROZEN)" print ("from server ==>", hi) return hi if __name__=='__main__': print ("Registering COM Server") import win32com.server.register win32com.server.register.UseCommandLine(COM_test, debug=True) the setup file (to be run as >python setup.py p2exe) #!/usr/bin/python3 # -*- coding: utf-8 -*- from distutils.core import setup import py2exe py2exe_options = dict( includes = [], packages = [], optimize=0, compressed=False, bundle_files=3, dist_dir='dist01', verbose = True ) setup(name="name", ctypes_com_server=[{ "modules": "COMbuilder_simpler",},], console=[{ "script": "COMbuilder_simpler.py",},], options={"py2exe": py2exe_options}, ) Running the resulting exe file will register the COM. And here a test script to request an object from the COM server and access the public method: import win32com.client import pythoncom import sys def main(): try: COMobj = win32com.client.DispatchEx('PythonZ.CondaTest') r = COMobj.where_am_i() print("from client ==>",r) except: print("COM server failed") if __name__=='__main__': main() Any idea of what is going wrong with the registration of the COM server from the exe file? Appreciate any hint or direction indication Enzo -------------- next part -------------- An HTML attachment was scrubbed... URL: From luckynuaa at 163.com Sun Oct 27 06:26:37 2019 From: luckynuaa at 163.com (luckynuaa at 163.com) Date: Sun, 27 Oct 2019 21:26:37 +1100 Subject: [python-win32] Problem passing array by reference Message-ID: <2019102721263530613610@163.com> Dear All,I am facing a problem passing an array by reference. It is exactly the same problem as described in this thread: https://mail.python.org/pipermail/python-win32/2002-November/000562.htmlhttps://mail.python.org/pipermail/python-win32/2014-July/013234.html I am calling a method on a COM object that fills in an array passed by reference. The array must be initialized to a given size otherwise the call will fail. Currently I am able to complete the call and the array returned by the method is the one I passed as a parameter but unfortunately the value of the array does not change and it should. For your information the COM object I work with is a Position interface maintained by the CATIA COM server. The method is Sub GetComponents(CATSafeArrayVariant array). I understand that the CATSafeArrayVariant type is equivalent to an array of variants. The python call looks like this: > >> a = range(0,12) > >> b = myPosition.GetComponents(a) > >> print a # outputs (0,1,2,3,4,5,6,7,8,9,10,11) instead of the actual > >>components > >> print b # same output This problem really bothers me. So any help will be appreciated. Thank you? luckynuaa at 163.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From luckynuaa at 163.com Sun Oct 27 08:06:02 2019 From: luckynuaa at 163.com (lcy) Date: Sun, 27 Oct 2019 20:06:02 +0800 (CST) Subject: [python-win32] passing array by reference (3) Message-ID: <4e9f2b0f.78c6.16e0d1be4c3.Coremail.luckynuaa@163.com> Hello? Following the tips you mentitoned in the year of 2017 I tried to test the Catia.SystemService.Evaluate() in pytyon, However it cannont work, anything went wrong with my code? Any advice will be appreciated, thank you! params="" CodeToEvaluate = "Sub CATMain()\n" + "MsgBox " + chr(34) + "Hello World" + chr(34) + "\nEnd Sub" CATIA.SystemService.Evaluate(CodeToEvaluate, "VB Script language", "CATMain", params) -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Oct 28 01:29:57 2019 From: timr at probo.com (Tim Roberts) Date: Sun, 27 Oct 2019 22:29:57 -0700 Subject: [python-win32] passing array by reference (3) In-Reply-To: <4e9f2b0f.78c6.16e0d1be4c3.Coremail.luckynuaa@163.com> References: <4e9f2b0f.78c6.16e0d1be4c3.Coremail.luckynuaa@163.com> Message-ID: <893E61B8-29F7-4554-895F-63B7B636BA18@probo.com> On Oct 27, 2019, at 5:06 AM, lcy wrote: > > Hello? > Following the tips you mentitoned in the year of 2017 > I tried to test the Catia.SystemService.Evaluate() in pytyon, However it cannont work, anything went wrong with my code? Any advice will be appreciated, thank you! What DID happen? You don?t have a newline at the very end of the string. CATIA might need that. ? Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengfei.wang84 at outlook.com Tue Oct 29 15:48:47 2019 From: pengfei.wang84 at outlook.com (Pengfei Wang) Date: Tue, 29 Oct 2019 19:48:47 +0000 Subject: [python-win32] Return value for Excel calculation error #Value! Type Message-ID: Hi, I am using win32 to read data from Excel files and it works great. However, recently I had an issue to identify the ?#Value!? errors in my Excel files. A wired number has been returned even though the cell value is shown as ?#Value!?. Is there any way to identify this error in the Excel file? Thanks! Pengfei