Python reads and writes Excel files and regular expressions

Python read and write Excel files

The two excel read and write libraries xlwtare used here .xlrd

#_*_ coding:utf-8 _*_
#__author__='观海云不远'
#__date__ = '2019-07-11'
#读写excel

import xlwt
import xlrd
import re

workbook = xlrd.open_workbook('data.xlsx')
sheet = workbook.sheet_by_index(0)

data = []

for rx in range(0, sheet.nrows):
    row = sheet.row(rx)
    item = []
    for cx in row:
        item.append(cx)
    data.append(item)

workbook = xlwt.Workbook()
sheet = workbook.add_sheet('output')

rIndex = 0
for row in iter(data):
    cIndex = 0
    for cel in row:
        sheet.write(rIndex, cIndex, cel.value + " changed")
        cIndex += 1
    rIndex += 1

workbook.save('data_output_1.xls')

Python regular expressions

Find whether xxx exists in val

import re
ret = bool(re.search(r'xxx', val))

Guess you like

Origin blog.csdn.net/TiktokLiveTool/article/details/130571399