编程语言
首页 > 编程语言> > 用Python统计电脑信息

用Python统计电脑信息

作者:互联网

# -*- coding: utf-8 -*-

import os, re, openpyxl
import time

def file_name(file_dir):
listfile = os.listdir(file_dir)
strfile = listfile.__str__()
#print(strfile)
return strfile


def regix(listname, strfile):
i=0
for name in listname:
pattern = re.compile(name)

if pattern.search(strfile) is not None:
pass
else:
i=i+1
print(name)
print(i)

def readExel():
filename = r'D:\123.xlsx'
inwb = openpyxl.load_workbook(filename) # 读文件
listname = []
# 获取读文件中所有的sheet,通过名字的方式
for sheetnames in inwb.sheetnames:
ws = inwb[sheetnames] # 获取第一个sheet内容

# 获取sheet的最大行数和列数
rows = ws.max_row
cols = ws.max_column
for r in range(3, rows):
for c in range(10, 11):
if ws.cell(r, c).value is not None:
listname.append(ws.cell(r, c).value)
#print(ws.cell(r, c).value)
return listname


strfile = file_name(r"\\172.16.1.20\AcmeData\检查报告")
listname = readExel()
regix(listname, strfile)
# def writeExcel(self):
# outwb = openpyxl.Workbook() # 打开一个将写的文件
# outws = outwb.create_sheet(index=0) # 在将写的文件创建sheet
# for row in range(1, 70000):
# for col in range(1, 4):
# outws.cell(row, col).value = row * 2 # 写文件
# print(row)
# saveExcel = "D:\\work\\Excel_txtProcesss\\test.xlsx"
# outwb.save(saveExcel) # 一定要记得保存

标签:listname,sheet,name,Python,电脑,ws,print,统计,row
来源: https://www.cnblogs.com/huluxia-fun/p/16023260.html