读取csv文件的内容写入word里面

读取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

在这里插入图片描述## 结果:

在这里插入图片描述

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值