python 后綴doc文件的讀取


文件內容如圖:

from win32com import client as wc
from docx import Document def word_convert(): account_list = [] new_file_name = 'C:/名單2.docx' file_exists = os.path.exists(new_file_name) if not file_exists: word = wc.Dispatch('Word.Application') doc = word.Documents.Open('C:/名單.doc') doc.SaveAs('C:/名單2.docx', 12, False, "", True, "", False, False, False,False) # 轉化后路徑下的文件 doc.Close() word.Quit() document = Document(new_file_name) tables = document.tables for table in tables: # 行列個數 row_count = len(table.rows) col_count = len(table.columns) for i in range(row_count): row = table.rows[i].cells if i == 0: continue for j in range(col_count): value_text = row[j].text if j == 1: account_list.append(value_text) # 我這里獲取的是第二列 return account_list

  

 先把 doc 文件轉換為 docx 讀取


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM