前言
处理word
#docx只能处理docx,不能处理doc,所以在进行之前,可以通过word的另存为docx格式
from docx import Document
from docx.shared import Cm
from docx.enum.text import WD_ALIGN_PARAGRAPH
import re
import os
import xlrd
wb = xlrd.open_workbook('./DATA/pingyu.xlsx')
sh = wb.sheet_by_index(0)
for i in range(sh.nrows):
if i==0:
continue
name = sh.cell(i,0).value
chinese = sh.cell(i,1).value
math = sh.cell(i,2).value
english = sh.cell(i,3).value
pinhyu = sh.cell(i,4).value
file = r"./DATA/result.docx"
document=Document(file)
tables=document.tables
tables[0].cell(1,1).text = chinese
tables[0].cell(1,2).text = math
tables[0].cell(1,3).text = english
tables[0].cell(2,1).text = pingjia
document.save( "./result/" + name + ".docx")
用xlrd,记住版本一定要按对
pip3 install xlrd==1.2.0
demo
import xlrd
wb = xlrd.open_workbook('./codes_from_edinliu/data/finance/html/train.xlsx')
sh = wb.sheet_by_index(0)
rokwey_list = []
html_list = []
for i in range(sh.nrows):
if i==0:
continue
rokwey_list.append(sh.cell(i,0).value)
html_list.append(sh.cell(i,1).value)
print(rokwey_list[:2])
print(html_list[:2])