Форум сайта python.su
И снова доброго времени суток
Похоже зачастил я сюда с вопросами, прошу прощения
Дело вот в чём. Работал я сегодня с кодом:
import sys from PyQt5 import QtWidgets import d2 #import d2_pBar class ExampleApp(QtWidgets.QMainWindow, d2.Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.pushButton.clicked.connect(self.browseFolder) self.pushButton_2.clicked.connect(self.convertDocs) def browseFolder(self): directory = QtWidgets.QFileDialog.getExistingDirectory(self, 'Выберите папку') if directory: self.lineEdit.setText(directory) #return directory #global directory def convertDocs(self): import win32com.client as win32 import os directory = self.lineEdit.text() print(directory) os.chdir(directory) word = win32.Dispatch('Word.Application') #self.barShow for file_name in os.listdir(os.getcwd()): if file_name.endswith('docx'): fn = os.path.join(os.getcwd(), file_name) wDoc = word.Documents.Open(fn) wDoc.SaveAs2(fn[0:-4] + 'doc', FileFormat = 0) wDoc.Close() word.Quit() #def barShow(self): #self.bshow = progressForm() #self.bshow.show() #class progressForm(QtWidgets.QMainWindow, d2.Ui_MainWindow): #def __init__(self): #super().__init__() #self.setupUi(self) def m2(): app = QtWidgets.QApplication(sys.argv) window = ExampleApp() window.show() app.exec_() if __name__ == '__main__': m2()
Traceback (most recent call last): File "C:\Documents and Settings\kersanova\Рабочий стол\design\progressbar\m2.pyw", line 31, in convertDocs wDoc = word.Documents.Open(fn) File "D:\Downloads\Python\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__ raise AttributeError("%s.%s" % (self._username_, attr)) AttributeError: Word.Application.Documents
Офлайн
Нагуглил следующий совет
EthexИсточник: https://bytes.com/topic/python/answers/482449-win32com-client-constants-attributeerror
There are a couple of different ways to run makepy.
Start Pythonwin, and from the menu select
Tools->Com Makepy Utility. You should see a list
of registered typelibs. Select “Microsoft Word x.y
Object Library” and hit Ok.
This can also be done programatically by initiating
Word with
win32com.client.gencache.EnsureDispatch('Word.Appl ication')
Traceback (most recent call last): File "C:\Documents and Settings\kersanova\Рабочий стол\Python\main.py", line 28, in convertDocs wDoc = word.Documents.Open(fn) File "D:\Downloads\Python\lib\site-packages\win32com\client\__init__.py", line 466, in __getattr__ return self._ApplyTypes_(*args) File "D:\Downloads\Python\lib\site-packages\win32com\client\__init__.py", line 459, in _ApplyTypes_ self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), pywintypes.com_error: (-2147417848, 'Вызванный объект был отключен от клиентов.', None, None)
EthexПеречитываю и подозреваю что не об этом…
Всё что смог найти об этом
Отредактировано Ethex (Июнь 14, 2018 16:46:20)
Офлайн
Запустил на домашнем компе “больной” файл, ошибки не произошло. Впрочем, исходя из этого пока нельзя ничего утверждать, т.к. на рабочем ошибка возникла не сразу. К слову, дома питон 3.6.5. На работе 3.4.1 (ставить свежее пока нет возможности)
Попробую тогда переустановить питон на работе. Если поможет, то не исключаю что только на время
Офлайн