import xlrd
from xlutils.copy import copy
import os
class ExcelTools:
# Excel读取相关 -------------------------------------------------------------------------------
# 打开Excel并读取数据
@staticmethod
# 读取表格
def readExcel(file, sheet):
data = xlrd.open_workbook(file)
table = data.sheet_by_name(sheet)
return table
# 获取行数
@staticmethod
def get_row_count(table):
return table.nrows()
# 获取列数
@staticmethod
def get_col_count(table):
return table.ncols()
# 读取整行
@staticmethod
def get_row_data(table, index):
return table.row_values(index)
# 读取整列
@staticmethod
def get_col_data(table, index):
return table.col_values(index)
# 读取单元格
@staticmethod
def get_cell_data(table, row, col):
return table.cell(row, col)
# Excel写出相关 -----------------------------------------------------------------------
Python 通过xlrd读取Excel/WPS表格
最新推荐文章于 2024-08-12 23:17:01 发布
本文介绍了使用Python的xlrd库高效读取Excel和WPS表格的方法,强调了其在处理大量数据(如6w条记录)时的高速性能,通常能在2-5秒内完成读取。
摘要由CSDN通过智能技术生成