讀取csv寫入word
代碼:
#!/usr?bin/env/ python
# -*- coding:utf-8 -*-
# author: lai zheng laing
# datetime: 2020/10/23 15:53
# software: PyCharm
import docx
import csv
file_path = 'E:/The_data_for_topiclcrlaw/yi_qing_fangkong_data/爬取的疫情防控資料.csv'
with open(file_path,encoding='utf-8') as file_name: # 打開檔案所在的位置
reader =csv.reader(file_name)
result = list(reader) # 存入串列
del result[0]
# str_convert = ''.join(result[0][:])
# print(str_convert)
a = (len(result[:][:]))
b = (len(result[0][:]))
doc = docx.Document() # 創建一個空的word
for i in range(a):
str_convert = ''.join(result[i][:]) # 將串列的內容寫入字串
str_num = ''.join(str_convert) # 創建一個總的字串
doc.add_paragraph(str_num) # 寫入word
print(str_num)
doc.save('C:/Users/acer/Desktop/test.doc') # 保存word
## 結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/191895.html
標籤:其他
上一篇:Python實作LR1文法
下一篇:八數碼寬度優先極簡版
