如何在使用 win32com.client 将 RTF 文件转换为 txt 文件时处理警报
How to handle alerts while converting RTF files to txt files using win32com.client
我正在尝试使用 win32com.client 将数万个 RTF 文件转换为 txt 格式。
wordapp = win32com.client.Dispatch('Word.Application')
doc = wordapp.Documents.Open(rtf_file, False, False, False)
doc.SaveAs(txt_file, FileFormat = 2)
我遇到以下通知:
"The document may contain text content that will be lost upon conversion to the chosen encoding. To preserve this content , click No to exit this dialog box,and then choose another encoding that supports the languages in this document. Do you want to continue saving the document? Yes/No"
我想继续并单击“是”。有办法处理这个吗?谢谢!
要防止显示警报,您可以通过 wordapp 调用将其关闭。
这应该有效;
wordapp = win32com.client.Dispatch('Word.Application')
# Add this
wordapp.DisplayAlerts = False
doc = wordapp.Documents.Open(rtf_file, False, False, False)
doc.SaveAs(txt_file, FileFormat = 2)
我正在尝试使用 win32com.client 将数万个 RTF 文件转换为 txt 格式。
wordapp = win32com.client.Dispatch('Word.Application')
doc = wordapp.Documents.Open(rtf_file, False, False, False)
doc.SaveAs(txt_file, FileFormat = 2)
我遇到以下通知:
"The document may contain text content that will be lost upon conversion to the chosen encoding. To preserve this content , click No to exit this dialog box,and then choose another encoding that supports the languages in this document. Do you want to continue saving the document? Yes/No"
我想继续并单击“是”。有办法处理这个吗?谢谢!
要防止显示警报,您可以通过 wordapp 调用将其关闭。
这应该有效;
wordapp = win32com.client.Dispatch('Word.Application')
# Add this
wordapp.DisplayAlerts = False
doc = wordapp.Documents.Open(rtf_file, False, False, False)
doc.SaveAs(txt_file, FileFormat = 2)