Преобразование .doc в .docx - PullRequest
       33

Преобразование .doc в .docx

0 голосов
/ 23 сентября 2019

При разработке этого скрипта тестовый файл будет сохранен в папку. Фактический файл не будет передан функции Document.open ().

Я попробовал это на своем компьютере.Может не работать из-за взаимодействия с сетью.

print('-------------------------------------Setting Variables-----------------------------------------')
oldlocation_forms = 'Old file location'
newlocation = 'location on my pc that is shared on network'
newlocation_sub = 'nested file that is shared on network'
form_x = 'file that needs to be converted*.doc'
print('form_x =' + form_)
os.chdir(oldlocation_forms)

for file_x in glob.glob(form_x):
    path_x_convert = oldlocation_forms + '/' + file_x

print('file_x =' + file_)
print('-------------------------------------Local variables---------------------------- ')

baseDir = oldlocation_forms
word = win32com.client.Dispatch("Word.application")

print('-------------------------------------Doc Convert-------------------------------- ')

for dir_path, dirs, files in os.walk(baseDir):
    for file_name in files:
        file_path = os.path.join(dir_path, '//'+file_x)
        file_name, file_extension = os.path.splitext(file_path)
        print('**************--------------------------------------------------------------------------------------------------------------------looking')
        print('              file_path =            ' + file_path)
        print('              file_name =            '+ file_name)
        print('              file_extension =       ' + file_extension)
        if file_extension.lower() == '.doc': #
            docx_file = '{0}{1}'.format(file_path,  'x')
            print('              docx_file =            ' + docx_file)
            try:
                word_doc = word.Documents.Open(docx_file)
                save_location_ = newlocation + '/' + file_x + 'x'
                print('          save_location_x =        ' + save_location_x)
                word_doc.SaveAs2(save_location_x, FileFormat = 16)
                print('**************Moved')
            except Exception:
                print('Failed to Convert:                  {0}'.format(docx_file))

word.Quit()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...