日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python声明编码格式_使用python将doc文件转为utf8编码格式的txt

發(fā)布時間:2023/12/2 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python声明编码格式_使用python将doc文件转为utf8编码格式的txt 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近花了點時間看了會doc的轉換,果然官方文檔最好用,代碼如下:

import os

import sys

import fnmatch

import win32com.client

PATH = os.path.abspath(os.path.dirname(sys.argv[0]))

doc_path = PATH + ‘/data/doc/’

txt_path = PATH + ‘/data/txt/’

def convert_dir_to_txt():

“””

將默認整個文件夾下的文件都進行轉換

:return:

“””

for root, dirs, files in os.walk(doc_path):

for _dir in dirs:

pass

for _file in files:

if fnmatch.fnmatch(_file, ‘*.doc’):

store_file = txt_path + _file[:-3] + ‘txt’

elif fnmatch.fnmatch(_file, ‘*.docx’):

store_file = txt_path + _file[:-4] + ‘txt’

word_file = os.path.join(root, _file)

dealer.Documents.Open(word_file)

try:

dealer.ActiveDocument.SaveAs(store_file, FileFormat=7,Encoding=65001)

except Exception as e:

print(e)

dealer.ActiveDocument.Close()

dealer = win32com.client.gencache.EnsureDispatch(‘Word.Application’)

convert_dir_to_txt()

延伸:根據下面官方給出的參考資料中的數值,可以轉換成多種形式多種編碼文件。

參考資料:

https://docs.microsoft.com/zh-cn/office/vba/api/Office.MsoEncoding

https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/ff839952(v=office.14)?redirectedfrom=MSDN

————————————————

版權聲明:本文為CSDN博主「六神就是我」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權協(xié)議,轉載請附上原文出處鏈接及本聲明。

原文鏈接:https://blog.csdn.net/sinat_33455447/java/article/details/101020285

總結

以上是生活随笔為你收集整理的python声明编码格式_使用python将doc文件转为utf8编码格式的txt的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。